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

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