wayland: release unused buffers after buffer swap

When the surface attaches to a buffer, all other buffers are available.
Export the function used to release a buffer, track the buffer used by
the surface, and release unused buffers when a new buffer is attached.
This commit is contained in:
Richard Acayan 2024-04-22 19:15:47 -04:00
parent 1c606d0274
commit d43f61ec76
4 changed files with 35 additions and 13 deletions

View file

@ -163,16 +163,22 @@ static void on_global_viewporter(void *data,
int ufkbd_wl_surface_consume_buffer(struct ufkbd_wl_surface *ctx,
struct wl_buffer **buf, void **ptr)
{
int ret;
int ret, i;
if (buf == NULL || ptr == NULL)
return -EINVAL;
ret = ufkbd_wl_buffer_consume(&ctx->bufs[0], buf, ptr);
if (ret != -EBUSY)
return ret;
for (i = 0; i < 2; i++) {
ret = ufkbd_wl_buffer_consume(&ctx->bufs[i], buf, ptr);
if (!ret) {
wl_surface_attach(ctx->wl, *buf, 0, 0);
ctx->used_buf = i;
break;
}
ret = ufkbd_wl_buffer_consume(&ctx->bufs[1], buf, ptr);
if (ret != -EBUSY)
break;
}
return ret;
}
@ -195,6 +201,16 @@ static int ufkbd_wl_surface_resize_buffers(struct ufkbd_wl_surface *ctx,
height * ctx->scale);
}
void ufkbd_wl_surface_release_unused(struct ufkbd_wl_surface *ctx)
{
int i;
for (i = 0; i < 2; i++) {
if (i != ctx->used_buf)
ufkbd_wl_buffer_release(&ctx->bufs[i]);
}
}
int ufkbd_wl_surface_init(struct ufkbd_input_wayland *ufkbd_wl,
struct ufkbd_wl_surface **out)
{
@ -207,6 +223,7 @@ int ufkbd_wl_surface_init(struct ufkbd_input_wayland *ufkbd_wl,
ctx->ufkbd_wl = ufkbd_wl;
ctx->scale = 1;
ctx->used_buf = -1;
ret = ufkbd_wl_buffer_init(&ctx->bufs[0], ufkbd_wl, 0);
if (ret)