aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-05-12 18:07:40 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-05-12 18:07:40 +0000
commit04215bac6cc3f7c05276adcc0ab47a6d799d4d25 (patch)
treeeb4c0ac447c3b0f5ce9ac85f1fc161db249d9f13 /shm.c
parentwayland: codespell: pre-empt -> preempt (diff)
parentchangelog: improved performance when double buffering (diff)
Merge branch 'double-buffering'
Closes #478
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/shm.c b/shm.c
index 2ec581c4..ed20af3a 100644
--- a/shm.c
+++ b/shm.c
@@ -30,6 +30,8 @@
#define TIME_SCROLL 0
+#define FORCED_DOUBLE_BUFFERING 0
+
/*
* Maximum memfd size allowed.
*
@@ -100,6 +102,9 @@ buffer_destroy(struct buffer *buf)
buf->real_mmapped = MAP_FAILED;
buf->pool = NULL;
buf->fd = -1;
+
+ free(buf->scroll_damage);
+ pixman_region32_fini(&buf->dirty);
}
void
@@ -222,6 +227,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 +237,30 @@ 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;
+ pixman_region32_clear(&it->item.dirty);
+ free(it->item.scroll_damage);
+ it->item.scroll_damage = NULL;
+ 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,14 +397,16 @@ 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 = 1234, /* Force a full repaint */
+ }));
struct buffer *ret = &tll_back(buffers);
if (!instantiate_offset(shm, ret, initial_offset))
goto err;
+ pixman_region32_init(&ret->dirty);
+
#if defined(MEASURE_SHM_ALLOCS) && MEASURE_SHM_ALLOCS
{
size_t currently_alloced = 0;