From 22dab77d28ee8527c240ddaed63d1bd6b65e587d Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 11 Jan 2024 11:37:50 +0100 Subject: [PATCH] shm: add support for wl_shm version 2 References: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/335 --- types/wlr_shm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/types/wlr_shm.c b/types/wlr_shm.c index 4b79f99e..1f45c88a 100644 --- a/types/wlr_shm.c +++ b/types/wlr_shm.c @@ -22,7 +22,7 @@ #error "Lock-free C11 atomic pointers are required" #endif -#define SHM_VERSION 1 +#define SHM_VERSION 2 struct wlr_shm_pool { struct wl_resource *resource; // may be NULL @@ -460,8 +460,14 @@ error_fd: close(fd); } +static void shm_handle_release(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + static const struct wl_shm_interface shm_impl = { .create_pool = shm_handle_create_pool, + .release = shm_handle_release, }; static void shm_bind(struct wl_client *client, void *data, uint32_t version, @@ -491,6 +497,8 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { struct wlr_shm *wlr_shm_create(struct wl_display *display, uint32_t version, const uint32_t *formats, size_t formats_len) { + assert(version <= SHM_VERSION); + // ARGB8888 and XRGB8888 must be supported per the wl_shm spec bool has_argb8888 = false, has_xrgb8888 = false; for (size_t i = 0; i < formats_len; i++) { @@ -522,7 +530,7 @@ struct wlr_shm *wlr_shm_create(struct wl_display *display, uint32_t version, shm->formats[i] = convert_drm_format_to_wl_shm(formats[i]); } - shm->global = wl_global_create(display, &wl_shm_interface, SHM_VERSION, + shm->global = wl_global_create(display, &wl_shm_interface, version, shm, shm_bind); if (shm->global == NULL) { wlr_log(WLR_ERROR, "wl_global_create failed");