From a422ae022bf95b9eeebeaa6ceafcb0f589499bfd Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Fri, 2 Feb 2024 17:52:27 +0100 Subject: [PATCH] wayland/buffer: Move scanout lifetime handling There doesn't seem to be a good reason to keep this code in `MetaWaylandSurface`. Moving it to `MetaWaylandBuffer` cleans things up and will allow us to tread buffers differently depending on their type. Part-of: --- src/wayland/meta-wayland-buffer.c | 22 +++++++++++++++++++--- src/wayland/meta-wayland-surface.c | 25 ++----------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 6837ee1ca..be7039c2e 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -897,6 +897,16 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer, #endif } +static void +scanout_destroyed (gpointer data, + GObject *where_the_object_was) +{ + MetaWaylandBuffer *buffer = data; + + meta_wayland_buffer_dec_use_count (buffer); + g_object_unref (buffer); +} + CoglScanout * meta_wayland_buffer_try_acquire_scanout (MetaWaylandBuffer *buffer, CoglOnscreen *onscreen) @@ -936,9 +946,15 @@ meta_wayland_buffer_try_acquire_scanout (MetaWaylandBuffer *buffer, return NULL; } - if (scanout) - g_signal_connect (scanout, "scanout-failed", - G_CALLBACK (on_scanout_failed), buffer); + if (!scanout) + return NULL; + + g_signal_connect (scanout, "scanout-failed", + G_CALLBACK (on_scanout_failed), buffer); + + g_object_ref (buffer); + meta_wayland_buffer_inc_use_count (buffer); + g_object_weak_ref (G_OBJECT (scanout), scanout_destroyed, buffer); return scanout; } diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index d31791bb9..213bccd64 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -2253,39 +2253,18 @@ meta_wayland_surface_get_buffer_height (MetaWaylandSurface *surface) return 0; } -static void -scanout_destroyed (gpointer data, - GObject *where_the_object_was) -{ - MetaWaylandBuffer *buffer = data; - - meta_wayland_buffer_dec_use_count (buffer); - g_object_unref (buffer); -} - CoglScanout * meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface, CoglOnscreen *onscreen) { - CoglScanout *scanout; - MetaWaylandBuffer *buffer; - if (!surface->buffer) return NULL; if (surface->buffer->use_count == 0) return NULL; - scanout = meta_wayland_buffer_try_acquire_scanout (surface->buffer, - onscreen); - if (!scanout) - return NULL; - - buffer = g_object_ref (surface->buffer); - meta_wayland_buffer_inc_use_count (buffer); - g_object_weak_ref (G_OBJECT (scanout), scanout_destroyed, buffer); - - return scanout; + return meta_wayland_buffer_try_acquire_scanout (surface->buffer, + onscreen); } MetaCrtc *