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

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