Blame SOURCES/0002-xwayland-move-formats-and-modifiers-functions-to-com.patch

4c4b8b
From ec91c17a881eaf69c4109f050e7bb9928906c52e Mon Sep 17 00:00:00 2001
4c4b8b
From: Erik Kurzinger <ekurzinger@nvidia.com>
4c4b8b
Date: Fri, 12 Feb 2021 12:09:27 -0800
4c4b8b
Subject: [PATCH xserver 02/27] xwayland: move formats and modifiers functions
4c4b8b
 to common glamor code
4c4b8b
MIME-Version: 1.0
4c4b8b
Content-Type: text/plain; charset=UTF-8
4c4b8b
Content-Transfer-Encoding: 8bit
4c4b8b
4c4b8b
This is preliminary work for hardware accelerated rendering with the
4c4b8b
NVIDIA driver.
4c4b8b
4c4b8b
This moves the modifiers and formats functions previously only available
4c4b8b
to the GBM backend to the common glamor code so that it can be used by
4c4b8b
both the GBM and EGLStream backends.
4c4b8b
4c4b8b
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
4c4b8b
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
4c4b8b
Signed-off-by: Erik Kurzinger <ekurzinger@nvidia.com>
4c4b8b
(cherry picked from commit 400d4d0fdd55192f394e1a8273dfb2423c895ec0)
4c4b8b
---
4c4b8b
 hw/xwayland/xwayland-glamor-gbm.c | 115 ++----------------------------
4c4b8b
 hw/xwayland/xwayland-glamor.c     | 111 ++++++++++++++++++++++++++++
4c4b8b
 hw/xwayland/xwayland-glamor.h     |   8 ++-
4c4b8b
 3 files changed, 123 insertions(+), 111 deletions(-)
4c4b8b
4c4b8b
diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
4c4b8b
index 73c69727e..455b755ca 100644
4c4b8b
--- a/hw/xwayland/xwayland-glamor-gbm.c
4c4b8b
+++ b/hw/xwayland/xwayland-glamor-gbm.c
4c4b8b
@@ -97,25 +97,6 @@ gbm_format_for_depth(int depth)
4c4b8b
     }
4c4b8b
 }
4c4b8b
 
4c4b8b
-static uint32_t
4c4b8b
-wl_drm_format_for_depth(int depth)
4c4b8b
-{
4c4b8b
-    switch (depth) {
4c4b8b
-    case 15:
4c4b8b
-        return WL_DRM_FORMAT_XRGB1555;
4c4b8b
-    case 16:
4c4b8b
-        return WL_DRM_FORMAT_RGB565;
4c4b8b
-    case 24:
4c4b8b
-        return WL_DRM_FORMAT_XRGB8888;
4c4b8b
-    case 30:
4c4b8b
-        return WL_DRM_FORMAT_ARGB2101010;
4c4b8b
-    default:
4c4b8b
-        ErrorF("unexpected depth: %d\n", depth);
4c4b8b
-    case 32:
4c4b8b
-        return WL_DRM_FORMAT_ARGB8888;
4c4b8b
-    }
4c4b8b
-}
4c4b8b
-
4c4b8b
 static char
4c4b8b
 is_device_path_render_node (const char *device_path)
4c4b8b
 {
4c4b8b
@@ -214,7 +195,7 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
4c4b8b
             uint32_t num_modifiers;
4c4b8b
             uint64_t *modifiers = NULL;
4c4b8b
 
4c4b8b
-            glamor_get_modifiers(screen, format, &num_modifiers, &modifiers);
4c4b8b
+            xwl_glamor_get_modifiers(screen, format, &num_modifiers, &modifiers);
4c4b8b
             bo = gbm_bo_create_with_modifiers(xwl_gbm->gbm, width, height,
4c4b8b
                                               format, modifiers, num_modifiers);
4c4b8b
             free(modifiers);
4c4b8b
@@ -277,8 +258,6 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
4c4b8b
     unsigned short width = pixmap->drawable.width;
4c4b8b
     unsigned short height = pixmap->drawable.height;
4c4b8b
     uint32_t format;
4c4b8b
-    struct xwl_format *xwl_format = NULL;
4c4b8b
-    Bool modifier_supported = FALSE;
4c4b8b
     int prime_fd;
4c4b8b
     int num_planes;
4c4b8b
     uint32_t strides[4];
4c4b8b
@@ -317,23 +296,8 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
4c4b8b
     offsets[0] = 0;
4c4b8b
 #endif
4c4b8b
 
4c4b8b
-    for (i = 0; i < xwl_screen->num_formats; i++) {
4c4b8b
-       if (xwl_screen->formats[i].format == format) {
4c4b8b
-          xwl_format = &xwl_screen->formats[i];
4c4b8b
-          break;
4c4b8b
-       }
4c4b8b
-    }
4c4b8b
-
4c4b8b
-    if (xwl_format) {
4c4b8b
-        for (i = 0; i < xwl_format->num_modifiers; i++) {
4c4b8b
-            if (xwl_format->modifiers[i] == modifier) {
4c4b8b
-                modifier_supported = TRUE;
4c4b8b
-                break;
4c4b8b
-            }
4c4b8b
-        }
4c4b8b
-    }
4c4b8b
-
4c4b8b
-    if (xwl_screen->dmabuf && modifier_supported) {
4c4b8b
+    if (xwl_screen->dmabuf &&
4c4b8b
+        xwl_glamor_is_modifier_supported(xwl_screen, format, modifier)) {
4c4b8b
         struct zwp_linux_buffer_params_v1 *params;
4c4b8b
 
4c4b8b
         params = zwp_linux_dmabuf_v1_create_params(xwl_screen->dmabuf);
4c4b8b
@@ -592,83 +556,14 @@ glamor_egl_fd_from_pixmap(ScreenPtr screen, PixmapPtr pixmap,
4c4b8b
     return -1;
4c4b8b
 }
4c4b8b
 
4c4b8b
-_X_EXPORT Bool
4c4b8b
-glamor_get_formats(ScreenPtr screen,
4c4b8b
-                   CARD32 *num_formats, CARD32 **formats)
4c4b8b
-{
4c4b8b
-    struct xwl_screen *xwl_screen = xwl_screen_get(screen);
4c4b8b
-    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
4c4b8b
-    int i;
4c4b8b
-
4c4b8b
-    /* Explicitly zero the count as the caller may ignore the return value */
4c4b8b
-    *num_formats = 0;
4c4b8b
-
4c4b8b
-    if (!xwl_gbm->dmabuf_capable || !xwl_screen->dmabuf)
4c4b8b
-        return FALSE;
4c4b8b
-
4c4b8b
-    if (xwl_screen->num_formats == 0)
4c4b8b
-       return TRUE;
4c4b8b
-
4c4b8b
-    *formats = calloc(xwl_screen->num_formats, sizeof(CARD32));
4c4b8b
-    if (*formats == NULL)
4c4b8b
-        return FALSE;
4c4b8b
-
4c4b8b
-    for (i = 0; i < xwl_screen->num_formats; i++)
4c4b8b
-       (*formats)[i] = xwl_screen->formats[i].format;
4c4b8b
-    *num_formats = xwl_screen->num_formats;
4c4b8b
-
4c4b8b
-    return TRUE;
4c4b8b
-}
4c4b8b
-
4c4b8b
-_X_EXPORT Bool
4c4b8b
-glamor_get_modifiers(ScreenPtr screen, uint32_t format,
4c4b8b
-                     uint32_t *num_modifiers, uint64_t **modifiers)
4c4b8b
-{
4c4b8b
-    struct xwl_screen *xwl_screen = xwl_screen_get(screen);
4c4b8b
-    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
4c4b8b
-    struct xwl_format *xwl_format = NULL;
4c4b8b
-    int i;
4c4b8b
-
4c4b8b
-    /* Explicitly zero the count as the caller may ignore the return value */
4c4b8b
-    *num_modifiers = 0;
4c4b8b
-
4c4b8b
-    if (!xwl_gbm->dmabuf_capable || !xwl_screen->dmabuf)
4c4b8b
-        return FALSE;
4c4b8b
-
4c4b8b
-    if (xwl_screen->num_formats == 0)
4c4b8b
-       return TRUE;
4c4b8b
-
4c4b8b
-    for (i = 0; i < xwl_screen->num_formats; i++) {
4c4b8b
-       if (xwl_screen->formats[i].format == format) {
4c4b8b
-          xwl_format = &xwl_screen->formats[i];
4c4b8b
-          break;
4c4b8b
-       }
4c4b8b
-    }
4c4b8b
-
4c4b8b
-    if (!xwl_format ||
4c4b8b
-        (xwl_format->num_modifiers == 1 &&
4c4b8b
-         xwl_format->modifiers[0] == DRM_FORMAT_MOD_INVALID))
4c4b8b
-        return FALSE;
4c4b8b
-
4c4b8b
-    *modifiers = calloc(xwl_format->num_modifiers, sizeof(uint64_t));
4c4b8b
-    if (*modifiers == NULL)
4c4b8b
-        return FALSE;
4c4b8b
-
4c4b8b
-    for (i = 0; i < xwl_format->num_modifiers; i++)
4c4b8b
-       (*modifiers)[i] = xwl_format->modifiers[i];
4c4b8b
-    *num_modifiers = xwl_format->num_modifiers;
4c4b8b
-
4c4b8b
-    return TRUE;
4c4b8b
-}
4c4b8b
-
4c4b8b
 static const dri3_screen_info_rec xwl_dri3_info = {
4c4b8b
     .version = 2,
4c4b8b
     .open = NULL,
4c4b8b
     .pixmap_from_fds = glamor_pixmap_from_fds,
4c4b8b
     .fds_from_pixmap = glamor_fds_from_pixmap,
4c4b8b
     .open_client = xwl_dri3_open_client,
4c4b8b
-    .get_formats = glamor_get_formats,
4c4b8b
-    .get_modifiers = glamor_get_modifiers,
4c4b8b
+    .get_formats = xwl_glamor_get_formats,
4c4b8b
+    .get_modifiers = xwl_glamor_get_modifiers,
4c4b8b
     .get_drawable_modifiers = glamor_get_drawable_modifiers,
4c4b8b
 };
4c4b8b
 
4c4b8b
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
4c4b8b
index cce0c911e..d8bf1bd5d 100644
4c4b8b
--- a/hw/xwayland/xwayland-glamor.c
4c4b8b
+++ b/hw/xwayland/xwayland-glamor.c
4c4b8b
@@ -79,6 +79,117 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
4c4b8b
     xwl_screen->glamor_ctx = glamor_ctx;
4c4b8b
 }
4c4b8b
 
4c4b8b
+Bool
4c4b8b
+xwl_glamor_is_modifier_supported(struct xwl_screen *xwl_screen,
4c4b8b
+                                 uint32_t format, uint64_t modifier)
4c4b8b
+{
4c4b8b
+    struct xwl_format *xwl_format = NULL;
4c4b8b
+    int i;
4c4b8b
+
4c4b8b
+    for (i = 0; i < xwl_screen->num_formats; i++) {
4c4b8b
+        if (xwl_screen->formats[i].format == format) {
4c4b8b
+            xwl_format = &xwl_screen->formats[i];
4c4b8b
+            break;
4c4b8b
+        }
4c4b8b
+    }
4c4b8b
+
4c4b8b
+    if (xwl_format) {
4c4b8b
+        for (i = 0; i < xwl_format->num_modifiers; i++) {
4c4b8b
+            if (xwl_format->modifiers[i] == modifier) {
4c4b8b
+                return TRUE;
4c4b8b
+            }
4c4b8b
+        }
4c4b8b
+    }
4c4b8b
+
4c4b8b
+    return FALSE;
4c4b8b
+}
4c4b8b
+
4c4b8b
+uint32_t
4c4b8b
+wl_drm_format_for_depth(int depth)
4c4b8b
+{
4c4b8b
+    switch (depth) {
4c4b8b
+    case 15:
4c4b8b
+        return WL_DRM_FORMAT_XRGB1555;
4c4b8b
+    case 16:
4c4b8b
+        return WL_DRM_FORMAT_RGB565;
4c4b8b
+    case 24:
4c4b8b
+        return WL_DRM_FORMAT_XRGB8888;
4c4b8b
+    case 30:
4c4b8b
+        return WL_DRM_FORMAT_ARGB2101010;
4c4b8b
+    default:
4c4b8b
+        ErrorF("unexpected depth: %d\n", depth);
4c4b8b
+    case 32:
4c4b8b
+        return WL_DRM_FORMAT_ARGB8888;
4c4b8b
+    }
4c4b8b
+}
4c4b8b
+
4c4b8b
+Bool
4c4b8b
+xwl_glamor_get_formats(ScreenPtr screen,
4c4b8b
+                       CARD32 *num_formats, CARD32 **formats)
4c4b8b
+{
4c4b8b
+    struct xwl_screen *xwl_screen = xwl_screen_get(screen);
4c4b8b
+    int i;
4c4b8b
+
4c4b8b
+    /* Explicitly zero the count as the caller may ignore the return value */
4c4b8b
+    *num_formats = 0;
4c4b8b
+
4c4b8b
+    if (!xwl_screen->dmabuf)
4c4b8b
+        return FALSE;
4c4b8b
+
4c4b8b
+    if (xwl_screen->num_formats == 0)
4c4b8b
+       return TRUE;
4c4b8b
+
4c4b8b
+    *formats = calloc(xwl_screen->num_formats, sizeof(CARD32));
4c4b8b
+    if (*formats == NULL)
4c4b8b
+        return FALSE;
4c4b8b
+
4c4b8b
+    for (i = 0; i < xwl_screen->num_formats; i++)
4c4b8b
+       (*formats)[i] = xwl_screen->formats[i].format;
4c4b8b
+    *num_formats = xwl_screen->num_formats;
4c4b8b
+
4c4b8b
+    return TRUE;
4c4b8b
+}
4c4b8b
+
4c4b8b
+Bool
4c4b8b
+xwl_glamor_get_modifiers(ScreenPtr screen, uint32_t format,
4c4b8b
+                         uint32_t *num_modifiers, uint64_t **modifiers)
4c4b8b
+{
4c4b8b
+    struct xwl_screen *xwl_screen = xwl_screen_get(screen);
4c4b8b
+    struct xwl_format *xwl_format = NULL;
4c4b8b
+    int i;
4c4b8b
+
4c4b8b
+    /* Explicitly zero the count as the caller may ignore the return value */
4c4b8b
+    *num_modifiers = 0;
4c4b8b
+
4c4b8b
+    if (!xwl_screen->dmabuf)
4c4b8b
+        return FALSE;
4c4b8b
+
4c4b8b
+    if (xwl_screen->num_formats == 0)
4c4b8b
+       return TRUE;
4c4b8b
+
4c4b8b
+    for (i = 0; i < xwl_screen->num_formats; i++) {
4c4b8b
+       if (xwl_screen->formats[i].format == format) {
4c4b8b
+          xwl_format = &xwl_screen->formats[i];
4c4b8b
+          break;
4c4b8b
+       }
4c4b8b
+    }
4c4b8b
+
4c4b8b
+    if (!xwl_format ||
4c4b8b
+        (xwl_format->num_modifiers == 1 &&
4c4b8b
+         xwl_format->modifiers[0] == DRM_FORMAT_MOD_INVALID))
4c4b8b
+        return FALSE;
4c4b8b
+
4c4b8b
+    *modifiers = calloc(xwl_format->num_modifiers, sizeof(uint64_t));
4c4b8b
+    if (*modifiers == NULL)
4c4b8b
+        return FALSE;
4c4b8b
+
4c4b8b
+    for (i = 0; i < xwl_format->num_modifiers; i++)
4c4b8b
+       (*modifiers)[i] = xwl_format->modifiers[i];
4c4b8b
+    *num_modifiers = xwl_format->num_modifiers;
4c4b8b
+
4c4b8b
+    return TRUE;
4c4b8b
+}
4c4b8b
+
4c4b8b
 static void
4c4b8b
 xwl_dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
4c4b8b
                          uint32_t format)
4c4b8b
diff --git a/hw/xwayland/xwayland-glamor.h b/hw/xwayland/xwayland-glamor.h
4c4b8b
index e017fce80..1637a0733 100644
4c4b8b
--- a/hw/xwayland/xwayland-glamor.h
4c4b8b
+++ b/hw/xwayland/xwayland-glamor.h
4c4b8b
@@ -120,7 +120,13 @@ void xwl_glamor_egl_make_current(struct xwl_screen *xwl_screen);
4c4b8b
 Bool xwl_glamor_has_present_flip(struct xwl_screen *xwl_screen);
4c4b8b
 Bool xwl_glamor_needs_buffer_flush(struct xwl_screen *xwl_screen);
4c4b8b
 Bool xwl_glamor_needs_n_buffering(struct xwl_screen *xwl_screen);
4c4b8b
-
4c4b8b
+Bool xwl_glamor_is_modifier_supported(struct xwl_screen *xwl_screen,
4c4b8b
+                                      uint32_t format, uint64_t modifier);
4c4b8b
+uint32_t wl_drm_format_for_depth(int depth);
4c4b8b
+Bool xwl_glamor_get_formats(ScreenPtr screen,
4c4b8b
+                            CARD32 *num_formats, CARD32 **formats);
4c4b8b
+Bool xwl_glamor_get_modifiers(ScreenPtr screen, uint32_t format,
4c4b8b
+                              uint32_t *num_modifiers, uint64_t **modifiers);
4c4b8b
 
4c4b8b
 #ifdef XV
4c4b8b
 /* glamor Xv Adaptor */
4c4b8b
-- 
4c4b8b
2.31.1
4c4b8b