Skip to content

Commit

Permalink
gsk/gl: only clear glyph cache durign reclaimation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chergert committed Mar 18, 2022
1 parent 7062411 commit a66a0dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gsk/gl/gskglglyphlibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions gsk/gl/gskgltexturelibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 *
Expand Down
1 change: 1 addition & 0 deletions gsk/gl/gskgltexturelibraryprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a66a0dd

Please sign in to comment.