Blame SOURCES/0001-xwayland-Move-dmabuf-interface-to-common-glamor-code.patch

b6a310
From c7853c6de126f6794946c592deed205c0ddad2d9 Mon Sep 17 00:00:00 2001
b6a310
From: Olivier Fourdan <ofourdan@redhat.com>
b6a310
Date: Wed, 3 Mar 2021 09:55:12 +0100
b6a310
Subject: [PATCH xserver 01/27] xwayland: Move dmabuf interface to common
b6a310
 glamor code
b6a310
b6a310
This is preliminary work for hardware accelerated rendering with the
b6a310
NVIDIA driver.
b6a310
b6a310
The EGLStream backend can possibly also use the dmabuf interface, so
b6a310
move the relevant code from the GBM specific source to the common bits.
b6a310
b6a310
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
b6a310
(cherry picked from commit ae225417c0a0828ffb24e11eb4b968c34692e25a)
b6a310
---
b6a310
 hw/xwayland/xwayland-glamor-gbm.c | 73 ++---------------------------
b6a310
 hw/xwayland/xwayland-glamor.c     | 76 +++++++++++++++++++++++++++++--
b6a310
 hw/xwayland/xwayland-screen.h     |  1 +
b6a310
 3 files changed, 76 insertions(+), 74 deletions(-)
b6a310
b6a310
diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
b6a310
index 221bf268a..73c69727e 100644
b6a310
--- a/hw/xwayland/xwayland-glamor-gbm.c
b6a310
+++ b/hw/xwayland/xwayland-glamor-gbm.c
b6a310
@@ -56,7 +56,6 @@ struct xwl_gbm_private {
b6a310
     char *device_name;
b6a310
     struct gbm_device *gbm;
b6a310
     struct wl_drm *drm;
b6a310
-    struct zwp_linux_dmabuf_v1 *dmabuf;
b6a310
     int drm_fd;
b6a310
     int fd_render_node;
b6a310
     Bool drm_authenticated;
b6a310
@@ -334,10 +333,10 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
b6a310
         }
b6a310
     }
b6a310
 
b6a310
-    if (xwl_gbm->dmabuf && modifier_supported) {
b6a310
+    if (xwl_screen->dmabuf && modifier_supported) {
b6a310
         struct zwp_linux_buffer_params_v1 *params;
b6a310
 
b6a310
-        params = zwp_linux_dmabuf_v1_create_params(xwl_gbm->dmabuf);
b6a310
+        params = zwp_linux_dmabuf_v1_create_params(xwl_screen->dmabuf);
b6a310
         for (i = 0; i < num_planes; i++) {
b6a310
             zwp_linux_buffer_params_v1_add(params, prime_fd, i,
b6a310
                                            offsets[i], strides[i],
b6a310
@@ -604,7 +603,7 @@ glamor_get_formats(ScreenPtr screen,
b6a310
     /* Explicitly zero the count as the caller may ignore the return value */
b6a310
     *num_formats = 0;
b6a310
 
b6a310
-    if (!xwl_gbm->dmabuf_capable || !xwl_gbm->dmabuf)
b6a310
+    if (!xwl_gbm->dmabuf_capable || !xwl_screen->dmabuf)
b6a310
         return FALSE;
b6a310
 
b6a310
     if (xwl_screen->num_formats == 0)
b6a310
@@ -633,7 +632,7 @@ glamor_get_modifiers(ScreenPtr screen, uint32_t format,
b6a310
     /* Explicitly zero the count as the caller may ignore the return value */
b6a310
     *num_modifiers = 0;
b6a310
 
b6a310
-    if (!xwl_gbm->dmabuf_capable || !xwl_gbm->dmabuf)
b6a310
+    if (!xwl_gbm->dmabuf_capable || !xwl_screen->dmabuf)
b6a310
         return FALSE;
b6a310
 
b6a310
     if (xwl_screen->num_formats == 0)
b6a310
@@ -797,54 +796,6 @@ static const struct wl_drm_listener xwl_drm_listener = {
b6a310
     xwl_drm_handle_capabilities
b6a310
 };
b6a310
 
b6a310
-static void
b6a310
-xwl_dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
b6a310
-                         uint32_t format)
b6a310
-{
b6a310
-}
b6a310
-
b6a310
-static void
b6a310
-xwl_dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
b6a310
-                           uint32_t format, uint32_t modifier_hi,
b6a310
-                           uint32_t modifier_lo)
b6a310
-{
b6a310
-   struct xwl_screen *xwl_screen = data;
b6a310
-    struct xwl_format *xwl_format = NULL;
b6a310
-    int i;
b6a310
-
b6a310
-    for (i = 0; i < xwl_screen->num_formats; i++) {
b6a310
-        if (xwl_screen->formats[i].format == format) {
b6a310
-            xwl_format = &xwl_screen->formats[i];
b6a310
-            break;
b6a310
-        }
b6a310
-    }
b6a310
-
b6a310
-    if (xwl_format == NULL) {
b6a310
-       xwl_screen->num_formats++;
b6a310
-       xwl_screen->formats = realloc(xwl_screen->formats,
b6a310
-                                     xwl_screen->num_formats * sizeof(*xwl_format));
b6a310
-       if (!xwl_screen->formats)
b6a310
-          return;
b6a310
-       xwl_format = &xwl_screen->formats[xwl_screen->num_formats - 1];
b6a310
-       xwl_format->format = format;
b6a310
-       xwl_format->num_modifiers = 0;
b6a310
-       xwl_format->modifiers = NULL;
b6a310
-    }
b6a310
-
b6a310
-    xwl_format->num_modifiers++;
b6a310
-    xwl_format->modifiers = realloc(xwl_format->modifiers,
b6a310
-                                    xwl_format->num_modifiers * sizeof(uint64_t));
b6a310
-    if (!xwl_format->modifiers)
b6a310
-       return;
b6a310
-    xwl_format->modifiers[xwl_format->num_modifiers - 1]  = (uint64_t) modifier_lo;
b6a310
-    xwl_format->modifiers[xwl_format->num_modifiers - 1] |= (uint64_t) modifier_hi << 32;
b6a310
-}
b6a310
-
b6a310
-static const struct zwp_linux_dmabuf_v1_listener xwl_dmabuf_listener = {
b6a310
-    .format   = xwl_dmabuf_handle_format,
b6a310
-    .modifier = xwl_dmabuf_handle_modifier
b6a310
-};
b6a310
-
b6a310
 Bool
b6a310
 xwl_screen_set_drm_interface(struct xwl_screen *xwl_screen,
b6a310
                              uint32_t id, uint32_t version)
b6a310
@@ -862,22 +813,6 @@ xwl_screen_set_drm_interface(struct xwl_screen *xwl_screen,
b6a310
     return TRUE;
b6a310
 }
b6a310
 
b6a310
-Bool
b6a310
-xwl_screen_set_dmabuf_interface(struct xwl_screen *xwl_screen,
b6a310
-                                uint32_t id, uint32_t version)
b6a310
-{
b6a310
-    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
b6a310
-
b6a310
-    if (version < 3)
b6a310
-        return FALSE;
b6a310
-
b6a310
-    xwl_gbm->dmabuf =
b6a310
-        wl_registry_bind(xwl_screen->registry, id, &zwp_linux_dmabuf_v1_interface, 3);
b6a310
-    zwp_linux_dmabuf_v1_add_listener(xwl_gbm->dmabuf, &xwl_dmabuf_listener, xwl_screen);
b6a310
-
b6a310
-    return TRUE;
b6a310
-}
b6a310
-
b6a310
 static Bool
b6a310
 xwl_glamor_gbm_init_wl_registry(struct xwl_screen *xwl_screen,
b6a310
                                 struct wl_registry *wl_registry,
b6a310
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
b6a310
index bcd07a1a5..cce0c911e 100644
b6a310
--- a/hw/xwayland/xwayland-glamor.c
b6a310
+++ b/hw/xwayland/xwayland-glamor.c
b6a310
@@ -35,6 +35,10 @@
b6a310
 #include "glx_extinit.h"
b6a310
 #endif
b6a310
 
b6a310
+#include "linux-dmabuf-unstable-v1-client-protocol.h"
b6a310
+#include "drm-client-protocol.h"
b6a310
+#include <drm_fourcc.h>
b6a310
+
b6a310
 #include "xwayland-glamor.h"
b6a310
 #include "xwayland-glx.h"
b6a310
 #include "xwayland-screen.h"
b6a310
@@ -75,6 +79,68 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
b6a310
     xwl_screen->glamor_ctx = glamor_ctx;
b6a310
 }
b6a310
 
b6a310
+static void
b6a310
+xwl_dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
b6a310
+                         uint32_t format)
b6a310
+{
b6a310
+}
b6a310
+
b6a310
+static void
b6a310
+xwl_dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
b6a310
+                           uint32_t format, uint32_t modifier_hi,
b6a310
+                           uint32_t modifier_lo)
b6a310
+{
b6a310
+    struct xwl_screen *xwl_screen = data;
b6a310
+    struct xwl_format *xwl_format = NULL;
b6a310
+    int i;
b6a310
+
b6a310
+    for (i = 0; i < xwl_screen->num_formats; i++) {
b6a310
+        if (xwl_screen->formats[i].format == format) {
b6a310
+            xwl_format = &xwl_screen->formats[i];
b6a310
+            break;
b6a310
+        }
b6a310
+    }
b6a310
+
b6a310
+    if (xwl_format == NULL) {
b6a310
+        xwl_screen->num_formats++;
b6a310
+        xwl_screen->formats = realloc(xwl_screen->formats,
b6a310
+                                      xwl_screen->num_formats * sizeof(*xwl_format));
b6a310
+        if (!xwl_screen->formats)
b6a310
+            return;
b6a310
+        xwl_format = &xwl_screen->formats[xwl_screen->num_formats - 1];
b6a310
+        xwl_format->format = format;
b6a310
+        xwl_format->num_modifiers = 0;
b6a310
+        xwl_format->modifiers = NULL;
b6a310
+    }
b6a310
+
b6a310
+    xwl_format->num_modifiers++;
b6a310
+    xwl_format->modifiers = realloc(xwl_format->modifiers,
b6a310
+                                    xwl_format->num_modifiers * sizeof(uint64_t));
b6a310
+    if (!xwl_format->modifiers)
b6a310
+        return;
b6a310
+    xwl_format->modifiers[xwl_format->num_modifiers - 1]  = (uint64_t) modifier_lo;
b6a310
+    xwl_format->modifiers[xwl_format->num_modifiers - 1] |= (uint64_t) modifier_hi << 32;
b6a310
+}
b6a310
+
b6a310
+static const struct zwp_linux_dmabuf_v1_listener xwl_dmabuf_listener = {
b6a310
+    .format = xwl_dmabuf_handle_format,
b6a310
+    .modifier = xwl_dmabuf_handle_modifier
b6a310
+};
b6a310
+
b6a310
+Bool
b6a310
+xwl_screen_set_dmabuf_interface(struct xwl_screen *xwl_screen,
b6a310
+                                uint32_t id, uint32_t version)
b6a310
+{
b6a310
+    if (version < 3)
b6a310
+        return FALSE;
b6a310
+
b6a310
+    xwl_screen->dmabuf =
b6a310
+        wl_registry_bind(xwl_screen->registry, id, &zwp_linux_dmabuf_v1_interface, 3);
b6a310
+    zwp_linux_dmabuf_v1_add_listener(xwl_screen->dmabuf, &xwl_dmabuf_listener, xwl_screen);
b6a310
+
b6a310
+    return TRUE;
b6a310
+}
b6a310
+
b6a310
 void
b6a310
 xwl_glamor_init_wl_registry(struct xwl_screen *xwl_screen,
b6a310
                             struct wl_registry *registry,
b6a310
@@ -89,11 +155,11 @@ xwl_glamor_init_wl_registry(struct xwl_screen *xwl_screen,
b6a310
                                                  version)) {
b6a310
         /* no-op */
b6a310
     } else if (xwl_screen->eglstream_backend.is_available &&
b6a310
-             xwl_screen->eglstream_backend.init_wl_registry(xwl_screen,
b6a310
-                                                            registry,
b6a310
-                                                            id,
b6a310
-                                                            interface,
b6a310
-                                                            version)) {
b6a310
+               xwl_screen->eglstream_backend.init_wl_registry(xwl_screen,
b6a310
+                                                              registry,
b6a310
+                                                              id,
b6a310
+                                                              interface,
b6a310
+                                                              version)) {
b6a310
         /* no-op */
b6a310
     }
b6a310
 }
b6a310
diff --git a/hw/xwayland/xwayland-screen.h b/hw/xwayland/xwayland-screen.h
b6a310
index 8d0b12705..5fe4712bd 100644
b6a310
--- a/hw/xwayland/xwayland-screen.h
b6a310
+++ b/hw/xwayland/xwayland-screen.h
b6a310
@@ -83,6 +83,7 @@ struct xwl_screen {
b6a310
     struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
b6a310
     struct zwp_pointer_constraints_v1 *pointer_constraints;
b6a310
     struct zwp_xwayland_keyboard_grab_manager_v1 *wp_grab;
b6a310
+    struct zwp_linux_dmabuf_v1 *dmabuf;
b6a310
     struct zxdg_output_manager_v1 *xdg_output_manager;
b6a310
     struct wp_viewporter *viewporter;
b6a310
     uint32_t serial;
b6a310
-- 
b6a310
2.31.1
b6a310