shm: auto-purge when we have multiple buffers eligible for re-use

It may happen that we end up with multiple non-busy, same-sized
buffers for the same cookie (context), and thus eligible for re-use.

Before this patch, we would keep all those buffers around. This is
completely unnecessary. Under normal circumstances, we’ll either be
re-using a single buffer, or swap between two. In the second case, the
“other” buffer is always busy, and thus not eligible for re-use.

So, if we _do_ detect multiple, re-usable buffers, pick the one with
the lowest “age” (increasing the chance of applying damage tracking,
instead of re-drawing everything), and mark the other one for purging.
This commit is contained in:
Daniel Eklöf 2021-07-15 19:19:31 +02:00
parent 5d7b729ac5
commit a486851bdd
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

9
shm.c
View file

@ -494,6 +494,15 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
it->item.scroll_damage = NULL;
xassert(it->item.pix_instances == pix_instances);
cached = &it->item;
} else {
/* We have multiple buffers eligable for
* re-use. Pick the youngest one, and mark the
* other one for purging */
if (it->item.age < cached->age) {
cached->purge = true;
cached = &it->item;
} else
it->item.purge = true;
}
}
}