shm: purge buffers *before* we (maybe) return one from the cache

This commit is contained in:
Daniel Eklöf 2019-11-02 01:31:48 +01:00
parent bf9aff056a
commit 6ed97a47be
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

32
shm.c
View file

@ -42,22 +42,6 @@ static const struct wl_buffer_listener buffer_listener = {
struct buffer *
shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
{
tll_foreach(buffers, it) {
if (it->item.width != width)
continue;
if (it->item.height != height)
continue;
if (it->item.cookie != cookie)
continue;
if (!it->item.busy) {
LOG_DBG("cookie=%lx: re-using buffer from cache", cookie);
it->item.busy = true;
it->item.purge = false;
return &it->item;
}
}
/* Purge buffers marked for purging */
tll_foreach(buffers, it) {
if (it->item.cookie != cookie)
@ -75,6 +59,22 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
tll_remove(buffers, it);
}
tll_foreach(buffers, it) {
if (it->item.width != width)
continue;
if (it->item.height != height)
continue;
if (it->item.cookie != cookie)
continue;
if (!it->item.busy) {
LOG_DBG("cookie=%lx: re-using buffer from cache", cookie);
it->item.busy = true;
it->item.purge = false;
return &it->item;
}
}
/* Purge old buffers associated with this cookie */
tll_foreach(buffers, it) {
if (it->item.cookie != cookie)