From bd9ea05ebb5b0bf145941dd6be04aa68f100bb20 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 19 Jan 2024 11:25:56 -0500 Subject: [PATCH] gpu: Evict stale textures from the cache This is straightforward. If a texture hasn't been used for 4 seconds, we consider it stale, and drop it the next time gc comes around. The choice of 4 seconds is arbitrary. Fixes: #6346 --- gsk/gpu/gskgpudevice.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gsk/gpu/gskgpudevice.c b/gsk/gpu/gskgpudevice.c index 73d7c3fce5..332754189a 100644 --- a/gsk/gpu/gskgpudevice.c +++ b/gsk/gpu/gskgpudevice.c @@ -20,6 +20,8 @@ G_STATIC_ASSERT (MAX_ATLAS_ITEM_SIZE < ATLAS_SIZE); #define CACHE_GC_TIMEOUT 15 /* seconds */ +#define CACHE_MAX_AGE (G_TIME_SPAN_SECOND * 4) /* 4 seconds, in µs */ + typedef struct _GskGpuCached GskGpuCached; typedef struct _GskGpuCachedClass GskGpuCachedClass; typedef struct _GskGpuCachedAtlas GskGpuCachedAtlas; @@ -64,6 +66,8 @@ struct _GskGpuCached GskGpuCachedAtlas *atlas; GskGpuCached *next; GskGpuCached *prev; + + gint64 timestamp; }; static void @@ -120,7 +124,7 @@ gsk_gpu_cached_use (GskGpuDevice *device, GskGpuCached *cached, gint64 timestamp) { - /* FIXME */ + cached->timestamp = timestamp; } /* }}} */ @@ -207,8 +211,7 @@ gsk_gpu_cached_texture_should_collect (GskGpuDevice *device, GskGpuCached *cached, gint64 timestamp) { - /* FIXME */ - return FALSE; + return timestamp - cached->timestamp > CACHE_MAX_AGE; } static const GskGpuCachedClass GSK_GPU_CACHED_TEXTURE_CLASS =