libs: display: wayland: add basic dmabuf protocol support
authorMichael Olbrich <m.olbrich@pengutronix.de>
Wed, 22 Jul 2020 07:36:18 +0000 (09:36 +0200)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 27 Jul 2020 15:02:19 +0000 (15:02 +0000)
This is just the basic infrastructure. Hook up the interface and collect
all supported formats.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/346>

gst-libs/gst/vaapi/gstvaapidisplay_wayland.c
gst-libs/gst/vaapi/gstvaapidisplay_wayland_priv.h
gst-libs/gst/vaapi/meson.build

index 8803c29..7dfe857 100644 (file)
@@ -106,6 +106,42 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = {
 };
 
 static void
+dmabuf_format (void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
+    uint32_t format)
+{
+}
+
+static void
+dmabuf_modifier (void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
+    uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo)
+{
+  GstVaapiDisplayWaylandPrivate *const priv = data;
+  GstDRMFormat drm_format = {
+    .format = format,
+    .modifier = (guint64) modifier_hi << 32 | modifier_lo
+  };
+
+  if (gst_vaapi_video_format_from_drm_format (format) ==
+      GST_VIDEO_FORMAT_UNKNOWN) {
+    GST_LOG ("ignoring unknown format 0x%x with modifier 0x%" G_GINT64_MODIFIER
+        "x", format, drm_format.modifier);
+    return;
+  }
+
+  GST_LOG ("got format 0x%x (%s) with modifier 0x%" G_GINT64_MODIFIER "x",
+      format, gst_video_format_to_string (gst_vaapi_video_format_from_drm_format
+          (format)), drm_format.modifier);
+
+  g_array_append_val (priv->dmabuf_formats, drm_format);
+}
+
+static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
+  dmabuf_format,
+  dmabuf_modifier,
+};
+
+
+static void
 registry_handle_global (void *data,
     struct wl_registry *registry,
     uint32_t id, const char *interface, uint32_t version)
@@ -126,6 +162,10 @@ registry_handle_global (void *data,
       priv->output = wl_registry_bind (registry, id, &wl_output_interface, 1);
       wl_output_add_listener (priv->output, &output_listener, priv);
     }
+  } else if (strcmp (interface, "zwp_linux_dmabuf_v1") == 0) {
+    priv->dmabuf =
+        wl_registry_bind (registry, id, &zwp_linux_dmabuf_v1_interface, 3);
+    zwp_linux_dmabuf_v1_add_listener (priv->dmabuf, &dmabuf_listener, priv);
   }
 }
 
@@ -217,6 +257,8 @@ gst_vaapi_display_wayland_close_display (GstVaapiDisplay * display)
   g_clear_pointer (&priv->compositor, wl_compositor_destroy);
   g_clear_pointer (&priv->registry, wl_registry_destroy);
 
+  g_array_unref (priv->dmabuf_formats);
+
   if (priv->wl_display) {
     if (!priv->use_foreign_display)
       wl_display_disconnect (priv->wl_display);
@@ -294,6 +336,7 @@ gst_vaapi_display_wayland_init (GstVaapiDisplayWayland * display)
 
   display->priv = priv;
   priv->event_fd = -1;
+  priv->dmabuf_formats = g_array_new (FALSE, FALSE, sizeof (GstDRMFormat));
 }
 
 static void
index b09adfb..6822d82 100644 (file)
@@ -25,6 +25,7 @@
 #define GST_VAAPI_DISPLAY_WAYLAND_PRIV_H
 
 #include "xdg-shell-client-protocol.h"
+#include "linux-dmabuf-unstable-v1-client-protocol.h"
 
 #include <gst/vaapi/gstvaapidisplay_wayland.h>
 #include "gstvaapidisplay_priv.h"
@@ -57,6 +58,13 @@ typedef struct _GstVaapiDisplayWaylandClass     GstVaapiDisplayWaylandClass;
 #define GST_VAAPI_DISPLAY_WL_DISPLAY(display) \
     GST_VAAPI_DISPLAY_WAYLAND_GET_PRIVATE(display)->wl_display
 
+typedef struct _GstDRMFormat GstDRMFormat;
+
+struct _GstDRMFormat {
+  guint format;
+  guint64 modifier;
+};
+
 struct _GstVaapiDisplayWaylandPrivate
 {
   gchar *display_name;
@@ -65,7 +73,9 @@ struct _GstVaapiDisplayWaylandPrivate
   struct wl_shell *wl_shell;
   struct xdg_wm_base *xdg_wm_base;
   struct wl_output *output;
+  struct zwp_linux_dmabuf_v1 *dmabuf;
   struct wl_registry *registry;
+  GArray *dmabuf_formats;
   guint width;
   guint height;
   guint phys_width;
index 246ac30..bcf261f 100644 (file)
@@ -174,12 +174,23 @@ if USE_WAYLAND
       command: [ wayland_scanner_bin, 'private-code', '@INPUT@', '@OUTPUT@' ],
       input: xdg_shell_xml_spec,
       output: 'xdg-shell-client-protocol.c')
+  dmabuf_xml_spec = join_paths(wayland_protocols_basedir, 'unstable', 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml')
+  dmabuf_header = custom_target('vaapi-dmabuf-client-header',
+      command: [ wayland_scanner_bin, 'client-header', '@INPUT@', '@OUTPUT@' ],
+      input: dmabuf_xml_spec,
+      output: 'linux-dmabuf-unstable-v1-client-protocol.h')
+  dmabuf_code = custom_target('vaapi-dmabuf-client-code',
+      command: [ wayland_scanner_bin, 'private-code', '@INPUT@', '@OUTPUT@' ],
+      input: dmabuf_xml_spec,
+      output: 'linux-dmabuf-unstable-v1-client-protocol.c')
 
   gstlibvaapi_sources += [
       'gstvaapidisplay_wayland.c',
       'gstvaapiwindow_wayland.c',
       xdg_shell_header,
       xdg_shell_code,
+      dmabuf_header,
+      dmabuf_code,
   ]
   gstlibvaapi_headers += [
       'gstvaapidisplay_wayland.h',