gsk/gl: only clear glyph cache durign reclaimation
authorChristian Hergert <chergert@redhat.com>
Tue, 15 Mar 2022 22:55:30 +0000 (15:55 -0700)
committerChristian Hergert <chergert@redhat.com>
Fri, 18 Mar 2022 19:33:33 +0000 (12:33 -0700)
We don't need to clear the front cache on every frame as we can clear it
specifically when we do reclaimation to avoid unnecessary memset() calls.

gsk/gl/gskglglyphlibrary.c
gsk/gl/gskgltexturelibrary.c
gsk/gl/gskgltexturelibraryprivate.h

index b749384674ac28262624a08cc89485616e1e42fe..ee13198921f6f9c7447bab533f03349ec63e58e4 100644 (file)
@@ -84,12 +84,12 @@ gsk_gl_glyph_value_free (gpointer data)
 }
 
 static void
-gsk_gl_glyph_library_begin_frame (GskGLTextureLibrary *library,
-                                  gint64               frame_id,
-                                  GPtrArray           *removed_atlases)
+gsk_gl_glyph_library_clear_cache (GskGLTextureLibrary *library)
 {
   GskGLGlyphLibrary *self = (GskGLGlyphLibrary *)library;
 
+  g_assert (GSK_IS_GL_GLYPH_LIBRARY (self));
+
   memset (self->front, 0, sizeof self->front);
 }
 
@@ -111,7 +111,7 @@ gsk_gl_glyph_library_class_init (GskGLGlyphLibraryClass *klass)
 
   object_class->finalize = gsk_gl_glyph_library_finalize;
 
-  library_class->begin_frame = gsk_gl_glyph_library_begin_frame;
+  library_class->clear_cache = gsk_gl_glyph_library_clear_cache;
 }
 
 static void
index fadec60a0ca6bd8cc7865387e3df33d76b1fdde9..b0694e7afb8cd0d941444d2e44f26760c4c213e0 100644 (file)
@@ -141,6 +141,7 @@ gsk_gl_texture_library_begin_frame (GskGLTextureLibrary *self,
                                     GPtrArray            *removed_atlases)
 {
   GHashTableIter iter;
+  gboolean drop_caches = FALSE;
 
   g_return_if_fail (GSK_IS_GL_TEXTURE_LIBRARY (self));
 
@@ -175,6 +176,8 @@ gsk_gl_texture_library_begin_frame (GskGLTextureLibrary *self,
                 if (dropped > 0)
                   g_message ("%s: Dropped %d items",
                              G_OBJECT_TYPE_NAME (self), dropped));
+
+      drop_caches |= dropped > 0;
     }
 
   if (frame_id % self->max_frame_age == 0)
@@ -208,7 +211,12 @@ gsk_gl_texture_library_begin_frame (GskGLTextureLibrary *self,
                                         g_hash_table_size (self->hash_table),
                                         atlased,
                                         g_hash_table_size (self->hash_table) - atlased));
+
+      drop_caches |= dropped > 0;
     }
+
+  if (drop_caches && GSK_GL_TEXTURE_LIBRARY_GET_CLASS (self)->clear_cache)
+    GSK_GL_TEXTURE_LIBRARY_GET_CLASS (self)->clear_cache (self);
 }
 
 static GskGLTexture *
index bb1db121721a491c59a72538027f9f86b27e9f89..39276ff69d896c8ca2c3a5e8abfc3c607bfdfca4 100644 (file)
@@ -103,6 +103,7 @@ typedef struct _GskGLTextureLibraryClass
   void (*begin_frame) (GskGLTextureLibrary *library,
                        gint64               frame_id,
                        GPtrArray           *removed_atlases);
+  void (*clear_cache) (GskGLTextureLibrary *library);
 } GskGLTextureLibraryClass;
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GskGLTextureLibrary, g_object_unref)