From 7963ba6a0deb5b696050d914ac395bca9c4c06b2 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Fri, 22 Nov 2024 23:18:55 +0300 Subject: [PATCH] buffer: introduce wlr_buffer_finish() --- examples/cairo-buffer.c | 1 + include/wlr/interfaces/wlr_buffer.h | 5 +++++ render/allocator/drm_dumb.c | 2 ++ render/allocator/gbm.c | 6 ++++-- types/buffer/buffer.c | 8 +++++--- types/buffer/client.c | 3 +++ types/buffer/dmabuf.c | 1 + types/buffer/readonly_data.c | 1 + types/wlr_drm.c | 5 ++++- types/wlr_linux_dmabuf_v1.c | 5 ++++- types/wlr_shm.c | 5 ++++- types/wlr_single_pixel_buffer_v1.c | 5 ++++- 12 files changed, 38 insertions(+), 9 deletions(-) diff --git a/examples/cairo-buffer.c b/examples/cairo-buffer.c index 7de4a053b..6392b2ac5 100644 --- a/examples/cairo-buffer.c +++ b/examples/cairo-buffer.c @@ -24,6 +24,7 @@ struct cairo_buffer { static void cairo_buffer_destroy(struct wlr_buffer *wlr_buffer) { struct cairo_buffer *buffer = wl_container_of(wlr_buffer, buffer, base); + wlr_buffer_finish(wlr_buffer); cairo_surface_destroy(buffer->surface); free(buffer); } diff --git a/include/wlr/interfaces/wlr_buffer.h b/include/wlr/interfaces/wlr_buffer.h index 820300f65..4244a00d5 100644 --- a/include/wlr/interfaces/wlr_buffer.h +++ b/include/wlr/interfaces/wlr_buffer.h @@ -36,6 +36,11 @@ struct wlr_buffer_resource_interface { void wlr_buffer_init(struct wlr_buffer *buffer, const struct wlr_buffer_impl *impl, int width, int height); +/** + * Emit the destroy event and clean up common buffer state. + */ +void wlr_buffer_finish(struct wlr_buffer *buffer); + /** * Allows the registration of a struct wl_resource implementation. * diff --git a/render/allocator/drm_dumb.c b/render/allocator/drm_dumb.c index eb4ce99fe..ea2757b0b 100644 --- a/render/allocator/drm_dumb.c +++ b/render/allocator/drm_dumb.c @@ -135,6 +135,8 @@ static bool buffer_get_dmabuf(struct wlr_buffer *wlr_buffer, static void buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_drm_dumb_buffer *buf = drm_dumb_buffer_from_buffer(wlr_buffer); + wlr_buffer_finish(wlr_buffer); + if (buf->data) { munmap(buf->data, buf->size); } diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c index da035c668..3e157bb69 100644 --- a/render/allocator/gbm.c +++ b/render/allocator/gbm.c @@ -155,8 +155,10 @@ static struct wlr_gbm_buffer *create_buffer(struct wlr_gbm_allocator *alloc, } static void buffer_destroy(struct wlr_buffer *wlr_buffer) { - struct wlr_gbm_buffer *buffer = - get_gbm_buffer_from_buffer(wlr_buffer); + struct wlr_gbm_buffer *buffer = get_gbm_buffer_from_buffer(wlr_buffer); + + wlr_buffer_finish(wlr_buffer); + wlr_dmabuf_attributes_finish(&buffer->dmabuf); if (buffer->gbm_bo != NULL) { gbm_bo_destroy(buffer->gbm_bo); diff --git a/types/buffer/buffer.c b/types/buffer/buffer.c index 953207a2c..1438b27b2 100644 --- a/types/buffer/buffer.c +++ b/types/buffer/buffer.c @@ -22,6 +22,11 @@ void wlr_buffer_init(struct wlr_buffer *buffer, wlr_addon_set_init(&buffer->addons); } +void wlr_buffer_finish(struct wlr_buffer *buffer) { + wl_signal_emit_mutable(&buffer->events.destroy, NULL); + wlr_addon_set_finish(&buffer->addons); +} + static void buffer_consider_destroy(struct wlr_buffer *buffer) { if (!buffer->dropped || buffer->n_locks > 0) { return; @@ -29,9 +34,6 @@ static void buffer_consider_destroy(struct wlr_buffer *buffer) { assert(!buffer->accessing_data_ptr); - wl_signal_emit_mutable(&buffer->events.destroy, NULL); - wlr_addon_set_finish(&buffer->addons); - buffer->impl->destroy(buffer); } diff --git a/types/buffer/client.c b/types/buffer/client.c index d96603a45..6aa55386d 100644 --- a/types/buffer/client.c +++ b/types/buffer/client.c @@ -24,6 +24,9 @@ static struct wlr_client_buffer *client_buffer_from_buffer( static void client_buffer_destroy(struct wlr_buffer *buffer) { struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer); + + wlr_buffer_finish(buffer); + wl_list_remove(&client_buffer->source_destroy.link); wl_list_remove(&client_buffer->renderer_destroy.link); wlr_texture_destroy(client_buffer->texture); diff --git a/types/buffer/dmabuf.c b/types/buffer/dmabuf.c index af0c8c5c8..078821e43 100644 --- a/types/buffer/dmabuf.c +++ b/types/buffer/dmabuf.c @@ -15,6 +15,7 @@ static struct wlr_dmabuf_buffer *dmabuf_buffer_from_buffer( static void dmabuf_buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_dmabuf_buffer *buffer = dmabuf_buffer_from_buffer(wlr_buffer); + wlr_buffer_finish(wlr_buffer); if (buffer->saved) { wlr_dmabuf_attributes_finish(&buffer->dmabuf); } diff --git a/types/buffer/readonly_data.c b/types/buffer/readonly_data.c index f934ddc77..1c8fcf126 100644 --- a/types/buffer/readonly_data.c +++ b/types/buffer/readonly_data.c @@ -17,6 +17,7 @@ static struct wlr_readonly_data_buffer *readonly_data_buffer_from_buffer( static void readonly_data_buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_readonly_data_buffer *buffer = readonly_data_buffer_from_buffer(wlr_buffer); + wlr_buffer_finish(wlr_buffer); free(buffer->saved_data); free(buffer); } diff --git a/types/wlr_drm.c b/types/wlr_drm.c index c58cdb4ec..e7e57c3c6 100644 --- a/types/wlr_drm.c +++ b/types/wlr_drm.c @@ -34,11 +34,14 @@ static struct wlr_drm_buffer *drm_buffer_from_buffer( static void buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_drm_buffer *buffer = drm_buffer_from_buffer(wlr_buffer); + wl_list_remove(&buffer->release.link); + + wlr_buffer_finish(wlr_buffer); + if (buffer->resource != NULL) { wl_resource_set_user_data(buffer->resource, NULL); } wlr_dmabuf_attributes_finish(&buffer->dmabuf); - wl_list_remove(&buffer->release.link); free(buffer); } diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c index 7809a29d8..8ccca906a 100644 --- a/types/wlr_linux_dmabuf_v1.c +++ b/types/wlr_linux_dmabuf_v1.c @@ -100,11 +100,14 @@ static struct wlr_dmabuf_v1_buffer *dmabuf_v1_buffer_from_buffer( static void buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_dmabuf_v1_buffer *buffer = dmabuf_v1_buffer_from_buffer(wlr_buffer); + wl_list_remove(&buffer->release.link); + + wlr_buffer_finish(wlr_buffer); + if (buffer->resource != NULL) { wl_resource_set_user_data(buffer->resource, NULL); } wlr_dmabuf_attributes_finish(&buffer->attributes); - wl_list_remove(&buffer->release.link); free(buffer); } diff --git a/types/wlr_shm.c b/types/wlr_shm.c index 1f45c88a3..171724471 100644 --- a/types/wlr_shm.c +++ b/types/wlr_shm.c @@ -155,8 +155,11 @@ static void pool_consider_destroy(struct wlr_shm_pool *pool); static void buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_shm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base); - assert(buffer->resource == NULL); wl_list_remove(&buffer->release.link); + + wlr_buffer_finish(wlr_buffer); + + assert(buffer->resource == NULL); wl_list_remove(&buffer->link); pool_consider_destroy(buffer->pool); free(buffer); diff --git a/types/wlr_single_pixel_buffer_v1.c b/types/wlr_single_pixel_buffer_v1.c index 2dab6c53c..949588ce4 100644 --- a/types/wlr_single_pixel_buffer_v1.c +++ b/types/wlr_single_pixel_buffer_v1.c @@ -53,10 +53,13 @@ static const struct wlr_buffer_resource_interface buffer_resource_interface = { static void buffer_destroy(struct wlr_buffer *wlr_buffer) { struct wlr_single_pixel_buffer_v1 *buffer = wl_container_of(wlr_buffer, buffer, base); + wl_list_remove(&buffer->release.link); + + wlr_buffer_finish(wlr_buffer); + if (buffer->resource != NULL) { wl_resource_set_user_data(buffer->resource, NULL); } - wl_list_remove(&buffer->release.link); free(buffer); }