[Mesa-dev] [PATCH 09/18] egl/wayland: Use visual map for DRIImage<->FourCC map

Daniel Stone daniels at collabora.com
Thu Feb 8 13:55:33 UTC 2018


When trying to translate between DRIImage format enums and FourCC codes,
use our visual map rather than an open-coded subset.

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

diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index b56596666b1..05a020ec215 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -432,10 +432,15 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
    struct dri2_egl_display *dri2_dpy =
       dri2_egl_display(dri2_surf->base.Resource.Display);
    int use_flags;
+   int visual_idx;
    unsigned int dri_image_format;
    uint64_t *modifiers;
    int num_modifiers;
 
+   visual_idx = dri2_wl_visual_idx_from_fourcc(dri2_surf->format);
+   assert(visual_idx != -1);
+   dri_image_format = dri2_wl_visuals[visual_idx].dri_image_format;
+
    /* currently supports five WL DRM formats,
     * WL_DRM_FORMAT_ARGB2101010, WL_DRM_FORMAT_XRGB2101010,
     * WL_DRM_FORMAT_ARGB8888, WL_DRM_FORMAT_XRGB8888,
@@ -443,27 +448,22 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
     */
    switch (dri2_surf->format) {
    case WL_DRM_FORMAT_ARGB2101010:
-      dri_image_format = __DRI_IMAGE_FORMAT_ARGB2101010;
       modifiers = u_vector_tail(&dri2_dpy->wl_modifiers.argb2101010);
       num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers.argb2101010);
       break;
    case WL_DRM_FORMAT_XRGB2101010:
-      dri_image_format = __DRI_IMAGE_FORMAT_XRGB2101010;
       modifiers = u_vector_tail(&dri2_dpy->wl_modifiers.xrgb2101010);
       num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers.xrgb2101010);
       break;
    case WL_DRM_FORMAT_ARGB8888:
-      dri_image_format = __DRI_IMAGE_FORMAT_ARGB8888;
       modifiers = u_vector_tail(&dri2_dpy->wl_modifiers.argb8888);
       num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers.argb8888);
       break;
    case WL_DRM_FORMAT_XRGB8888:
-      dri_image_format = __DRI_IMAGE_FORMAT_XRGB8888;
       modifiers = u_vector_tail(&dri2_dpy->wl_modifiers.xrgb8888);
       num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers.xrgb8888);
       break;
    case WL_DRM_FORMAT_RGB565:
-      dri_image_format = __DRI_IMAGE_FORMAT_RGB565;
       modifiers = u_vector_tail(&dri2_dpy->wl_modifiers.rgb565);
       num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers.rgb565);
       break;
@@ -786,6 +786,7 @@ get_fourcc(struct dri2_egl_display *dri2_dpy,
 {
    EGLBoolean query;
    int dri_format;
+   int visual_idx;
 
    query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FOURCC,
                                        fourcc);
@@ -797,16 +798,12 @@ get_fourcc(struct dri2_egl_display *dri2_dpy,
    if (!query)
       return false;
 
-   switch (dri_format) {
-   case __DRI_IMAGE_FORMAT_ARGB8888:
-      *fourcc = __DRI_IMAGE_FOURCC_ARGB8888;
-      return true;
-   case __DRI_IMAGE_FORMAT_XRGB8888:
-      *fourcc = __DRI_IMAGE_FOURCC_XRGB8888;
-      return true;
-   default:
+   visual_idx = dri2_wl_visual_idx_from_dri_image_format(dri_format);
+   if (visual_idx == -1)
       return false;
-   }
+
+   *fourcc = dri2_wl_visuals[visual_idx].wl_drm_format;
+   return true;
 }
 
 static struct wl_buffer *
-- 
2.14.3



More information about the mesa-dev mailing list