[Mesa-dev] [PATCH 07/18] egl/wayland: Use visual map for buffer_from_image

Daniel Stone daniels at collabora.com
Thu Feb 8 14:05:57 UTC 2018


When creating a wl_buffer on an upstream Wayland display from an
existing EGLImage, use the dri2_wl_visual map rather than another
hardcoded list of formats.

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 src/egl/drivers/dri2/platform_wayland.c | 38 ++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 1eac2158ac2..0839f5e85a7 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -130,6 +130,17 @@ dri2_wl_visual_idx_from_config(struct dri2_egl_display *dri2_dpy,
    return -1;
 }
 
+static int
+dri2_wl_visual_idx_from_dri_image_format(uint32_t dri_image_format)
+{
+   for (int i = 0; i < ARRAY_SIZE(dri2_wl_visuals); i++) {
+      if (dri2_wl_visuals[i].dri_image_format == dri_image_format)
+         return i;
+   }
+
+   return -1;
+}
+
 static int
 roundtrip(struct dri2_egl_display *dri2_dpy)
 {
@@ -1039,29 +1050,16 @@ dri2_wl_create_wayland_buffer_from_image(_EGLDriver *drv,
    struct dri2_egl_image *dri2_img = dri2_egl_image(img);
    __DRIimage *image = dri2_img->dri_image;
    struct wl_buffer *buffer;
-   int format;
+   int format, visual_idx;
 
+   /* Check the upstream display supports this buffer's format. */
    dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &format);
-   switch (format) {
-   case __DRI_IMAGE_FORMAT_ARGB2101010:
-      if (!(dri2_dpy->formats & HAS_ARGB2101010))
-         goto bad_format;
-      break;
-   case __DRI_IMAGE_FORMAT_XRGB2101010:
-      if (!(dri2_dpy->formats & HAS_XRGB2101010))
-         goto bad_format;
-      break;
-   case __DRI_IMAGE_FORMAT_ARGB8888:
-      if (!(dri2_dpy->formats & HAS_ARGB8888))
-         goto bad_format;
-      break;
-   case __DRI_IMAGE_FORMAT_XRGB8888:
-      if (!(dri2_dpy->formats & HAS_XRGB8888))
-         goto bad_format;
-      break;
-   default:
+   visual_idx = dri2_wl_visual_idx_from_dri_image_format(format);
+   if (visual_idx == -1)
+      goto bad_format;
+
+   if (!(dri2_dpy->formats & dri2_wl_visuals[visual_idx].has_format))
       goto bad_format;
-   }
 
    buffer = create_wl_buffer(dri2_dpy, NULL, image);
 
-- 
2.14.3



More information about the mesa-dev mailing list