From 628f12a48bb4f82405d7a38ad661e5abeb84172d Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 13 Dec 2023 16:21:34 +0100 Subject: [PATCH] tests/wayland-test-clients: Try simple dma-buf alloc first and fall back to the complex one. If a driver supports allocating linear YCbCr formats we can use that instead of constructing our own compatible buffer. Part-of: --- .../wayland-test-client-utils.c | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c b/src/tests/wayland-test-clients/wayland-test-client-utils.c index a579dce10..c0bbc796b 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c @@ -1097,8 +1097,8 @@ alloc_dmabuf_simple (WaylandBuffer *buffer, } static gboolean -alloc_dmabuf_ycbcr (WaylandBuffer *buffer, - uint32_t bo_flags) +alloc_dmabuf_complex (WaylandBuffer *buffer, + uint32_t bo_flags) { WaylandBufferDmabuf *dmabuf = WAYLAND_BUFFER_DMABUF (buffer); WaylandBufferPrivate *priv = wayland_buffer_get_instance_private (buffer); @@ -1151,6 +1151,8 @@ alloc_dmabuf_ycbcr (WaylandBuffer *buffer, vsub[1] = 2; hsub[2] = 2; break; + default: + return FALSE; } wl_params = zwp_linux_dmabuf_v1_create_params (wl_dmabuf); @@ -1240,6 +1242,9 @@ wayland_buffer_dmabuf_allocate (WaylandBuffer *buffer, GUINT_TO_POINTER (priv->format)); g_assert_nonnull (dma_buf_format); + if (alloc_dmabuf_simple (buffer, n_modifiers, modifiers, bo_flags)) + return TRUE; + may_alloc_linear = !modifiers; for (i = 0; i < n_modifiers; i++) { @@ -1251,23 +1256,10 @@ wayland_buffer_dmabuf_allocate (WaylandBuffer *buffer, } } - switch (priv->format) - { - case DRM_FORMAT_ARGB8888: - case DRM_FORMAT_XRGB8888: - return alloc_dmabuf_simple (buffer, n_modifiers, modifiers, bo_flags); - case DRM_FORMAT_YUYV: - case DRM_FORMAT_NV12: - case DRM_FORMAT_P010: - case DRM_FORMAT_YUV420: - if (!may_alloc_linear) - return FALSE; - return alloc_dmabuf_ycbcr (buffer, bo_flags); - default: - g_assert_not_reached (); - } + if (!may_alloc_linear) + return FALSE; - return FALSE; + return alloc_dmabuf_complex (buffer, bo_flags); } static void *