[Mesa-dev] [PATCH 12/18] egl/wayland: Use an array for modifiers
Daniel Stone
daniels at collabora.com
Thu Feb 8 14:06:02 UTC 2018
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 at collabora.com>
---
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 9ba5e6d0ac0..4e711ff3851 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -217,13 +217,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 91e2ef8cd32..7ab085ccf44 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -432,37 +432,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);
@@ -1180,36 +1151,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);
}
@@ -1351,12 +1304,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);
@@ -2087,11 +2041,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);
}
--
2.14.3
More information about the mesa-dev
mailing list