diff options
-rw-r--r-- | include/types/wlr_buffer.h | 22 | ||||
-rw-r--r-- | types/buffer/resource.c | 10 | ||||
-rw-r--r-- | types/buffer/shm_client.c | 125 | ||||
-rw-r--r-- | types/meson.build | 1 |
4 files changed, 1 insertions, 157 deletions
diff --git a/include/types/wlr_buffer.h b/include/types/wlr_buffer.h index 59d78e9c..f34b03a8 100644 --- a/include/types/wlr_buffer.h +++ b/include/types/wlr_buffer.h @@ -3,28 +3,6 @@ #include <wlr/types/wlr_buffer.h> -struct wlr_shm_client_buffer { - struct wlr_buffer base; - - uint32_t format; - size_t stride; - - // The following fields are NULL if the client has destroyed the wl_buffer - struct wl_resource *resource; - struct wl_shm_buffer *shm_buffer; - - // This is used to keep the backing storage alive after the client has - // destroyed the wl_buffer - struct wl_shm_pool *saved_shm_pool; - void *saved_data; - - struct wl_listener resource_destroy; - struct wl_listener release; -}; - -struct wlr_shm_client_buffer *shm_client_buffer_get_or_create( - struct wl_resource *resource); - /** * A read-only buffer that holds a data pointer. * diff --git a/types/buffer/resource.c b/types/buffer/resource.c index 14d315fb..8d39b6b9 100644 --- a/types/buffer/resource.c +++ b/types/buffer/resource.c @@ -49,15 +49,7 @@ struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) { assert(resource && wlr_resource_is_buffer(resource)); struct wlr_buffer *buffer; - if (wl_shm_buffer_get(resource) != NULL) { - struct wlr_shm_client_buffer *shm_client_buffer = - shm_client_buffer_get_or_create(resource); - if (shm_client_buffer == NULL) { - wlr_log(WLR_ERROR, "Failed to create shm client buffer"); - return NULL; - } - buffer = wlr_buffer_lock(&shm_client_buffer->base); - } else if (wlr_dmabuf_v1_resource_is_buffer(resource)) { + if (wlr_dmabuf_v1_resource_is_buffer(resource)) { struct wlr_dmabuf_v1_buffer *dmabuf = wlr_dmabuf_v1_buffer_from_buffer_resource(resource); buffer = wlr_buffer_lock(&dmabuf->base); diff --git a/types/buffer/shm_client.c b/types/buffer/shm_client.c deleted file mode 100644 index 55f2dea2..00000000 --- a/types/buffer/shm_client.c +++ /dev/null @@ -1,125 +0,0 @@ -#include <assert.h> -#include <stdlib.h> -#include <wayland-server.h> -#include <wlr/interfaces/wlr_buffer.h> -#include "render/pixel_format.h" -#include "types/wlr_buffer.h" - -static const struct wlr_buffer_impl shm_client_buffer_impl; - -static bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer) { - return buffer->impl == &shm_client_buffer_impl; -} - -static struct wlr_shm_client_buffer *shm_client_buffer_from_buffer( - struct wlr_buffer *buffer) { - assert(buffer_is_shm_client_buffer(buffer)); - return (struct wlr_shm_client_buffer *)buffer; -} - -static void shm_client_buffer_destroy(struct wlr_buffer *wlr_buffer) { - struct wlr_shm_client_buffer *buffer = - shm_client_buffer_from_buffer(wlr_buffer); - wl_list_remove(&buffer->resource_destroy.link); - wl_list_remove(&buffer->release.link); - if (buffer->saved_shm_pool != NULL) { - wl_shm_pool_unref(buffer->saved_shm_pool); - } - free(buffer); -} - -static bool shm_client_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer, - uint32_t flags, void **data, uint32_t *format, size_t *stride) { - struct wlr_shm_client_buffer *buffer = - shm_client_buffer_from_buffer(wlr_buffer); - *format = buffer->format; - *stride = buffer->stride; - if (buffer->shm_buffer != NULL) { - *data = wl_shm_buffer_get_data(buffer->shm_buffer); - wl_shm_buffer_begin_access(buffer->shm_buffer); - } else { - *data = buffer->saved_data; - } - return true; -} - -static void shm_client_buffer_end_data_ptr_access(struct wlr_buffer *wlr_buffer) { - struct wlr_shm_client_buffer *buffer = - shm_client_buffer_from_buffer(wlr_buffer); - if (buffer->shm_buffer != NULL) { - wl_shm_buffer_end_access(buffer->shm_buffer); - } -} - -static const struct wlr_buffer_impl shm_client_buffer_impl = { - .destroy = shm_client_buffer_destroy, - .begin_data_ptr_access = shm_client_buffer_begin_data_ptr_access, - .end_data_ptr_access = shm_client_buffer_end_data_ptr_access, -}; - -static void shm_client_buffer_resource_handle_destroy( - struct wl_listener *listener, void *data) { - struct wlr_shm_client_buffer *buffer = - wl_container_of(listener, buffer, resource_destroy); - - // In order to still be able to access the shared memory region, we need to - // keep a reference to the wl_shm_pool - buffer->saved_shm_pool = wl_shm_buffer_ref_pool(buffer->shm_buffer); - buffer->saved_data = wl_shm_buffer_get_data(buffer->shm_buffer); - - // The wl_shm_buffer destroys itself with the wl_resource - buffer->resource = NULL; - buffer->shm_buffer = NULL; - wl_list_remove(&buffer->resource_destroy.link); - wl_list_init(&buffer->resource_destroy.link); - - // This might destroy the buffer - wlr_buffer_drop(&buffer->base); -} - -static void shm_client_buffer_handle_release(struct wl_listener *listener, - void *data) { - struct wlr_shm_client_buffer *buffer = - wl_container_of(listener, buffer, release); - if (buffer->resource != NULL) { - wl_buffer_send_release(buffer->resource); - } -} - -struct wlr_shm_client_buffer *shm_client_buffer_get_or_create( - struct wl_resource *resource) { - struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(resource); - assert(shm_buffer != NULL); - - struct wl_listener *resource_destroy_listener = - wl_resource_get_destroy_listener(resource, - shm_client_buffer_resource_handle_destroy); - if (resource_destroy_listener != NULL) { - struct wlr_shm_client_buffer *buffer = - wl_container_of(resource_destroy_listener, buffer, resource_destroy); - return buffer; - } - - int32_t width = wl_shm_buffer_get_width(shm_buffer); - int32_t height = wl_shm_buffer_get_height(shm_buffer); - - struct wlr_shm_client_buffer *buffer = calloc(1, sizeof(*buffer)); - if (buffer == NULL) { - return NULL; - } - wlr_buffer_init(&buffer->base, &shm_client_buffer_impl, width, height); - buffer->resource = resource; - buffer->shm_buffer = shm_buffer; - - enum wl_shm_format wl_shm_format = wl_shm_buffer_get_format(shm_buffer); - buffer->format = convert_wl_shm_format_to_drm(wl_shm_format); - buffer->stride = wl_shm_buffer_get_stride(shm_buffer); - - buffer->resource_destroy.notify = shm_client_buffer_resource_handle_destroy; - wl_resource_add_destroy_listener(resource, &buffer->resource_destroy); - - buffer->release.notify = shm_client_buffer_handle_release; - wl_signal_add(&buffer->base.events.release, &buffer->release); - - return buffer; -} diff --git a/types/meson.build b/types/meson.build index 2e547cfe..5bc217eb 100644 --- a/types/meson.build +++ b/types/meson.build @@ -33,7 +33,6 @@ wlr_files += files( 'buffer/dmabuf.c', 'buffer/readonly_data.c', 'buffer/resource.c', - 'buffer/shm_client.c', 'wlr_compositor.c', 'wlr_content_type_v1.c', 'wlr_cursor.c', |