From 85d8eac4bcf44c077bb82aaae10ae45feb9c4e72 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Mon, 7 Dec 2020 14:09:58 +0100 Subject: [PATCH] xwayland: Hold cursor buffer until released MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cursor code would destroy the buffer as soon as the cursor is unrealized on X11 side. Yet, the Wayland compositor may still be using the buffer as long as a released callback has not been received. Increase the reference counter on the pixmap to hold a reference on the pixmap when attaching it to the surface and use the new pixmap release callback mechanism to release that reference when the buffer is released. Signed-off-by: Olivier Fourdan Acked-by: Martin Peres Reviewed-by: Michel Dänzer --- hw/xwayland/xwayland-cursor.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c index 6869222b4..91cc18464 100644 --- a/hw/xwayland/xwayland-cursor.c +++ b/hw/xwayland/xwayland-cursor.c @@ -34,6 +34,7 @@ #include "xwayland-cursor.h" #include "xwayland-input.h" +#include "xwayland-pixmap.h" #include "xwayland-screen.h" #include "xwayland-shm.h" #include "xwayland-types.h" @@ -135,6 +136,13 @@ static const struct wl_callback_listener frame_listener = { frame_callback }; +static void +xwl_cursor_buffer_release_callback(void *data) +{ + /* drop the reference we took in set_cursor */ + xwl_shm_destroy_pixmap(data); +} + static void xwl_cursor_copy_bits_to_pixmap(CursorPtr cursor, PixmapPtr pixmap) { @@ -161,6 +169,12 @@ xwl_cursor_attach_pixmap(struct xwl_seat *xwl_seat, xwl_cursor->frame_cb = wl_surface_frame(xwl_cursor->surface); wl_callback_add_listener(xwl_cursor->frame_cb, &frame_listener, xwl_cursor); + /* Hold a reference on the pixmap until it's released by the compositor */ + pixmap->refcnt++; + xwl_pixmap_set_buffer_release_cb(pixmap, + xwl_cursor_buffer_release_callback, + pixmap); + wl_surface_commit(xwl_cursor->surface); }