xserver: Branch 'master' - 4 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 8 16:24:23 UTC 2023


 hw/xwayland/xwayland-glamor-gbm.c |  136 ++++++++++++++++++++++++++------------
 1 file changed, 96 insertions(+), 40 deletions(-)

New commits:
commit 4e20d96e8dfc9d19b5730c23ae3cc8da811c346e
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Tue Mar 7 18:21:22 2023 +0100

    xwayland/glamor: Track if a xwl_pixmap uses explicit modifiers
    
    If we allocated with implicit modifiers, then we shouldn't use the
    modifier returned by gbm_bo when checking whether the modifier is
    supported or not, since it won't be if the compositor only advertises
    implicit modifiers, nor should we use the modifier when creating the
    Wayland buffer object, as it wasn't explicitly advertised.
    
    Fixes: c6f2598a4 ("xwayland: don't fall back to wl_drm with explicit modifier")
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index d545a570d..04cb5bc23 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -69,6 +69,7 @@ struct xwl_pixmap {
     EGLImage image;
     unsigned int texture;
     struct gbm_bo *bo;
+    Bool implicit_modifier;
 };
 
 static DevPrivateKeyRec xwl_gbm_private_key;
@@ -116,7 +117,8 @@ is_device_path_render_node (const char *device_path)
 
 static PixmapPtr
 xwl_glamor_gbm_create_pixmap_for_bo(ScreenPtr screen, struct gbm_bo *bo,
-                                    int depth)
+                                    int depth,
+                                    Bool implicit_modifier)
 {
     PixmapPtr pixmap;
     struct xwl_pixmap *xwl_pixmap;
@@ -188,6 +190,7 @@ xwl_glamor_gbm_create_pixmap_for_bo(ScreenPtr screen, struct gbm_bo *bo,
     xwl_glamor_egl_make_current(xwl_screen);
     xwl_pixmap->bo = bo;
     xwl_pixmap->buffer = NULL;
+    xwl_pixmap->implicit_modifier = implicit_modifier;
 
 #ifdef GBM_BO_FD_FOR_PLANE
     if (xwl_gbm->dmabuf_capable) {
@@ -286,6 +289,7 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
          hint == CREATE_PIXMAP_USAGE_SHARED ||
          (xwl_screen->rootless && hint == 0))) {
         uint32_t format = gbm_format_for_depth(depth);
+        Bool implicit = FALSE;
 
 #ifdef GBM_BO_WITH_MODIFIERS
         if (xwl_gbm->dmabuf_capable) {
@@ -301,12 +305,13 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
         }
 #endif
         if (bo == NULL) {
+            implicit = TRUE;
             bo = gbm_bo_create(xwl_gbm->gbm, width, height, format,
                                GBM_BO_USE_RENDERING);
         }
 
         if (bo) {
-            pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth);
+            pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth, implicit);
 
             if (!pixmap) {
                 gbm_bo_destroy(bo);
@@ -395,7 +400,8 @@ init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap,
 
     return TRUE;
 }
-#else
+#endif
+
 static Bool
 init_buffer_params_fallback(struct xwl_pixmap *xwl_pixmap,
                             uint64_t          *modifier,
@@ -415,7 +421,6 @@ init_buffer_params_fallback(struct xwl_pixmap *xwl_pixmap,
 
     return TRUE;
 }
-#endif
 
 static struct wl_buffer *
 xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
@@ -447,22 +452,25 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
     format = wl_drm_format_for_depth(pixmap->drawable.depth);
 
 #ifdef GBM_BO_WITH_MODIFIERS
-    if (!init_buffer_params_with_modifiers(xwl_pixmap,
-                                           &modifier,
-                                           &num_planes,
-                                           prime_fds,
-                                           strides,
-                                           offsets))
-        return NULL;
-#else
-    if (!init_buffer_params_fallback(xwl_pixmap,
-                                     &modifier,
-                                     &num_planes,
-                                     prime_fds,
-                                     strides,
-                                     offsets))
-        return NULL;
+    if (!xwl_pixmap->implicit_modifier) {
+        if (!init_buffer_params_with_modifiers(xwl_pixmap,
+                                               &modifier,
+                                               &num_planes,
+                                               prime_fds,
+                                               strides,
+                                               offsets))
+            return NULL;
+    } else
 #endif
+    {
+        if (!init_buffer_params_fallback(xwl_pixmap,
+                                         &modifier,
+                                         &num_planes,
+                                         prime_fds,
+                                         strides,
+                                         offsets))
+            return NULL;
+    }
 
     if (xwl_screen->dmabuf &&
         xwl_glamor_is_modifier_supported(xwl_screen, format, modifier)) {
@@ -626,6 +634,7 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds,
     struct gbm_bo *bo = NULL;
     PixmapPtr pixmap;
     int i;
+    Bool implicit = FALSE;
 
     if (width == 0 || height == 0 || num_fds == 0 ||
         depth < 15 || bpp != BitsPerPixel(depth) ||
@@ -659,6 +668,7 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds,
        data.format = gbm_format_for_depth(depth);
        bo = gbm_bo_import(xwl_gbm->gbm, GBM_BO_IMPORT_FD, &data,
                           GBM_BO_USE_RENDERING);
+       implicit = TRUE;
     } else {
        goto error;
     }
@@ -666,7 +676,7 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds,
     if (bo == NULL)
        goto error;
 
-    pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth);
+    pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth, implicit);
     if (pixmap == NULL) {
        gbm_bo_destroy(bo);
        goto error;
commit 9bd83c02a8e02b902303a145de15c13ee650b910
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Wed Mar 8 16:54:30 2023 +0100

    xwayland/glamor/gbm: Use helper for implicit buffer params too
    
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 2e1a4bfd5..d545a570d 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -395,6 +395,26 @@ init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap,
 
     return TRUE;
 }
+#else
+static Bool
+init_buffer_params_fallback(struct xwl_pixmap *xwl_pixmap,
+                            uint64_t          *modifier,
+                            int               *num_planes,
+                            int               *prime_fds,
+                            uint32_t          *strides,
+                            uint32_t          *offsets)
+{
+    *num_planes = 1;
+    *modifier = DRM_FORMAT_MOD_INVALID;
+    prime_fds[0] = gbm_bo_get_fd(xwl_pixmap->bo);
+    if (prime_fds[0] == -1)
+        return FALSE;
+
+    strides[0] = gbm_bo_get_stride(xwl_pixmap->bo);
+    offsets[0] = 0;
+
+    return TRUE;
+}
 #endif
 
 static struct wl_buffer *
@@ -435,13 +455,13 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
                                            offsets))
         return NULL;
 #else
-    num_planes = 1;
-    modifier = DRM_FORMAT_MOD_INVALID;
-    prime_fds[0] = gbm_bo_get_fd(xwl_pixmap->bo);
-    if (prime_fds[0] == -1)
+    if (!init_buffer_params_fallback(xwl_pixmap,
+                                     &modifier,
+                                     &num_planes,
+                                     prime_fds,
+                                     strides,
+                                     offsets))
         return NULL;
-    strides[0] = gbm_bo_get_stride(xwl_pixmap->bo);
-    offsets[0] = 0;
 #endif
 
     if (xwl_screen->dmabuf &&
commit af255b16513bab34bfc527cae139eb09c3fdbf82
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Wed Mar 8 16:53:32 2023 +0100

    xwayland/glamor/gbm: Initialize explicit buffer params in helper
    
    This is preparing for cleaning up the macro mess.
    
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 82d9e7880..2e1a4bfd5 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -347,42 +347,24 @@ static const struct wl_buffer_listener xwl_glamor_gbm_buffer_listener = {
     xwl_pixmap_buffer_release_cb,
 };
 
-static struct wl_buffer *
-xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
+#ifdef GBM_BO_WITH_MODIFIERS
+static Bool
+init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap,
+                                  uint64_t          *modifier,
+                                  int               *num_planes,
+                                  int               *prime_fds,
+                                  uint32_t          *strides,
+                                  uint32_t          *offsets)
 {
-    struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen);
-    struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap);
-    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
-    unsigned short width = pixmap->drawable.width;
-    unsigned short height = pixmap->drawable.height;
-    uint32_t format;
-    int num_planes;
-    int prime_fds[4];
-    uint32_t strides[4];
-    uint32_t offsets[4];
-    uint64_t modifier;
-    int i;
 #ifndef GBM_BO_FD_FOR_PLANE
     int32_t first_handle;
 #endif
+    int i;
 
-    if (xwl_pixmap == NULL)
-       return NULL;
-
-    if (xwl_pixmap->buffer) {
-        /* Buffer already exists. */
-        return xwl_pixmap->buffer;
-    }
-
-    if (!xwl_pixmap->bo)
-       return NULL;
-
-    format = wl_drm_format_for_depth(pixmap->drawable.depth);
+    *num_planes = gbm_bo_get_plane_count(xwl_pixmap->bo);
+    *modifier = gbm_bo_get_modifier(xwl_pixmap->bo);
 
-#ifdef GBM_BO_WITH_MODIFIERS
-    num_planes = gbm_bo_get_plane_count(xwl_pixmap->bo);
-    modifier = gbm_bo_get_modifier(xwl_pixmap->bo);
-    for (i = 0; i < num_planes; i++) {
+    for (i = 0; i < *num_planes; i++) {
 #ifdef GBM_BO_FD_FOR_PLANE
         prime_fds[i] = gbm_bo_get_fd_for_plane(xwl_pixmap->bo, i);
 #else
@@ -405,11 +387,53 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
         if (prime_fds[i] == -1) {
             while (--i >= 0)
                 close(prime_fds[i]);
-            return NULL;
+            return FALSE;
         }
         strides[i] = gbm_bo_get_stride_for_plane(xwl_pixmap->bo, i);
         offsets[i] = gbm_bo_get_offset(xwl_pixmap->bo, i);
     }
+
+    return TRUE;
+}
+#endif
+
+static struct wl_buffer *
+xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
+{
+    struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen);
+    struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap);
+    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
+    unsigned short width = pixmap->drawable.width;
+    unsigned short height = pixmap->drawable.height;
+    uint32_t format;
+    int num_planes;
+    int prime_fds[4];
+    uint32_t strides[4];
+    uint32_t offsets[4];
+    uint64_t modifier;
+    int i;
+
+    if (xwl_pixmap == NULL)
+       return NULL;
+
+    if (xwl_pixmap->buffer) {
+        /* Buffer already exists. */
+        return xwl_pixmap->buffer;
+    }
+
+    if (!xwl_pixmap->bo)
+       return NULL;
+
+    format = wl_drm_format_for_depth(pixmap->drawable.depth);
+
+#ifdef GBM_BO_WITH_MODIFIERS
+    if (!init_buffer_params_with_modifiers(xwl_pixmap,
+                                           &modifier,
+                                           &num_planes,
+                                           prime_fds,
+                                           strides,
+                                           offsets))
+        return NULL;
 #else
     num_planes = 1;
     modifier = DRM_FORMAT_MOD_INVALID;
commit 08b0ea09de120a64c498238cc15b6cc04276ca22
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Wed Mar 8 13:58:40 2023 +0100

    xwayland/glamor/gbm: Only use modifier gbm API if explicit
    
    If we're using implicit modifiers, we'll pass NULL and zero modifiers.
    Lets just use the legacy API directly instead.
    
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 8e46f30f7..82d9e7880 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -293,8 +293,10 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
             uint64_t *modifiers = NULL;
 
             xwl_glamor_get_modifiers(screen, format, &num_modifiers, &modifiers);
-            bo = gbm_bo_create_with_modifiers(xwl_gbm->gbm, width, height,
-                                              format, modifiers, num_modifiers);
+
+            if (num_modifiers > 0)
+                bo = gbm_bo_create_with_modifiers(xwl_gbm->gbm, width, height,
+                                                  format, modifiers, num_modifiers);
             free(modifiers);
         }
 #endif


More information about the xorg-commit mailing list