From 03c3b642bd03020c0355372a05ed4d46be2fce6b Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sat, 26 Aug 2023 11:48:42 +0200 Subject: [PATCH 1/3] cogl: Move CoglScanout declarations from onscreen to types While closely related, types appears to be the more appropriate place these days. Part-of: --- cogl/cogl/cogl-onscreen.h | 11 ----------- cogl/cogl/cogl-types.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cogl/cogl/cogl-onscreen.h b/cogl/cogl/cogl-onscreen.h index f22a8979e46..33928d31ef7 100644 --- a/cogl/cogl/cogl-onscreen.h +++ b/cogl/cogl/cogl-onscreen.h @@ -45,8 +45,6 @@ G_BEGIN_DECLS -typedef struct _CoglScanout CoglScanout; - #define COGL_TYPE_ONSCREEN (cogl_onscreen_get_type ()) COGL_EXPORT G_DECLARE_DERIVABLE_TYPE (CoglOnscreen, cogl_onscreen, @@ -85,15 +83,6 @@ struct _CoglOnscreenClass int (* get_buffer_age) (CoglOnscreen *onscreen); }; -#define COGL_SCANOUT_ERROR (cogl_scanout_error_quark ()) -COGL_EXPORT GQuark -cogl_scanout_error_quark (void); - -typedef enum _CoglScanoutError -{ - COGL_SCANOUT_ERROR_INHIBITED, -} CoglScanoutError; - /** * cogl_onscreen_show: * @onscreen: The onscreen framebuffer to make visible diff --git a/cogl/cogl/cogl-types.h b/cogl/cogl/cogl-types.h index e46c948807c..30749da1c8b 100644 --- a/cogl/cogl/cogl-types.h +++ b/cogl/cogl/cogl-types.h @@ -425,4 +425,20 @@ typedef enum COGL_STEREO_RIGHT } CoglStereoMode; +typedef struct _CoglScanout CoglScanout; + +#define COGL_SCANOUT_ERROR (cogl_scanout_error_quark ()) + +/** + * CoglScanoutError: + * @COGL_SCANOUT_ERROR_INHIBITED: Scanout inhibited + */ +typedef enum _CoglScanoutError +{ + COGL_SCANOUT_ERROR_INHIBITED, +} CoglScanoutError; + +COGL_EXPORT GQuark +cogl_scanout_error_quark (void); + G_END_DECLS -- GitLab From 03a98343d23e3499785318482545f519b48546aa Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Tue, 19 Dec 2023 22:48:39 +0100 Subject: [PATCH 2/3] wayland/dma-buf: Take MetaWaylandBuffer in try_acquire_scanout And do some minor variable order cleanup while on it. Part-of: --- src/wayland/meta-wayland-buffer.c | 8 +------- src/wayland/meta-wayland-dma-buf.c | 29 +++++++++++++++++++---------- src/wayland/meta-wayland-dma-buf.h | 4 ++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 40386ad79ed..6837ee1cae4 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -928,13 +928,7 @@ meta_wayland_buffer_try_acquire_scanout (MetaWaylandBuffer *buffer, break; case META_WAYLAND_BUFFER_TYPE_DMA_BUF: { - MetaWaylandDmaBufBuffer *dma_buf; - - dma_buf = meta_wayland_dma_buf_from_buffer (buffer); - if (!dma_buf) - return NULL; - - scanout = meta_wayland_dma_buf_try_acquire_scanout (dma_buf, onscreen); + scanout = meta_wayland_dma_buf_try_acquire_scanout (buffer, onscreen); break; } case META_WAYLAND_BUFFER_TYPE_UNKNOWN: diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c index f713c5968f7..ef8c540be00 100644 --- a/src/wayland/meta-wayland-dma-buf.c +++ b/src/wayland/meta-wayland-dma-buf.c @@ -605,23 +605,32 @@ import_scanout_gbm_bo (MetaWaylandDmaBufBuffer *dma_buf, #endif CoglScanout * -meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf, - CoglOnscreen *onscreen) +meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandBuffer *buffer, + CoglOnscreen *onscreen) { #ifdef HAVE_NATIVE_BACKEND - MetaContext *context = - meta_wayland_compositor_get_context (dma_buf->manager->compositor); - MetaBackend *backend = meta_context_get_backend (context); - MetaRenderer *renderer = meta_backend_get_renderer (backend); - MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer); - int n_planes; + MetaWaylandDmaBufBuffer *dma_buf; + MetaContext *context; + MetaBackend *backend; + MetaRenderer *renderer; + MetaRendererNative *renderer_native; MetaDeviceFile *device_file; MetaGpuKms *gpu_kms; struct gbm_bo *gbm_bo; - gboolean use_modifier; + g_autoptr (MetaDrmBufferGbm) fb = NULL; g_autoptr (GError) error = NULL; MetaDrmBufferFlags flags; - g_autoptr (MetaDrmBufferGbm) fb = NULL; + gboolean use_modifier; + int n_planes; + + dma_buf = meta_wayland_dma_buf_from_buffer (buffer); + if (!dma_buf) + return NULL; + + context = meta_wayland_compositor_get_context (dma_buf->manager->compositor); + backend = meta_context_get_backend (context); + renderer = meta_backend_get_renderer (backend); + renderer_native = META_RENDERER_NATIVE (renderer); for (n_planes = 0; n_planes < META_WAYLAND_DMA_BUF_MAX_FDS; n_planes++) { diff --git a/src/wayland/meta-wayland-dma-buf.h b/src/wayland/meta-wayland-dma-buf.h index 1c03acb3283..026e4837de1 100644 --- a/src/wayland/meta-wayland-dma-buf.h +++ b/src/wayland/meta-wayland-dma-buf.h @@ -64,5 +64,5 @@ meta_wayland_dma_buf_create_source (MetaWaylandBuffer *buffer, gpointer user_data); CoglScanout * -meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf, - CoglOnscreen *onscreen); +meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandBuffer *buffer, + CoglOnscreen *onscreen); -- GitLab From a422ae022bf95b9eeebeaa6ceafcb0f589499bfd Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Fri, 2 Feb 2024 17:52:27 +0100 Subject: [PATCH 3/3] 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 6837ee1cae4..be7039c2e21 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 d31791bb970..213bccd64c3 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 * -- GitLab