[gtk/matthiasc/for-master: 2/2] ngl: Don't cache large glyphs forever




commit f7df384ee1cbd5bba6f15226eeb8215eea89ba55
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 3 13:43:15 2021 -0400

    ngl: Don't cache large glyphs forever
    
    We never put large icons into the icon cache,
    so all its items are always atlased, but we do
    put large glyphs in to the glyph cache, and we
    were never freeing those items, even when they
    go unused. Fix that.

 gsk/ngl/gskngltexturelibrary.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/gsk/ngl/gskngltexturelibrary.c b/gsk/ngl/gskngltexturelibrary.c
index 6e4eb62d4e..7998ae9850 100644
--- a/gsk/ngl/gskngltexturelibrary.c
+++ b/gsk/ngl/gskngltexturelibrary.c
@@ -172,24 +172,41 @@ gsk_ngl_texture_library_begin_frame (GskNglTextureLibrary *self,
 
       GSK_NOTE (GLYPH_CACHE,
                 if (dropped > 0)
-                  g_message ("%s: Dropped %d icons",
+                  g_message ("%s: Dropped %d items",
                              G_OBJECT_TYPE_NAME (self), dropped));
     }
 
   if (frame_id % MAX_FRAME_AGE == 0)
     {
       GskNglTextureAtlasEntry *entry;
+      int atlased = 0;
+      int dropped = 0;
 
       g_hash_table_iter_init (&iter, self->hash_table);
       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&entry))
         {
+          if (!entry->is_atlased && !entry->accessed)
+            {
+              gsk_ngl_driver_release_texture (self->driver, entry->texture);
+              g_hash_table_iter_remove (&iter);
+              dropped++;
+              continue;
+            }
+
           gsk_ngl_texture_atlas_entry_mark_unused (entry);
           entry->accessed = FALSE;
+          if (entry->is_atlased)
+            atlased++;
         }
 
-      GSK_NOTE (GLYPH_CACHE, g_message ("%s: %d atlas items cached",
+      GSK_NOTE (GLYPH_CACHE, g_message ("%s: Dropped %d individual items",
+                                        G_OBJECT_TYPE_NAME (self),
+                                        dropped);
+                             g_message ("%s: %d items cached (%d atlased, %d individually)",
                                         G_OBJECT_TYPE_NAME (self),
-                                        g_hash_table_size (self->hash_table)));
+                                        g_hash_table_size (self->hash_table),
+                                        atlased,
+                                        g_hash_table_size (self->hash_table) - atlased));
     }
 }
 


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