ngl: Don't cache large glyphs forever
authorMatthias Clasen <mclasen@redhat.com>
Sun, 3 Oct 2021 17:43:15 +0000 (13:43 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 3 Oct 2021 17:43:15 +0000 (13:43 -0400)
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

index 6e4eb62d4eb0ac2452969d1940285e460ebf598b..7998ae98502609641871793375f144ddafd401b4 100644 (file)
@@ -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));
     }
 }