mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
shm: purge unused buffers
When we need to create a new buffer (because the cache doesn't have any buffers of correct size, or because they're all busy), purge buffers with a size mismatch.
This commit is contained in:
parent
00b46455a0
commit
5812242405
1 changed files with 28 additions and 7 deletions
35
shm.c
35
shm.c
|
|
@ -17,6 +17,15 @@
|
|||
|
||||
static tll(struct buffer) buffers;
|
||||
|
||||
static void
|
||||
buffer_destroy(struct buffer *buf)
|
||||
{
|
||||
if (buf->pix != NULL)
|
||||
pixman_image_unref(buf->pix);
|
||||
wl_buffer_destroy(buf->wl_buf);
|
||||
munmap(buf->mmapped, buf->size);
|
||||
}
|
||||
|
||||
static void
|
||||
buffer_release(void *data, struct wl_buffer *wl_buffer)
|
||||
{
|
||||
|
|
@ -48,6 +57,24 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
|
|||
}
|
||||
}
|
||||
|
||||
/* Purge old buffers associated with this cookie */
|
||||
tll_foreach(buffers, it) {
|
||||
if (it->item.cookie != cookie)
|
||||
continue;
|
||||
|
||||
if (it->item.busy)
|
||||
continue;
|
||||
|
||||
if (it->item.width == width && it->item.height == height)
|
||||
continue;
|
||||
|
||||
LOG_DBG("cookie=%lx: purging buffer (width=%d, height=%d)",
|
||||
cookie, it->item.width, it->item.height);
|
||||
|
||||
buffer_destroy(&it->item);
|
||||
tll_remove(buffers, it);
|
||||
}
|
||||
|
||||
/*
|
||||
* No existing buffer available. Create a new one by:
|
||||
*
|
||||
|
|
@ -151,13 +178,7 @@ void
|
|||
shm_fini(void)
|
||||
{
|
||||
tll_foreach(buffers, it) {
|
||||
struct buffer *buf = &it->item;
|
||||
|
||||
if (buf->pix != NULL)
|
||||
pixman_image_unref(buf->pix);
|
||||
wl_buffer_destroy(buf->wl_buf);
|
||||
munmap(buf->mmapped, buf->size);
|
||||
|
||||
buffer_destroy(&it->item);
|
||||
tll_remove(buffers, it);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue