cogl-pango-glyph-cache: Notify of reorg for global atlased glyphs

Whenever the glyph cache puts a glyph in the global atlas it will now
register for notifications of reorganisation of the global
atlases. When this happens it will forward this on as a notification
of reorganisation of the glyph cache.
This commit is contained in:
Neil Roberts 2011-03-30 12:56:09 +01:00 committed by Robert Bragg
parent 239614a375
commit 28b0f76cc9

View File

@ -46,6 +46,11 @@ struct _CoglPangoGlyphCache
/* List of callbacks to invoke when an atlas is reorganized */ /* List of callbacks to invoke when an atlas is reorganized */
GHookList reorganize_callbacks; GHookList reorganize_callbacks;
/* TRUE if we've ever stored a texture in the global atlas. This is
used to make sure we only register one callback to listen for
global atlas reorganizations */
gboolean using_global_atlas;
/* True if some of the glyphs are dirty. This is used as an /* True if some of the glyphs are dirty. This is used as an
optimization in _cogl_pango_glyph_cache_set_dirty_glyphs to avoid optimization in _cogl_pango_glyph_cache_set_dirty_glyphs to avoid
iterating the hash table if we know none of them are dirty */ iterating the hash table if we know none of them are dirty */
@ -128,6 +133,14 @@ cogl_pango_glyph_cache_new (gboolean use_mipmapping)
return cache; return cache;
} }
static void
cogl_pango_glyph_cache_reorganize_cb (void *user_data)
{
CoglPangoGlyphCache *cache = user_data;
g_hook_list_invoke (&cache->reorganize_callbacks, FALSE);
}
void void
cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache) cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache)
{ {
@ -142,6 +155,10 @@ cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache)
void void
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache) cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache)
{ {
if (cache->using_global_atlas)
_cogl_atlas_texture_remove_reorganize_callback
(cogl_pango_glyph_cache_reorganize_cb, cache);
cogl_pango_glyph_cache_clear (cache); cogl_pango_glyph_cache_clear (cache);
g_hash_table_unref (cache->hash_table); g_hash_table_unref (cache->hash_table);
@ -178,14 +195,6 @@ cogl_pango_glyph_cache_update_position_cb (void *user_data,
value->dirty = TRUE; value->dirty = TRUE;
} }
static void
cogl_pango_glyph_cache_reorganize_cb (void *user_data)
{
CoglPangoGlyphCache *cache = user_data;
g_hook_list_invoke (&cache->reorganize_callbacks, FALSE);
}
static gboolean static gboolean
cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache, cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
PangoFont *font, PangoFont *font,
@ -215,6 +224,17 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
value->tx_pixel = 0; value->tx_pixel = 0;
value->ty_pixel = 0; value->ty_pixel = 0;
/* The first time we store a texture in the global atlas we'll
register for notifications when the global atlas is reorganized
so we can forward the notification on as a glyph
reorganization */
if (!cache->using_global_atlas)
{
_cogl_atlas_texture_add_reorganize_callback
(cogl_pango_glyph_cache_reorganize_cb, cache);
cache->using_global_atlas = TRUE;
}
return TRUE; return TRUE;
} }