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

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