Mesa (staging/20.0): egl/wayland: Fix zwp_linux_dmabuf usage

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 6 23:04:00 UTC 2020


Module: Mesa
Branch: staging/20.0
Commit: bc1b6f4324f037ced4eedb0b990a1a57f1281760
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bc1b6f4324f037ced4eedb0b990a1a57f1281760

Author: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
Date:   Tue Mar 24 14:19:51 2020 +1100

egl/wayland: Fix zwp_linux_dmabuf usage

There's no guarantee that the formats advertised by wl_drm and the formats
advertised by zwp_linux_dmabuf_v1 are the same.

get_back_bo() handles this by falling back from createImageWithModifiers() to
createImage() when there's a wl_drm format but no corresponding linux_dmabuf
format, but create_wl_buffer() unconditionally tries to create a linux_dmabuf
buffer unless DRIimage has DRM_FORMAT_MOD_INVALID.

Fix this by always checking if the DRIimage modifier has been advertised
by zwp_linux_dmabuf_v1, and falling back to wl_drm if not.

If DRM_FORMAT_MOD_INVALID has been advertised then we trust the client
has allocated something appropriate and treat any modifier as matching.

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2220
Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
Reviewed-by: Daniel Stone <daniels at collabora.com>
Reviewed-by: Simon Ser <contact at emersion.fr>
(cherry picked from commit 98675d34c115e3a8db9b6b74e8eca01af5fff101)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4869>

---

 src/egl/drivers/dri2/platform_wayland.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 324ac2357da..7b7646e6e7f 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -925,20 +925,28 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy,
    }
 
    bool supported_modifier = false;
-   if (modifier != DRM_FORMAT_MOD_INVALID) {
-      supported_modifier = true;
-   } else {
-      int visual_idx = dri2_wl_visual_idx_from_fourcc(fourcc);
-      assert(visual_idx != -1);
-
-      uint64_t *mod;
-      u_vector_foreach(mod, &dri2_dpy->wl_modifiers[visual_idx]) {
-         if (*mod == DRM_FORMAT_MOD_INVALID) {
-            supported_modifier = true;
-            break;
-         }
+   bool mod_invalid_supported = false;
+   int visual_idx = dri2_wl_visual_idx_from_fourcc(fourcc);
+   assert(visual_idx != -1);
+
+   uint64_t *mod;
+   u_vector_foreach(mod, &dri2_dpy->wl_modifiers[visual_idx]) {
+      if (*mod == DRM_FORMAT_MOD_INVALID) {
+         mod_invalid_supported = true;
+      }
+      if (*mod == modifier) {
+         supported_modifier = true;
+         break;
       }
    }
+   if (!supported_modifier && mod_invalid_supported) {
+      /* If the server has advertised DRM_FORMAT_MOD_INVALID then we trust
+       * that the client has allocated the buffer with the right implicit
+       * modifier for the format, even though it's allocated a buffer the
+       * server hasn't explicitly claimed to support. */
+      modifier = DRM_FORMAT_MOD_INVALID;
+      supported_modifier = true;
+   }
 
    if (dri2_dpy->wl_dmabuf && supported_modifier) {
       struct zwp_linux_buffer_params_v1 *params;



More information about the mesa-commit mailing list