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

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