From 287638db59d0938ceb263fcef1bf0c28eefb2033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Wed, 30 Aug 2023 18:38:03 +0200 Subject: [PATCH] xwayland/glamor/gbm: Set GBM_BO_USE_LINEAR if only LINEAR modifier is supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some drivers might not support explicit format modifiers. On these drivers `gbm_bo_create_with_modifiers()` will fail and the `gbm_bo_create()` code path will be used instead. In this case, if the LINEAR modifier is advertised (and the INVALID modifier is not) add the `GBM_BO_USE_LINEAR` flag. Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1438 Reviewed-by: Michel Dänzer Signed-off-by: José Expósito's avatarJosé Expósito --- hw/xwayland/xwayland-glamor-gbm.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c index b177b77e0..cfcd39a35 100644 --- a/hw/xwayland/xwayland-glamor-gbm.c +++ b/hw/xwayland/xwayland-glamor-gbm.c @@ -284,6 +284,8 @@ xwl_glamor_gbm_create_pixmap_internal(struct xwl_screen *xwl_screen, struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen); struct gbm_bo *bo = NULL; PixmapPtr pixmap = NULL; + uint32_t num_modifiers = 0; + uint64_t *modifiers = NULL; if (width > 0 && height > 0 && depth >= 15 && (hint == CREATE_PIXMAP_USAGE_BACKING_PIXMAP || @@ -294,8 +296,6 @@ xwl_glamor_gbm_create_pixmap_internal(struct xwl_screen *xwl_screen, #ifdef GBM_BO_WITH_MODIFIERS if (xwl_gbm->dmabuf_capable) { - uint32_t num_modifiers = 0; - uint64_t *modifiers = NULL; Bool supports_scanout = FALSE; if (drawable) { @@ -324,7 +324,6 @@ xwl_glamor_gbm_create_pixmap_internal(struct xwl_screen *xwl_screen, format, modifiers, num_modifiers); #endif } - free(modifiers); } #endif if (bo == NULL) { @@ -332,6 +331,22 @@ xwl_glamor_gbm_create_pixmap_internal(struct xwl_screen *xwl_screen, implicit = TRUE; if (implicit_scanout) usage |= GBM_BO_USE_SCANOUT; + + if (num_modifiers > 0) { + Bool has_mod_invalid = FALSE, has_mod_linear = FALSE; + int i; + + for (i = 0; i < num_modifiers; i++) { + if (modifiers[i] == DRM_FORMAT_MOD_INVALID) + has_mod_invalid = TRUE; + else if (modifiers[i] == DRM_FORMAT_MOD_LINEAR) + has_mod_linear = TRUE; + } + + if (!has_mod_invalid && has_mod_linear) + usage |= GBM_BO_USE_LINEAR; + } + bo = gbm_bo_create(xwl_gbm->gbm, width, height, format, usage); } @@ -350,6 +365,7 @@ xwl_glamor_gbm_create_pixmap_internal(struct xwl_screen *xwl_screen, if (!pixmap) pixmap = glamor_create_pixmap(xwl_screen->screen, width, height, depth, hint); + free(modifiers); return pixmap; }