[gtk/big-glyphs] gl: Improve cache dropping code



commit 040562ed3b8e0f61e678df8e1c477515b81ef33d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 2 20:54:11 2019 +0000

    gl: Improve cache dropping code
    
    There was a TODO here to avoid iterating the
    glyphs multiple times, so avoid that. And
    actually log the number of glyphs that was dropped.

 gsk/gl/gskglglyphcache.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c
index 0af8301f94..40a94a9bea 100644
--- a/gsk/gl/gskglglyphcache.c
+++ b/gsk/gl/gskglglyphcache.c
@@ -381,7 +381,7 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self)
   GHashTableIter iter;
   GlyphCacheKey *key;
   GskGLCachedGlyph *value;
-  guint dropped = 0;
+  GHashTable *removed = g_hash_table_new (g_direct_hash, g_direct_equal);
 
   self->timestamp++;
 
@@ -421,18 +421,43 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self)
               atlas->image->texture_id = 0;
             }
 
-          /* Remove all glyphs that point to this atlas */
-          g_hash_table_iter_init (&iter, self->hash_table);
-          while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value))
-            {
-              if (value->atlas == atlas)
-                g_hash_table_iter_remove (&iter);
-            }
-          /* TODO: The above loop inside this other loop could be slow... */
+          g_hash_table_add (removed, atlas);
 
           g_ptr_array_remove_index (self->atlases, i);
+       }
+    }
+
+  if (g_hash_table_size (removed) > 0)
+    {
+      guint dropped = 0;
+
+      /* Remove all glyphs whose atlas was removed */
+      g_hash_table_iter_init (&iter, self->hash_table);
+      while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value))
+        {
+          if (g_hash_table_contains (removed, value->atlas))
+            {
+              g_hash_table_iter_remove (&iter);
+              dropped++;
+            }
         }
+
+      GSK_RENDERER_NOTE(self->renderer, GLYPH_CACHE, if (dropped > 0) g_message ("Dropped %d glyphs", 
dropped));
     }
 
-  GSK_RENDERER_NOTE(self->renderer, GLYPH_CACHE, g_message ("Dropped %d glyphs", dropped));
+  g_hash_table_unref (removed);
+
+  for (i = 0; i < self->atlases->len; i++)
+    {
+      GskGLGlyphAtlas *atlas = g_ptr_array_index (self->atlases, i);
+
+      if (atlas->image)
+        {
+          char *filename;
+
+          filename = g_strdup_printf ("glyphatlas%d-%ld.png", i, self->timestamp);
+          gsk_gl_image_write_to_png (atlas->image, self->gl_driver, filename);
+          g_free (filename);
+        }
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]