Expose to the DMABUF protocol the pixel formats already explicitly
supported as fallback by gl-renderer in import_yuv_dmabuf function plus
the standard RGB formats that all GPU supports:
ARGB8888, XRGB8888, RGB565, YUYV, NV12, YUV420 and YUV444.

Signed-off-by: Vincent Abriou <vincent.abr...@st.com>
---
v2:
 - Remove dependency with libdrm as suggested by Daniel Stone.
   To do so, the reuse of wl_shm enums is not possible because
   WL_SHM_FORMAT_ARGB8888 (=0) and WL_SHM_FORMAT_XRGB8888 (=1) do not
   match fourcc. So I had to directly use fourcc to describe the supported
   dmabuf formats.


 libweston/linux-dmabuf.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c
index 7b29f08..748b664 100644
--- a/libweston/linux-dmabuf.c
+++ b/libweston/linux-dmabuf.c
@@ -30,6 +30,29 @@
 #include "compositor.h"
 #include "linux-dmabuf.h"
 #include "linux-dmabuf-unstable-v1-server-protocol.h"
+#include "shared/helpers.h"
+
+/* linux-dmabuf should not be dependent from libdrm thus we need to define
+ * dmabuf formats using fourcc */
+#define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
+                               ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
+
+uint32_t dmabuf_formats[] = {
+       /* ARGB8888 [31:0] A:R:G:B 8:8:8:8 little endian */
+       fourcc_code('A', 'R', '2', '4'),
+       /* XRGB8888 [31:0] x:R:G:B 8:8:8:8 little endian */
+       fourcc_code('X', 'R', '2', '4'),
+       /* RGB565   [15:0] R:G:B 5:6:5 little endian*/
+       fourcc_code('R', 'G', '1', '6'),
+       /* YUYV     [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
+       fourcc_code('Y', 'U', 'Y', 'V'),
+       /* NV12     2x2 subsampled Cr:Cb plane*/
+       fourcc_code('N', 'V', '1', '2'),
+       /* YUV420   2x2 subsampled Cb (1) and Cr (2) planes*/
+       fourcc_code('Y', 'U', '1', '2'),
+       /* YUV444   non-subsampled Cb (1) and Cr (2) planes */
+       fourcc_code('Y', 'U', '2', '4'),
+};
 
 static void
 linux_dmabuf_buffer_destroy(struct linux_dmabuf_buffer *buffer)
@@ -423,6 +446,7 @@ bind_linux_dmabuf(struct wl_client *client,
 {
        struct weston_compositor *compositor = data;
        struct wl_resource *resource;
+       unsigned int i;
 
        resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
                                      version, id);
@@ -434,9 +458,8 @@ bind_linux_dmabuf(struct wl_client *client,
        wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
                                       compositor, NULL);
 
-       /* EGL_EXT_image_dma_buf_import does not provide a way to query the
-        * supported pixel formats. */
-       /* XXX: send formats */
+       for (i = 0; i < ARRAY_LENGTH(dmabuf_formats); i++)
+               zwp_linux_dmabuf_v1_send_format(resource, dmabuf_formats[i]);
 }
 
 /** Advertise linux_dmabuf support
-- 
2.7.4

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to