[mutter] wayland/dma-buf: Add manager struct
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] wayland/dma-buf: Add manager struct
- Date: Wed, 5 Jan 2022 17:17:47 +0000 (UTC)
commit 51308a9d78ba712a9a25438e257c430d517f35ac
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Wed Aug 4 10:12:33 2021 +0200
wayland/dma-buf: Add manager struct
It'll be used to store state related to DMA buffer Wayland support.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1959>
src/wayland/meta-wayland-dma-buf.c | 49 ++++++++++++++++++++++++++++----------
src/wayland/meta-wayland-dma-buf.h | 5 +++-
src/wayland/meta-wayland-private.h | 1 +
src/wayland/meta-wayland-types.h | 2 ++
src/wayland/meta-wayland.c | 28 +++++++++++++++++++++-
5 files changed, 71 insertions(+), 14 deletions(-)
---
diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c
index 8108d614f2..599bd973b4 100644
--- a/src/wayland/meta-wayland-dma-buf.c
+++ b/src/wayland/meta-wayland-dma-buf.c
@@ -66,6 +66,11 @@
#define META_WAYLAND_DMA_BUF_MAX_FDS 4
+struct _MetaWaylandDmaBufManager
+{
+ MetaWaylandCompositor *compositor;
+};
+
struct _MetaWaylandDmaBufBuffer
{
GObject parent;
@@ -713,17 +718,17 @@ send_modifiers (struct wl_resource *resource,
static void
dma_buf_bind (struct wl_client *client,
- void *data,
+ void *user_data,
uint32_t version,
uint32_t id)
{
- MetaWaylandCompositor *compositor = data;
+ MetaWaylandDmaBufManager *dma_buf_manager = user_data;
struct wl_resource *resource;
resource = wl_resource_create (client, &zwp_linux_dmabuf_v1_interface,
version, id);
wl_resource_set_implementation (resource, &dma_buf_implementation,
- compositor, NULL);
+ dma_buf_manager, NULL);
send_modifiers (resource, DRM_FORMAT_ARGB8888);
send_modifiers (resource, DRM_FORMAT_ABGR8888);
send_modifiers (resource, DRM_FORMAT_XRGB8888);
@@ -740,38 +745,58 @@ dma_buf_bind (struct wl_client *client,
}
/**
- * meta_wayland_dma_buf_init:
+ * meta_wayland_dma_buf_manager_new:
* @compositor: The #MetaWaylandCompositor
*
* Creates the global Wayland object that exposes the linux-dmabuf protocol.
*
- * Returns: Whether the initialization was successful. If this is %FALSE,
- * clients won't be able to use the linux-dmabuf protocol to pass buffers.
+ * Returns: (transfer full): The MetaWaylandDmaBufManager instance.
*/
-gboolean
-meta_wayland_dma_buf_init (MetaWaylandCompositor *compositor)
+MetaWaylandDmaBufManager *
+meta_wayland_dma_buf_manager_new (MetaWaylandCompositor *compositor,
+ GError **error)
{
MetaBackend *backend = meta_get_backend ();
MetaEgl *egl = meta_backend_get_egl (backend);
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
EGLDisplay egl_display = cogl_egl_context_get_egl_display (cogl_context);
+ g_autoptr (GError) local_error = NULL;
+ g_autofree MetaWaylandDmaBufManager *dma_buf_manager = NULL;
g_assert (backend && egl && clutter_backend && cogl_context && egl_display);
if (!meta_egl_has_extensions (egl, egl_display, NULL,
"EGL_EXT_image_dma_buf_import_modifiers",
NULL))
- return FALSE;
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "Missing 'EGL_EXT_image_dma_buf_import_modifiers'");
+ return NULL;
+ }
+
+ dma_buf_manager = g_new0 (MetaWaylandDmaBufManager, 1);
if (!wl_global_create (compositor->wayland_display,
&zwp_linux_dmabuf_v1_interface,
META_ZWP_LINUX_DMABUF_V1_VERSION,
- compositor,
+ dma_buf_manager,
dma_buf_bind))
- return FALSE;
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Failed to create zwp_linux_dmabuf_v1 global");
+ return NULL;
+ }
- return TRUE;
+ dma_buf_manager->compositor = compositor;
+
+ return g_steal_pointer (&dma_buf_manager);
+}
+
+void
+meta_wayland_dma_buf_manager_free (MetaWaylandDmaBufManager *dma_buf_manager)
+{
+ g_free (dma_buf_manager);
}
static void
diff --git a/src/wayland/meta-wayland-dma-buf.h b/src/wayland/meta-wayland-dma-buf.h
index cdc65aeb5b..72fd0b16a0 100644
--- a/src/wayland/meta-wayland-dma-buf.h
+++ b/src/wayland/meta-wayland-dma-buf.h
@@ -39,7 +39,10 @@ G_DECLARE_FINAL_TYPE (MetaWaylandDmaBufBuffer, meta_wayland_dma_buf_buffer,
typedef struct _MetaWaylandDmaBufBuffer MetaWaylandDmaBufBuffer;
-gboolean meta_wayland_dma_buf_init (MetaWaylandCompositor *compositor);
+MetaWaylandDmaBufManager * meta_wayland_dma_buf_manager_new (MetaWaylandCompositor *compositor,
+ GError **error);
+
+void meta_wayland_dma_buf_manager_free (MetaWaylandDmaBufManager *dma_buf_manager);
gboolean
meta_wayland_dma_buf_buffer_attach (MetaWaylandBuffer *buffer,
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 35fad86922..9836e11f12 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -100,6 +100,7 @@ struct _MetaWaylandCompositor
GHashTable *scheduled_surface_associations;
MetaWaylandPresentationTime presentation_time;
+ MetaWaylandDmaBufManager *dma_buf_manager;
};
#define META_TYPE_WAYLAND_COMPOSITOR (meta_wayland_compositor_get_type ())
diff --git a/src/wayland/meta-wayland-types.h b/src/wayland/meta-wayland-types.h
index aeb6f61786..b2c8615a55 100644
--- a/src/wayland/meta-wayland-types.h
+++ b/src/wayland/meta-wayland-types.h
@@ -63,4 +63,6 @@ typedef struct _MetaWaylandPointerClient MetaWaylandPointerClient;
typedef struct _MetaWaylandActivation MetaWaylandActivation;
+typedef struct _MetaWaylandDmaBufManager MetaWaylandDmaBufManager;
+
#endif
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 4f777792d1..462364949b 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -437,6 +437,9 @@ meta_wayland_compositor_finalize (GObject *object)
{
MetaWaylandCompositor *compositor = META_WAYLAND_COMPOSITOR (object);
+ g_clear_pointer (&compositor->dma_buf_manager,
+ meta_wayland_dma_buf_manager_free);
+
g_clear_pointer (&compositor->seat, meta_wayland_seat_free);
g_clear_pointer (&compositor->display_name, g_free);
@@ -526,6 +529,29 @@ meta_wayland_init_egl (MetaWaylandCompositor *compositor)
g_warning ("Failed to bind Wayland display: %s", error->message);
}
+static void
+init_dma_buf_support (MetaWaylandCompositor *compositor)
+{
+ g_autoptr (GError) error = NULL;
+
+ compositor->dma_buf_manager = meta_wayland_dma_buf_manager_new (compositor,
+ &error);
+ if (!compositor->dma_buf_manager)
+ {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
+ {
+ meta_topic (META_DEBUG_WAYLAND,
+ "Wayland DMA buffer protocol support not enabled: %s",
+ error->message);
+ }
+ else
+ {
+ g_warning ("Wayland DMA buffer protocol support not enabled: %s",
+ error->message);
+ }
+ }
+}
+
MetaWaylandCompositor *
meta_wayland_compositor_new (MetaContext *context)
{
@@ -577,7 +603,7 @@ meta_wayland_compositor_new (MetaContext *context)
meta_wayland_relative_pointer_init (compositor);
meta_wayland_pointer_constraints_init (compositor);
meta_wayland_xdg_foreign_init (compositor);
- meta_wayland_dma_buf_init (compositor);
+ init_dma_buf_support (compositor);
meta_wayland_keyboard_shortcuts_inhibit_init (compositor);
meta_wayland_surface_inhibit_shortcuts_dialog_init ();
meta_wayland_text_input_init (compositor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]