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.
This commit is contained in:
Matthias Clasen
2019-10-12 01:35:13 -04:00
parent 0a876f11a0
commit 61db797f29
3 changed files with 52 additions and 58 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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;