gl renderer: Change shadow cache eviction strategy

Since we can do partial redraws, dropping every shadow that's been
unused for one frame happens too fast. This is also a problem when a
shadow gets drawn on a texture for a few frames.
This commit is contained in:
Timm Bäder 2019-02-28 10:12:17 +01:00
parent 416a4cf5ea
commit 7931ab5f33

View File

@ -1,6 +1,8 @@
#include "gskglshadowcacheprivate.h"
#define MAX_UNUSED_FRAMES (16 * 5) /* 5 seconds? */
typedef struct
{
GskRoundedRect outline;
@ -13,7 +15,7 @@ typedef struct
float blur_radius;
int texture_id;
guint used : 1;
int unused_frames;
} CacheItem;
static gboolean
@ -67,7 +69,7 @@ gsk_gl_shadow_cache_begin_frame (GskGLShadowCache *self,
{
CacheItem *item = &g_array_index (self->textures, CacheItem, i);
if (!item->used)
if (item->unused_frames > MAX_UNUSED_FRAMES)
{
gsk_gl_driver_destroy_texture (gl_driver, item->texture_id);
g_array_remove_index_fast (self->textures, i);
@ -76,7 +78,7 @@ gsk_gl_shadow_cache_begin_frame (GskGLShadowCache *self,
}
else
{
item->used = FALSE;
item->unused_frames ++;
}
}
}
@ -113,7 +115,7 @@ gsk_gl_shadow_cache_get_texture_id (GskGLShadowCache *self,
if (item == NULL)
return 0;
item->used = TRUE;
item->unused_frames = 0;
g_assert (item->texture_id != 0);
@ -137,6 +139,6 @@ gsk_gl_shadow_cache_commit (GskGLShadowCache *self,
item->outline = *shadow_rect;
item->blur_radius = blur_radius;
item->used = TRUE;
item->unused_frames = 0;
item->texture_id = texture_id;
}