[gtk/wip/matthiasc/shared-glyph-cache] Do away with all the context switching
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/shared-glyph-cache] Do away with all the context switching
- Date: Tue, 4 Jun 2019 11:07:56 +0000 (UTC)
commit b19450b23d8b08148546885c7d1c2b6a462dcd52
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jun 4 10:53:31 2019 +0000
Do away with all the context switching
Turns out we don't need it, after all.
gsk/gl/gskglglyphcache.c | 50 ++++++++++--------------------------------------
gsk/gl/gskgliconcache.c | 43 +++++------------------------------------
2 files changed, 15 insertions(+), 78 deletions(-)
---
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c
index 41fb9f4ffb..816db7607e 100644
--- a/gsk/gl/gskglglyphcache.c
+++ b/gsk/gl/gskglglyphcache.c
@@ -73,20 +73,11 @@ gsk_gl_glyph_cache_new (GdkDisplay *display)
return glyph_cache;
}
-static GdkGLContext *
-get_context (GskGLGlyphCache *cache)
-{
- return (GdkGLContext *)g_object_get_data (G_OBJECT (cache->display), "shared_data_gl_context");
-}
-
void
gsk_gl_glyph_cache_free (GskGLGlyphCache *self)
{
- GdkGLContext *context = get_context (self);
guint i;
- gdk_gl_context_make_current (context);
-
for (i = 0; i < self->atlases->len; i ++)
{
GskGLTextureAtlas *atlas = g_ptr_array_index (self->atlases, i);
@@ -280,16 +271,9 @@ upload_region_or_else (GskGLGlyphCache *self,
guint texture_id,
GskImageRegion *region)
{
- GdkGLContext *previous;
-
- previous = gdk_gl_context_get_current ();
- gdk_gl_context_make_current (get_context (self));
-
glBindTexture (GL_TEXTURE_2D, texture_id);
glTextureSubImage2D (texture_id, 0, region->x, region->y, region->width, region->height,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, region->data);
-
- gdk_gl_context_make_current (previous);
}
static void
@@ -300,10 +284,9 @@ upload_dirty_glyph (GskGLGlyphCache *self,
g_assert (atlas->user_data != NULL);
- gdk_gl_context_push_debug_group_printf (get_context (self),
-(driver),
-- "Uploading glyph %d", ((Dirty
-Glyph *)atlas->user_data)->key->glyph);
+ gdk_gl_context_push_debug_group_printf (gdk_gl_context_get_current (),
+ "Uploading glyph %d",
+ ((DirtyGlyph *)atlas->user_data)->key->glyph);
if (render_glyph (atlas, (DirtyGlyph *)atlas->user_data, ®ion))
{
@@ -311,7 +294,7 @@ Glyph *)atlas->user_data)->key->glyph);
g_free (region.data);
}
- gdk_gl_context_pop_debug_group (get_context (self));
+ gdk_gl_context_pop_debug_group (gdk_gl_context_get_current ());
/* TODO: This could be unnecessary. We can just reuse the allocated
* DirtyGlyph next time.
@@ -387,20 +370,17 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache,
return value;
}
+/* Not using gdk_gl_driver_create_texture here, since we want
+ * this texture to survive the driver and stay around until
+ * the display gets closed.
+ */
static guint
create_shared_texture (GskGLGlyphCache *self,
int width,
int height)
{
- GdkGLContext *previous;
- GdkGLContext *context;
guint texture_id;
- previous = gdk_gl_context_get_current ();
- context = get_context (self);
-
- gdk_gl_context_make_current (context);
-
glGenTextures (1, &texture_id);
glBindTexture (GL_TEXTURE_2D, texture_id);
@@ -410,15 +390,13 @@ create_shared_texture (GskGLGlyphCache *self,
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- if (gdk_gl_context_get_use_es (context))
+ if (gdk_gl_context_get_use_es (gdk_gl_context_get_current ()))
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
else
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture (GL_TEXTURE_2D, 0);
- gdk_gl_context_make_current (previous);
-
return texture_id;
}
@@ -433,7 +411,7 @@ gsk_gl_glyph_cache_get_glyph_texture_id (GskGLGlyphCache *self,
if (atlas->texture_id == 0)
{
atlas->texture_id = create_shared_texture (self, atlas->width, atlas->height);
- gdk_gl_context_label_object_printf (get_context (self),
+ gdk_gl_context_label_object_printf (gdk_gl_context_get_current (),
GL_TEXTURE, atlas->texture_id,
"Glyph atlas %d", atlas->texture_id);
}
@@ -452,7 +430,6 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self)
GlyphCacheKey *key;
GskGLCachedGlyph *value;
GHashTable *removed = g_hash_table_new (g_direct_hash, g_direct_equal);
- GdkGLContext *previous = NULL;
guint dropped = 0;
self->timestamp++;
@@ -482,10 +459,6 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self)
if (atlas->texture_id != 0)
{
- previous = gdk_gl_context_get_current ();
- if (previous != get_context (self))
- gdk_gl_context_make_current (get_context (self));
-
glDeleteTextures (1, &atlas->texture_id);
atlas->texture_id = 0;
}
@@ -496,9 +469,6 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self)
}
}
- if (previous)
- gdk_gl_context_make_current (previous);
-
/* Remove all glyphs whose atlas was removed, and
* mark old glyphs as unused
*/
diff --git a/gsk/gl/gskgliconcache.c b/gsk/gl/gskgliconcache.c
index 3970d31066..04869d388c 100644
--- a/gsk/gl/gskgliconcache.c
+++ b/gsk/gl/gskgliconcache.c
@@ -1,6 +1,7 @@
#include "gskgliconcacheprivate.h"
#include "gskgltextureatlasprivate.h"
#include "gdk/gdktextureprivate.h"
+#include "gdk/gdkglcontextprivate.h"
#include <epoxy/gl.h>
@@ -47,20 +48,11 @@ gsk_gl_icon_cache_new (GdkDisplay *display)
return self;
}
-static GdkGLContext *
-get_context (GskGLIconCache *cache)
-{
- return (GdkGLContext *)g_object_get_data (G_OBJECT (cache->display), "shared_data_gl_context");
-}
-
void
gsk_gl_icon_cache_free (GskGLIconCache *self)
{
- GdkGLContext *context = get_context (self);
guint i, p;
- gdk_gl_context_make_current (context);
-
for (i = 0, p = self->atlases->len; i < p; i ++)
{
GskGLTextureAtlas *atlas = g_ptr_array_index (self->atlases, i);
@@ -84,7 +76,6 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self)
GHashTableIter iter;
GdkTexture *texture;
IconData *icon_data;
- GdkGLContext *previous = NULL;
/* Increase frame age of all icons */
g_hash_table_iter_init (&iter, self->icons);
@@ -123,10 +114,6 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self)
if (atlas->texture_id != 0)
{
- previous = gdk_gl_context_get_current ();
- if (previous != get_context (self))
- gdk_gl_context_make_current (get_context (self));
-
glDeleteTextures (1, &atlas->texture_id);
atlas->texture_id = 0;
}
@@ -135,9 +122,6 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self)
i --; /* Check the current index again */
}
}
-
- if (previous)
- gdk_gl_context_make_current (previous);
}
/* FIXME: this could probably be done more efficiently */
@@ -175,15 +159,8 @@ create_shared_texture (GskGLIconCache *self,
int width,
int height)
{
- GdkGLContext *previous;
- GdkGLContext *context;
guint texture_id;
- previous = gdk_gl_context_get_current ();
- context = get_context (self);
-
- gdk_gl_context_make_current (context);
-
glGenTextures (1, &texture_id);
glBindTexture (GL_TEXTURE_2D, texture_id);
@@ -193,15 +170,13 @@ create_shared_texture (GskGLIconCache *self,
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- if (gdk_gl_context_get_use_es (context))
+ if (gdk_gl_context_get_use_es (gdk_gl_context_get_current ()))
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
else
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture (GL_TEXTURE_2D, 0);
- gdk_gl_context_make_current (previous);
-
return texture_id;
}
@@ -210,16 +185,9 @@ upload_region_or_else (GskGLIconCache *self,
guint texture_id,
GskImageRegion *region)
{
- GdkGLContext *previous;
-
- previous = gdk_gl_context_get_current ();
- gdk_gl_context_make_current (get_context (self));
-
glBindTexture (GL_TEXTURE_2D, texture_id);
glTextureSubImage2D (texture_id, 0, region->x, region->y, region->width, region->height,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, region->data);
-
- gdk_gl_context_make_current (previous);
}
void
@@ -281,7 +249,7 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self,
atlas = g_malloc (sizeof (GskGLTextureAtlas));
gsk_gl_texture_atlas_init (atlas, ATLAS_SIZE, ATLAS_SIZE);
atlas->texture_id = create_shared_texture (self, atlas->width, atlas->height);
- gdk_gl_context_label_object_printf (get_context (self),
+ gdk_gl_context_label_object_printf (gdk_gl_context_get_current (),
GL_TEXTURE, atlas->texture_id,
"Icon atlas %d", atlas->texture_id);
@@ -314,13 +282,12 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self,
region.height = theight + 2;
region.data = cairo_image_surface_get_data (padded_surface);
- gdk_gl_context_push_debug_group_printf (get_context (self),
-(driver),
+ gdk_gl_context_push_debug_group_printf (gdk_gl_context_get_current (),
"Uploading texture");
upload_region_or_else (self, atlas->texture_id, ®ion);
- gdk_gl_context_pop_debug_group (get_context (self));
+ gdk_gl_context_pop_debug_group (gdk_gl_context_get_current ());
*out_texture_id = atlas->texture_id;
*out_texture_rect = icon_data->texture_rect;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]