egl/wayland: Use an array for modifiers
authorDaniel Stone <daniels@collabora.com>
Tue, 6 Feb 2018 10:29:13 +0000 (10:29 +0000)
committerDaniel Stone <daniels@collabora.com>
Fri, 9 Feb 2018 16:17:16 +0000 (16:17 +0000)
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 <daniels@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_wayland.c

index c49156fbb6e8f091d116ee17039792bd3334f118..0f4e7a8d1e8093478bbd6c2f790683650850d63d 100644 (file)
@@ -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;
index d214a8515d6ce16547d1f5b6950de226409b8a2e..f91baded8776b2733a890ed40ae2698902fa70d6 100644 (file)
@@ -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);
 }