From: Matthias Clasen Date: Sat, 12 Oct 2019 05:35:13 +0000 (-0400) Subject: gl: Simplify glyph cache lookup X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~728 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=61db797f29ea545d2f2104e4f549d6ae8d9bce48;p=gtk4.git gl: Simplify glyph cache lookup Make this function more similar to the icon cache equivalent, and simplify it a bit. We don't use the boolean return, and we don't need to look at the age of entry when marking it used. --- diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c index f7cb6fc2c6..21121b1ce5 100644 --- a/gsk/gl/gskglglyphcache.c +++ b/gsk/gl/gskglglyphcache.c @@ -252,11 +252,11 @@ add_to_cache (GskGLGlyphCache *self, upload_glyph (key, value); } -gboolean -gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache, - GlyphCacheKey *lookup, - GskGLDriver *driver, - const GskGLCachedGlyph **cached_glyph_out) +void +gsk_gl_glyph_cache_lookup_or_add (GskGLGlyphCache *cache, + GlyphCacheKey *lookup, + GskGLDriver *driver, + const GskGLCachedGlyph **cached_glyph_out) { GskGLCachedGlyph *value; @@ -264,60 +264,54 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache, if (value) { - const guint age = cache->timestamp - value->timestamp; - - if (age > MAX_FRAME_AGE) + value->timestamp = cache->timestamp; + if (value->atlas && !value->used) { - if (value->atlas && !value->used) - { - gsk_gl_texture_atlas_mark_used (value->atlas, value->draw_width, value->draw_height); - value->used = TRUE; - } + gsk_gl_texture_atlas_mark_used (value->atlas, value->draw_width, value->draw_height); + value->used = TRUE; } - value->timestamp = cache->timestamp; *cached_glyph_out = value; - } - else - { - GlyphCacheKey *key; - PangoRectangle ink_rect; - - pango_font_get_glyph_extents (lookup->font, lookup->glyph, &ink_rect, NULL); - pango_extents_to_pixels (&ink_rect, NULL); - if (lookup->xshift != 0) - ink_rect.width += 1; - if (lookup->yshift != 0) - ink_rect.height += 1; - - value = g_new0 (GskGLCachedGlyph, 1); - - value->draw_x = ink_rect.x; - value->draw_y = ink_rect.y; - value->draw_width = ink_rect.width; - value->draw_height = ink_rect.height; - value->timestamp = cache->timestamp; - value->atlas = NULL; /* For now */ - - key = g_new0 (GlyphCacheKey, 1); - - key->font = g_object_ref (lookup->font); - key->glyph = lookup->glyph; - key->xshift = lookup->xshift; - key->yshift = lookup->yshift; - key->scale = lookup->scale; - key->hash = lookup->hash; - - if (key->scale > 0 && - value->draw_width * key->scale / 1024 > 0 && - value->draw_height * key->scale / 1024 > 0) - add_to_cache (cache, key, driver, value); - - *cached_glyph_out = value; - g_hash_table_insert (cache->hash_table, key, value); + return; } - return (*cached_glyph_out)->atlas != NULL; + { + GlyphCacheKey *key; + PangoRectangle ink_rect; + + pango_font_get_glyph_extents (lookup->font, lookup->glyph, &ink_rect, NULL); + pango_extents_to_pixels (&ink_rect, NULL); + if (lookup->xshift != 0) + ink_rect.width += 1; + if (lookup->yshift != 0) + ink_rect.height += 1; + + value = g_new0 (GskGLCachedGlyph, 1); + + value->draw_x = ink_rect.x; + value->draw_y = ink_rect.y; + value->draw_width = ink_rect.width; + value->draw_height = ink_rect.height; + value->timestamp = cache->timestamp; + value->atlas = NULL; /* For now */ + + key = g_new0 (GlyphCacheKey, 1); + + key->font = g_object_ref (lookup->font); + key->glyph = lookup->glyph; + key->xshift = lookup->xshift; + key->yshift = lookup->yshift; + key->scale = lookup->scale; + key->hash = lookup->hash; + + if (key->scale > 0 && + value->draw_width * key->scale / 1024 > 0 && + value->draw_height * key->scale / 1024 > 0) + add_to_cache (cache, key, driver, value); + + *cached_glyph_out = value; + g_hash_table_insert (cache->hash_table, key, value); + } } void diff --git a/gsk/gl/gskglglyphcacheprivate.h b/gsk/gl/gskglglyphcacheprivate.h index dbe5196cca..259688fbb7 100644 --- a/gsk/gl/gskglglyphcacheprivate.h +++ b/gsk/gl/gskglglyphcacheprivate.h @@ -74,7 +74,7 @@ GskGLGlyphCache * gsk_gl_glyph_cache_ref (GskGLGlyphCache *se void gsk_gl_glyph_cache_unref (GskGLGlyphCache *self); void gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self, GPtrArray *removed_atlases); -gboolean gsk_gl_glyph_cache_lookup (GskGLGlyphCache *self, +void gsk_gl_glyph_cache_lookup_or_add (GskGLGlyphCache *self, GlyphCacheKey *lookup, GskGLDriver *driver, const GskGLCachedGlyph **cached_glyph_out); diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index 2600a35c90..913472f3af 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -587,10 +587,10 @@ render_text_node (GskGLRenderer *self, glyph_cache_key_set_glyph_and_shift (&lookup, gi->glyph, x + cx, y + cy); - gsk_gl_glyph_cache_lookup (self->glyph_cache, - &lookup, - self->gl_driver, - &glyph); + gsk_gl_glyph_cache_lookup_or_add (self->glyph_cache, + &lookup, + self->gl_driver, + &glyph); if (glyph->texture_id == 0) goto next;