Module: Mesa
Branch: master
Commit: 4732094cff302a10c167e0cb23851c19fccddbe0
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4732094cff302a10c167e0cb23851c19fccddbe0

Author: Daniel Stone <dani...@collabora.com>
Date:   Tue Feb  6 10:29:13 2018 +0000

egl/wayland: Use an array for modifiers

Each Wayland EGLDisplay currently contains a struct with one vector of
modifiers per format, hardcoded in the header. To allow easier support
for more formats, turn this into an array of u_vectors which is opaque
outside of platform_wayland.c.

Signed-off-by: Daniel Stone <dani...@collabora.com>
Reviewed-by: Emil Velikov <emil.veli...@collabora.com>
Tested-by: Ilia Mirkin <imir...@alum.mit.edu>

---

 src/egl/drivers/dri2/egl_dri2.h         |  8 +---
 src/egl/drivers/dri2/platform_wayland.c | 84 ++++++++-------------------------
 2 files changed, 20 insertions(+), 72 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index c49156fbb6..0f4e7a8d1e 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -212,13 +212,7 @@ struct dri2_egl_display
    struct wl_shm            *wl_shm;
    struct wl_event_queue    *wl_queue;
    struct zwp_linux_dmabuf_v1 *wl_dmabuf;
-   struct {
-      struct u_vector        xrgb2101010;
-      struct u_vector        argb2101010;
-      struct u_vector        xrgb8888;
-      struct u_vector        argb8888;
-      struct u_vector        rgb565;
-   } wl_modifiers;
+   struct u_vector          *wl_modifiers;
    bool                      authenticated;
    int                       formats;
    uint32_t                  capabilities;
diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index d214a8515d..f91baded87 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -436,37 +436,8 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
    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,
-    * and WL_DRM_FORMAT_RGB565
-    */
-   switch (dri2_surf->format) {
-   case WL_DRM_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:
-      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:
-      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:
-      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:
-      modifiers = u_vector_tail(&dri2_dpy->wl_modifiers.rgb565);
-      num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers.rgb565);
-      break;
-   default:
-      /* format is not supported */
-      return -1;
-   }
+   modifiers = u_vector_tail(&dri2_dpy->wl_modifiers[visual_idx]);
+   num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers[visual_idx]);
 
    /* There might be a buffer release already queued that wasn't processed */
    wl_display_dispatch_queue_pending(dri2_dpy->wl_dpy, dri2_surf->wl_queue);
@@ -1187,36 +1158,18 @@ dmabuf_handle_modifier(void *data, struct 
zwp_linux_dmabuf_v1 *dmabuf,
 {
    struct dri2_egl_display *dri2_dpy = data;
    int visual_idx = dri2_wl_visual_idx_from_fourcc(format);
-   uint64_t *mod = NULL;
+   uint64_t *mod;
 
-   if (modifier_hi == (DRM_FORMAT_MOD_INVALID >> 32) &&
-       modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff))
+   if (visual_idx == -1)
       return;
 
-   switch (format) {
-   case WL_DRM_FORMAT_ARGB2101010:
-      mod = u_vector_add(&dri2_dpy->wl_modifiers.argb2101010);
-      break;
-   case WL_DRM_FORMAT_XRGB2101010:
-      mod = u_vector_add(&dri2_dpy->wl_modifiers.xrgb2101010);
-      break;
-   case WL_DRM_FORMAT_ARGB8888:
-      mod = u_vector_add(&dri2_dpy->wl_modifiers.argb8888);
-      break;
-   case WL_DRM_FORMAT_XRGB8888:
-      mod = u_vector_add(&dri2_dpy->wl_modifiers.xrgb8888);
-      break;
-   case WL_DRM_FORMAT_RGB565:
-      mod = u_vector_add(&dri2_dpy->wl_modifiers.rgb565);
-      break;
-   default:
-      break;
-   }
-
-   if (!mod)
+   if (modifier_hi == (DRM_FORMAT_MOD_INVALID >> 32) &&
+       modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff))
       return;
 
    dri2_dpy->formats |= (1 << visual_idx);
+
+   mod = u_vector_add(&dri2_dpy->wl_modifiers[visual_idx]);
    *mod = (uint64_t) modifier_hi << 32;
    *mod |= (uint64_t) (modifier_lo & 0xffffffff);
 }
@@ -1358,12 +1311,13 @@ dri2_initialize_wayland_drm(_EGLDriver *drv, 
_EGLDisplay *disp)
       dri2_dpy->wl_dpy = disp->PlatformDisplay;
    }
 
-   if (!u_vector_init(&dri2_dpy->wl_modifiers.xrgb2101010, sizeof(uint64_t), 
32) ||
-       !u_vector_init(&dri2_dpy->wl_modifiers.argb2101010, sizeof(uint64_t), 
32) ||
-       !u_vector_init(&dri2_dpy->wl_modifiers.xrgb8888, sizeof(uint64_t), 32) 
||
-       !u_vector_init(&dri2_dpy->wl_modifiers.argb8888, sizeof(uint64_t), 32) 
||
-       !u_vector_init(&dri2_dpy->wl_modifiers.rgb565, sizeof(uint64_t), 32)) {
+   dri2_dpy->wl_modifiers =
+      calloc(ARRAY_SIZE(dri2_wl_visuals), sizeof(*dri2_dpy->wl_modifiers));
+   if (!dri2_dpy->wl_modifiers)
       goto cleanup;
+   for (int i = 0; i < ARRAY_SIZE(dri2_wl_visuals); i++) {
+      if (!u_vector_init(&dri2_dpy->wl_modifiers[i], sizeof(uint64_t), 32))
+         goto cleanup;
    }
 
    dri2_dpy->wl_queue = wl_display_create_queue(dri2_dpy->wl_dpy);
@@ -2094,11 +2048,11 @@ dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy)
       wl_event_queue_destroy(dri2_dpy->wl_queue);
    if (dri2_dpy->wl_dpy_wrapper)
       wl_proxy_wrapper_destroy(dri2_dpy->wl_dpy_wrapper);
-   u_vector_finish(&dri2_dpy->wl_modifiers.argb2101010);
-   u_vector_finish(&dri2_dpy->wl_modifiers.xrgb2101010);
-   u_vector_finish(&dri2_dpy->wl_modifiers.argb8888);
-   u_vector_finish(&dri2_dpy->wl_modifiers.xrgb8888);
-   u_vector_finish(&dri2_dpy->wl_modifiers.rgb565);
+
+   for (int i = 0; dri2_dpy->wl_modifiers && i < ARRAY_SIZE(dri2_wl_visuals); 
i++)
+      u_vector_finish(&dri2_dpy->wl_modifiers[i]);
+   free(dri2_dpy->wl_modifiers);
+
    if (dri2_dpy->own_device)
       wl_display_disconnect(dri2_dpy->wl_dpy);
 }

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to