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

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