aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-07-16 14:49:27 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-07-17 17:14:42 +0000
commit0751172b922e32a9c6d54b52e721c934cb88fe9f (patch)
tree8e0db05c984983b04584122acd82a5b9468bbbb3
parentshm: refactor: move away from a single, global, buffer list (diff)
shm: get_buffer: purge mismatching buffers in first buffer iteration
There's no longer any need to defer purging of mismatching buffer (i.e. buffers whose width/height doesn't match the requested ones) to after the cache lookup loop.
-rw-r--r--shm.c32
1 files changed, 6 insertions, 26 deletions
diff --git a/shm.c b/shm.c
index acc14a68..f7e7a4c5 100644
--- a/shm.c
+++ b/shm.c
@@ -519,10 +519,12 @@ shm_get_buffer(struct buffer_chain *chain, int width, int height)
tll_foreach(chain->bufs, it) {
struct buffer_private *buf = it->item;
- if (buf->public.width != width)
- continue;
- if (buf->public.height != height)
+ if (buf->public.width != width || buf->public.height != height) {
+ LOG_DBG("purging mismatching buffer %p", (void *)buf);
+ if (buffer_unref_no_remove_from_chain(buf))
+ tll_remove(chain->bufs, it);
continue;
+ }
if (buf->busy)
buf->public.age++;
@@ -559,18 +561,6 @@ shm_get_buffer(struct buffer_chain *chain, int width, int height)
if (cached != NULL)
return &cached->public;
- /* Mark old buffers associated with this cookie for purging */
- tll_foreach(chain->bufs, it) {
- struct buffer_private *buf = it->item;
-
- if (buf->public.width == width && buf->public.height == height)
- continue;
-
- LOG_DBG("marking buffer %p for purging", (void *)buf);
- if (buffer_unref_no_remove_from_chain(buf))
- tll_remove(chain->bufs, it);
- }
-
struct buffer *ret;
get_new_buffers(chain, 1, &width, &height, &ret, false);
return ret;
@@ -909,16 +899,6 @@ shm_unref(struct buffer *_buf)
}
}
-void
-shm_chain_purge(struct buffer_chain *chain)
-{
- tll_foreach(chain->bufs, it) {
- struct buffer_private *buf = it->item;
- if (buffer_unref_no_remove_from_chain(buf))
- tll_remove(chain->bufs, it);
- }
-}
-
struct buffer_chain *
shm_chain_new(struct wl_shm *shm, bool scrollable, size_t pix_instances)
{
@@ -938,6 +918,6 @@ shm_chain_free(struct buffer_chain *chain)
if (chain == NULL)
return;
- shm_chain_purge(chain);
+ shm_purge(chain);
free(chain);
}