aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-05-07 16:18:35 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-05-12 18:06:04 +0000
commitc8b342ae51cba357f21a3f6c77f6a527981101b8 (patch)
tree1c6b4a2b31997883b9c4cc5c0182c8a1863e2401 /shm.c
parentwayland: codespell: pre-empt -> preempt (diff)
shm: track busy buffers’ age, and add compile-time option to force double buffering
By default, age all matching buffers that are busy (i.e. in use by the compositor). This allows us to detect whether we can apply the current frame’s damage directly, or if we need to prepare the buffer first (e.g. copy old buffer, or re-apply last frame’s damage etc).
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/shm.c b/shm.c
index 2ec581c4..a39c7c34 100644
--- a/shm.c
+++ b/shm.c
@@ -30,6 +30,8 @@
#define TIME_SCROLL 0
+#define FORCED_DOUBLE_BUFFERING 0
+
/*
* Maximum memfd size allowed.
*
@@ -222,6 +224,8 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
tll_remove(buffers, it);
}
+ struct buffer *cached = NULL;
+
tll_foreach(buffers, it) {
if (it->item.width != width)
continue;
@@ -230,16 +234,27 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
if (it->item.cookie != cookie)
continue;
- if (!it->item.busy) {
- LOG_DBG("cookie=%lx: re-using buffer from cache (buf=%p)",
- cookie, (void *)&it->item);
- it->item.busy = true;
- it->item.purge = false;
- xassert(it->item.pix_instances == pix_instances);
- return &it->item;
- }
+ if (it->item.busy)
+ it->item.age++;
+ else
+#if FORCED_DOUBLE_BUFFERING
+ if (it->item.age == 0)
+ it->item.age++;
+ else
+#endif
+ {
+ LOG_DBG("cookie=%lx: re-using buffer from cache (buf=%p)",
+ cookie, (void *)&it->item);
+ it->item.busy = true;
+ it->item.purge = false;
+ xassert(it->item.pix_instances == pix_instances);
+ cached = &it->item;
+ }
}
+ if (cached != NULL)
+ return cached;
+
/* Purge old buffers associated with this cookie */
tll_foreach(buffers, it) {
if (it->item.cookie != cookie)
@@ -376,9 +391,9 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
.scrollable = scrollable,
.real_mmapped = real_mmapped,
.mmap_size = memfd_size,
- .offset = 0}
- )
- );
+ .offset = 0,
+ .age = 0,
+ }));
struct buffer *ret = &tll_back(buffers);
if (!instantiate_offset(shm, ret, initial_offset))