diff options
author | Simon Ser <contact@emersion.fr> | 2020-07-21 18:28:01 +0200 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2020-08-18 04:12:09 +0000 |
commit | d4e8c4622890b0cdcfe5f4b9c5608d15ce976901 (patch) | |
tree | 1b95bee364c3b264de56509888b0338d137da6df | |
parent | c726ceacc1a39c56d2b054ac5f35798d0c3640d7 (diff) |
xwayland: only use linux-dmabuf if format/modifier was advertised
Previously, linux-dmabuf was used unconditionally if the buffer had a
modifier. However creating a linux-dmabuf buffer with a format/modifier
which hasn't been advertised will fail.
Change xwl_glamor_gbm_get_wl_buffer_for_pixmap to use linux-dmabuf when
the format/modifier has been advertised only.
Signed-off-by: Simon Ser <contact@emersion.fr>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1035
Tested-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
(cherry picked from commit c0e13cbf5a56e1fdd1e4ce58ebdefb6d2904e4b3)
-rw-r--r-- | hw/xwayland/xwayland-glamor-gbm.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c index 4f590cd43..ebff70a00 100644 --- a/hw/xwayland/xwayland-glamor-gbm.c +++ b/hw/xwayland/xwayland-glamor-gbm.c @@ -285,6 +285,9 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr 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; + struct xwl_format *xwl_format = NULL; + Bool modifier_supported = FALSE; int prime_fd; int num_planes; uint32_t strides[4]; @@ -309,6 +312,8 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap, if (!xwl_pixmap->bo) return NULL; + format = wl_drm_format_for_depth(pixmap->drawable.depth); + prime_fd = gbm_bo_get_fd(xwl_pixmap->bo); if (prime_fd == -1) return NULL; @@ -327,7 +332,23 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap, offsets[0] = 0; #endif - if (xwl_gbm->dmabuf && modifier != DRM_FORMAT_MOD_INVALID) { + for (i = 0; i < xwl_screen->num_formats; i++) { + if (xwl_screen->formats[i].format == format) { + xwl_format = &xwl_screen->formats[i]; + break; + } + } + + if (xwl_format) { + for (i = 0; i < xwl_format->num_modifiers; i++) { + if (xwl_format->modifiers[i] == modifier) { + modifier_supported = TRUE; + break; + } + } + } + + if (xwl_gbm->dmabuf && modifier_supported) { struct zwp_linux_buffer_params_v1 *params; params = zwp_linux_dmabuf_v1_create_params(xwl_gbm->dmabuf); @@ -339,13 +360,12 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap, xwl_pixmap->buffer = zwp_linux_buffer_params_v1_create_immed(params, width, height, - wl_drm_format_for_depth(pixmap->drawable.depth), - 0); + format, 0); zwp_linux_buffer_params_v1_destroy(params); } else if (num_planes == 1) { xwl_pixmap->buffer = wl_drm_create_prime_buffer(xwl_gbm->drm, prime_fd, width, height, - wl_drm_format_for_depth(pixmap->drawable.depth), + format, 0, gbm_bo_get_stride(xwl_pixmap->bo), 0, 0, 0, 0); |