From 2478dd832214ad3cfe28a3273745a840d33ef75e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 11 Jul 2024 10:29:03 +0200 Subject: [PATCH] subsurface: Split a function I want to call the inner one from a different place in future commits. --- gdk/wayland/gdksubsurface-wayland.c | 35 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/gdk/wayland/gdksubsurface-wayland.c b/gdk/wayland/gdksubsurface-wayland.c index 03d39eeb3c..0f62bc810b 100644 --- a/gdk/wayland/gdksubsurface-wayland.c +++ b/gdk/wayland/gdksubsurface-wayland.c @@ -143,18 +143,19 @@ static const struct zwp_linux_buffer_params_v1_listener params_listener = { }; static struct wl_buffer * -get_dmabuf_wl_buffer (GdkWaylandSubsurface *self, - GdkTexture *texture) +get_dmabuf_wl_buffer (GdkWaylandSubsurface *self, + const GdkDmabuf *dmabuf, + int width, + int height, + const struct wl_buffer_listener *listener, + void * data) { GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (GDK_SUBSURFACE (self)->parent)); - const GdkDmabuf *dmabuf; struct zwp_linux_buffer_params_v1 *params; struct wl_buffer *buffer; CreateBufferData cd = { NULL, FALSE }; struct wl_event_queue *event_queue; - dmabuf = gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture)); - params = zwp_linux_dmabuf_v1_create_params (display->linux_dmabuf); for (gsize i = 0; i < dmabuf->n_planes; i++) @@ -173,8 +174,8 @@ get_dmabuf_wl_buffer (GdkWaylandSubsurface *self, zwp_linux_buffer_params_v1_add_listener (params, ¶ms_listener, &cd); zwp_linux_buffer_params_v1_create (params, - gdk_texture_get_width (texture), - gdk_texture_get_height (texture), + width, + height, dmabuf->fourcc, 0); @@ -189,12 +190,28 @@ get_dmabuf_wl_buffer (GdkWaylandSubsurface *self, if (buffer) { wl_proxy_set_queue ((struct wl_proxy *) buffer, NULL); - wl_buffer_add_listener (buffer, &dmabuf_buffer_listener, g_object_ref (texture)); + wl_buffer_add_listener (buffer, listener, data); + } + else + { + listener->release (data, NULL); } return buffer; } +static struct wl_buffer * +get_dmabuf_texture_wl_buffer (GdkWaylandSubsurface *self, + GdkTexture *texture) +{ + return get_dmabuf_wl_buffer (self, + gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture)), + gdk_texture_get_width (texture), + gdk_texture_get_height (texture), + &dmabuf_buffer_listener, + g_object_ref (texture)); +} + static struct wl_buffer * get_wl_buffer (GdkWaylandSubsurface *self, GdkTexture *texture) @@ -203,7 +220,7 @@ get_wl_buffer (GdkWaylandSubsurface *self, struct wl_buffer *buffer = NULL; if (GDK_IS_DMABUF_TEXTURE (texture)) - buffer = get_dmabuf_wl_buffer (self, texture); + buffer = get_dmabuf_texture_wl_buffer (self, texture); if (GDK_DISPLAY_DEBUG_CHECK (display, FORCE_OFFLOAD)) {