cogl-pango-glyph-cache: Don't put zero-sized glyphs in the cache

It now avoids trying to reserve space for zero-sized glyphs. That
happens for example when the layout contains a space. This was causing
the regular glyph cache to be used because the global atlas does not
support zero-sized images. That would then break up the
batching. Instead it now still reserves an entry in the cache but
leaves the texture as COGL_INVALID_HANDLE.
This commit is contained in:
Neil Roberts 2010-02-22 16:40:49 +00:00
parent 0c755f6909
commit 22ce8a7111
2 changed files with 30 additions and 16 deletions

View File

@ -70,7 +70,8 @@ struct _CoglPangoGlyphCacheKey
static void static void
cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value) cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value)
{ {
cogl_handle_unref (value->texture); if (value->texture)
cogl_handle_unref (value->texture);
g_slice_free (CoglPangoGlyphCacheValue, value); g_slice_free (CoglPangoGlyphCacheValue, value);
} }
@ -307,7 +308,6 @@ cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache,
value = g_slice_new (CoglPangoGlyphCacheValue); value = g_slice_new (CoglPangoGlyphCacheValue);
value->texture = COGL_INVALID_HANDLE; value->texture = COGL_INVALID_HANDLE;
value->dirty = TRUE;
pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL); pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
pango_extents_to_pixels (&ink_rect, NULL); pango_extents_to_pixels (&ink_rect, NULL);
@ -317,18 +317,29 @@ cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache,
value->draw_width = ink_rect.width; value->draw_width = ink_rect.width;
value->draw_height = ink_rect.height; value->draw_height = ink_rect.height;
/* Try adding the glyph to the global atlas... */ /* If the glyph is zero-sized then we don't need to reserve any
if (!cogl_pango_glyph_cache_add_to_global_atlas (cache, space for it and we can just avoid painting anything */
font, if (ink_rect.width < 1 || ink_rect.height < 1)
glyph, value->dirty = FALSE;
value) && else
!cogl_pango_glyph_cache_add_to_local_atlas (cache,
font,
glyph,
value))
{ {
cogl_pango_glyph_cache_value_free (value); /* Try adding the glyph to the global atlas... */
return NULL; if (!cogl_pango_glyph_cache_add_to_global_atlas (cache,
font,
glyph,
value) &&
/* If it fails try the local atlas */
!cogl_pango_glyph_cache_add_to_local_atlas (cache,
font,
glyph,
value))
{
cogl_pango_glyph_cache_value_free (value);
return NULL;
}
value->dirty = TRUE;
cache->has_dirty_glyphs = TRUE;
} }
key = g_slice_new (CoglPangoGlyphCacheKey); key = g_slice_new (CoglPangoGlyphCacheKey);
@ -336,8 +347,6 @@ cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache,
key->glyph = glyph; key->glyph = glyph;
g_hash_table_insert (cache->hash_table, key, value); g_hash_table_insert (cache->hash_table, key, value);
cache->has_dirty_glyphs = TRUE;
} }
return value; return value;

View File

@ -501,6 +501,11 @@ cogl_pango_renderer_set_dirty_glyph (PangoFont *font,
COGL_NOTE (PANGO, "redrawing glyph %i", glyph); COGL_NOTE (PANGO, "redrawing glyph %i", glyph);
/* Glyphs that don't take up any space will end up without a
texture. These should never become dirty so they shouldn't end up
here */
g_return_if_fail (value->texture != COGL_INVALID_HANDLE);
surface = cairo_image_surface_create (CAIRO_FORMAT_A8, surface = cairo_image_surface_create (CAIRO_FORMAT_A8,
value->draw_width, value->draw_width,
value->draw_height); value->draw_height);
@ -824,7 +829,7 @@ cogl_pango_renderer_draw_glyphs (PangoRenderer *renderer,
PANGO_UNKNOWN_GLYPH_WIDTH, PANGO_UNKNOWN_GLYPH_WIDTH,
PANGO_UNKNOWN_GLYPH_HEIGHT); PANGO_UNKNOWN_GLYPH_HEIGHT);
} }
else else if (cache_value->texture)
{ {
x += (float)(cache_value->draw_x); x += (float)(cache_value->draw_x);
y += (float)(cache_value->draw_y); y += (float)(cache_value->draw_y);