From d0a615e17b0aa32f20cc7c1d4e0ab97193f85195 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 30 Mar 2011 12:56:09 +0100 Subject: [PATCH] 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. --- clutter/cogl/pango/cogl-pango-glyph-cache.c | 36 ++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/clutter/cogl/pango/cogl-pango-glyph-cache.c b/clutter/cogl/pango/cogl-pango-glyph-cache.c index 62be87399..b1fbd9285 100644 --- a/clutter/cogl/pango/cogl-pango-glyph-cache.c +++ b/clutter/cogl/pango/cogl-pango-glyph-cache.c @@ -46,6 +46,11 @@ struct _CoglPangoGlyphCache /* List of callbacks to invoke when an atlas is reorganized */ 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 optimization in _cogl_pango_glyph_cache_set_dirty_glyphs to avoid 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; } +static void +cogl_pango_glyph_cache_reorganize_cb (void *user_data) +{ + CoglPangoGlyphCache *cache = user_data; + + g_hook_list_invoke (&cache->reorganize_callbacks, FALSE); +} + void cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache) { @@ -142,6 +155,10 @@ cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache) void 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); g_hash_table_unref (cache->hash_table); @@ -178,14 +195,6 @@ cogl_pango_glyph_cache_update_position_cb (void *user_data, 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 cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache, PangoFont *font, @@ -215,6 +224,17 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache, value->tx_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; }