diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-06-03 19:00:17 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-06-04 23:00:02 +0000 |
commit | 7293fd517e9c884c9e70dae0d9cf43d9a4e47d3e (patch) | |
tree | 8cd1a3a1eff9371a400f4bc2da297e4d6a322018 /gsk | |
parent | c9cea36b37a8035c84499e43af8a88b1a0bb6de9 (diff) | |
download | gtk+-7293fd517e9c884c9e70dae0d9cf43d9a4e47d3e.tar.gz |
glyph cache: Stop storing driver and render
This is the first step towards sharing glyph
caches across renderers.
Diffstat (limited to 'gsk')
-rw-r--r-- | gsk/gl/gskglglyphcache.c | 55 | ||||
-rw-r--r-- | gsk/gl/gskglglyphcacheprivate.h | 17 | ||||
-rw-r--r-- | gsk/gl/gskglrenderer.c | 11 |
3 files changed, 40 insertions, 43 deletions
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c index af735e6d2d..b1338d9e58 100644 --- a/gsk/gl/gskglglyphcache.c +++ b/gsk/gl/gskglglyphcache.c @@ -40,11 +40,11 @@ create_atlas (GskGLGlyphCache *self, { GskGLTextureAtlas *atlas; - GSK_RENDERER_NOTE(self->renderer, GLYPH_CACHE, g_message ("Create atlas %d x %d", atlas->width, atlas->height)); - atlas = g_new (GskGLTextureAtlas, 1); gsk_gl_texture_atlas_init (atlas, MAX (width, ATLAS_SIZE), MAX (height, ATLAS_SIZE)); + GSK_NOTE(GLYPH_CACHE, g_message ("Create atlas %d x %d", atlas->width, atlas->height)); + return atlas; } @@ -60,20 +60,16 @@ free_atlas (gpointer v) } void -gsk_gl_glyph_cache_init (GskGLGlyphCache *self, - GskRenderer *renderer, - GskGLDriver *gl_driver) +gsk_gl_glyph_cache_init (GskGLGlyphCache *self) { self->hash_table = g_hash_table_new_full (glyph_cache_hash, glyph_cache_equal, glyph_cache_key_free, glyph_cache_value_free); self->atlases = g_ptr_array_new_with_free_func (free_atlas); - - self->renderer = renderer; - self->gl_driver = gl_driver; } void -gsk_gl_glyph_cache_free (GskGLGlyphCache *self) +gsk_gl_glyph_cache_free (GskGLGlyphCache *self, + GskGLDriver *driver) { guint i; @@ -83,7 +79,7 @@ gsk_gl_glyph_cache_free (GskGLGlyphCache *self) if (atlas->image.texture_id != 0) { - gsk_gl_image_destroy (&atlas->image, self->gl_driver); + gsk_gl_image_destroy (&atlas->image, driver); atlas->image.texture_id = 0; } } @@ -183,7 +179,7 @@ add_to_cache (GskGLGlyphCache *cache, ((DirtyGlyph *)atlas->user_data)->value = value; #ifdef G_ENABLE_DEBUG - if (GSK_RENDERER_DEBUG_CHECK (cache->renderer, GLYPH_CACHE)) + if (GSK_DEBUG_CHECK (GLYPH_CACHE)) { for (i = 0; i < cache->atlases->len; i++) { @@ -265,24 +261,25 @@ render_glyph (const GskGLTextureAtlas *atlas, static void upload_dirty_glyph (GskGLGlyphCache *self, - GskGLTextureAtlas *atlas) + GskGLTextureAtlas *atlas, + GskGLDriver *driver) { GskImageRegion region; g_assert (atlas->user_data != NULL); - gdk_gl_context_push_debug_group_printf (gsk_gl_driver_get_gl_context (self->gl_driver), + gdk_gl_context_push_debug_group_printf (gsk_gl_driver_get_gl_context (driver), "Uploading glyph %d", ((DirtyGlyph *)atlas->user_data)->key->glyph); if (render_glyph (atlas, (DirtyGlyph *)atlas->user_data, ®ion)) { - gsk_gl_image_upload_region (&atlas->image, self->gl_driver, ®ion); + gsk_gl_image_upload_region (&atlas->image, driver, ®ion); g_free (region.data); } - gdk_gl_context_pop_debug_group (gsk_gl_driver_get_gl_context (self->gl_driver)); + gdk_gl_context_pop_debug_group (gsk_gl_driver_get_gl_context (driver)); /* TODO: This could be unnecessary. We can just reuse the allocated * DirtyGlyph next time. */ g_clear_pointer (&atlas->user_data, g_free); @@ -356,9 +353,10 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache, return value; } -GskGLImage * -gsk_gl_glyph_cache_get_glyph_image (GskGLGlyphCache *self, - const GskGLCachedGlyph *glyph) +guint +gsk_gl_glyph_cache_get_glyph_texture_id (GskGLGlyphCache *self, + GskGLDriver *driver, + const GskGLCachedGlyph *glyph) { GskGLTextureAtlas *atlas = glyph->atlas; @@ -366,20 +364,21 @@ gsk_gl_glyph_cache_get_glyph_image (GskGLGlyphCache *self, if (atlas->image.texture_id == 0) { - gsk_gl_image_create (&atlas->image, self->gl_driver, atlas->width, atlas->height, GL_LINEAR, GL_LINEAR); - gdk_gl_context_label_object_printf (gsk_gl_driver_get_gl_context (self->gl_driver), + gsk_gl_image_create (&atlas->image, driver, atlas->width, atlas->height, GL_LINEAR, GL_LINEAR); + gdk_gl_context_label_object_printf (gsk_gl_driver_get_gl_context (driver), GL_TEXTURE, atlas->image.texture_id, "Glyph atlas %d", atlas->image.texture_id); } if (atlas->user_data != NULL) - upload_dirty_glyph (self, atlas); + upload_dirty_glyph (self, atlas, driver); - return &atlas->image; + return atlas->image.texture_id; } void -gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self) +gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self, + GskGLDriver *driver) { int i; GHashTableIter iter; @@ -400,7 +399,7 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self) if (gsk_gl_texture_atlas_get_unused_ratio (atlas) > MAX_OLD_RATIO) { - GSK_RENDERER_NOTE(self->renderer, GLYPH_CACHE, + GSK_NOTE(GLYPH_CACHE, g_message ("Dropping atlas %d (%g.2%% old)", i, gsk_gl_texture_atlas_get_unused_ratio (atlas))); @@ -409,13 +408,13 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self) g_message ("Dropping glyph cache... Ratio: %f", gsk_gl_texture_atlas_get_unused_ratio (atlas)); - gsk_gl_image_write_to_png (&atlas->image, self->gl_driver, + gsk_gl_image_write_to_png (&atlas->image, driver, g_strdup_printf ("dropped_%d.png", kk++)); #endif if (atlas->image.texture_id != 0) { - gsk_gl_image_destroy (&atlas->image, self->gl_driver); + gsk_gl_image_destroy (&atlas->image, driver); atlas->image.texture_id = 0; } @@ -454,7 +453,7 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self) } g_hash_table_unref (removed); - GSK_RENDERER_NOTE(self->renderer, GLYPH_CACHE, if (dropped > 0) g_message ("Dropped %d glyphs", dropped)); + GSK_NOTE(GLYPH_CACHE, if (dropped > 0) g_message ("Dropped %d glyphs", dropped)); #if 0 for (i = 0; i < self->atlases->len; i++) @@ -466,7 +465,7 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self) char *filename; filename = g_strdup_printf ("glyphatlas%d-%ld.png", i, self->timestamp); - gsk_gl_image_write_to_png (atlas->image, self->gl_driver, filename); + gsk_gl_image_write_to_png (atlas->image, driver, filename); g_free (filename); } } diff --git a/gsk/gl/gskglglyphcacheprivate.h b/gsk/gl/gskglglyphcacheprivate.h index 29427f0cd8..c3ab245cf4 100644 --- a/gsk/gl/gskglglyphcacheprivate.h +++ b/gsk/gl/gskglglyphcacheprivate.h @@ -3,16 +3,12 @@ #include "gskgldriverprivate.h" #include "gskglimageprivate.h" -#include "gskrendererprivate.h" #include "gskgltextureatlasprivate.h" #include <pango/pango.h> #include <gdk/gdk.h> typedef struct { - GskGLDriver *gl_driver; - GskRenderer *renderer; - GHashTable *hash_table; GPtrArray *atlases; @@ -56,12 +52,13 @@ struct _GskGLCachedGlyph }; -void gsk_gl_glyph_cache_init (GskGLGlyphCache *self, - GskRenderer *renderer, - GskGLDriver *gl_driver); -void gsk_gl_glyph_cache_free (GskGLGlyphCache *self); -void gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self); -GskGLImage * gsk_gl_glyph_cache_get_glyph_image (GskGLGlyphCache *self, +void gsk_gl_glyph_cache_init (GskGLGlyphCache *self); +void gsk_gl_glyph_cache_free (GskGLGlyphCache *self, + GskGLDriver *driver); +void gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self, + GskGLDriver *driver); +guint gsk_gl_glyph_cache_get_glyph_texture_id (GskGLGlyphCache *self, + GskGLDriver *driver, const GskGLCachedGlyph *glyph); const GskGLCachedGlyph * gsk_gl_glyph_cache_lookup (GskGLGlyphCache *self, gboolean create, diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index 6ea34e396d..c2f5e0abde 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -593,8 +593,9 @@ render_text_node (GskGLRenderer *self, cx = (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE; cy = (double)(gi->geometry.y_offset) / PANGO_SCALE; - ops_set_texture (builder, gsk_gl_glyph_cache_get_glyph_image (&self->glyph_cache, - glyph)->texture_id); + ops_set_texture (builder, gsk_gl_glyph_cache_get_glyph_texture_id (&self->glyph_cache, + self->gl_driver, + glyph)); tx = glyph->tx; ty = glyph->ty; @@ -2495,7 +2496,7 @@ gsk_gl_renderer_realize (GskRenderer *renderer, if (!gsk_gl_renderer_create_programs (self, error)) return FALSE; - gsk_gl_glyph_cache_init (&self->glyph_cache, renderer, self->gl_driver); + gsk_gl_glyph_cache_init (&self->glyph_cache); gsk_gl_icon_cache_init (&self->icon_cache, renderer, self->gl_driver); gsk_gl_shadow_cache_init (&self->shadow_cache); @@ -2521,7 +2522,7 @@ gsk_gl_renderer_unrealize (GskRenderer *renderer) for (i = 0; i < GL_N_PROGRAMS; i ++) glDeleteProgram (self->programs[i].id); - gsk_gl_glyph_cache_free (&self->glyph_cache); + gsk_gl_glyph_cache_free (&self->glyph_cache, self->gl_driver); gsk_gl_icon_cache_free (&self->icon_cache); gsk_gl_shadow_cache_free (&self->shadow_cache, self->gl_driver); @@ -3088,7 +3089,7 @@ gsk_gl_renderer_do_render (GskRenderer *renderer, ORTHO_FAR_PLANE); graphene_matrix_scale (&projection, 1, -1, 1); - gsk_gl_glyph_cache_begin_frame (&self->glyph_cache); + gsk_gl_glyph_cache_begin_frame (&self->glyph_cache, self->gl_driver); gsk_gl_icon_cache_begin_frame (&self->icon_cache); gsk_gl_shadow_cache_begin_frame (&self->shadow_cache, self->gl_driver); |