[PATCH v2] linux-dmabuf: advertise supported formats and modifiers

Varad Gautam varadgautam at gmail.com
Wed Apr 26 13:47:17 UTC 2017


From: Varad Gautam <varad.gautam at collabora.com>

implement 'modifier' event to communicate available formats and modifiers
to the client and support zwp_linux_dmabuf_v1 interface version 3.

v2: handle zero modifiers case, deprecate 'format' event.

Signed-off-by: Varad Gautam <varad.gautam at collabora.com>
---

Although DRM_FORMAT_MOD_NONE better articulates the no-modifier case, since
it is shared with DRM_FORMAT_MOD_LINEAR, we end up using
DRM_FORMAT_MOD_INVALID here.

protocol: https://patchwork.freedesktop.org/patch/133970/
tree: git://git.collabora.com/git/user/varad/weston.git dmabuf-modifiers-v2

 libweston/linux-dmabuf.c | 39 +++++++++++++++++++++++++++++++++++----
 libweston/linux-dmabuf.h |  3 +++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c
index 9121e59..4f153b1 100644
--- a/libweston/linux-dmabuf.c
+++ b/libweston/linux-dmabuf.c
@@ -467,6 +467,11 @@ bind_linux_dmabuf(struct wl_client *client,
 {
 	struct weston_compositor *compositor = data;
 	struct wl_resource *resource;
+	int *formats = NULL;
+	uint64_t *modifiers = NULL;
+	int num_formats, num_modifiers;
+	uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
+	int i, j;
 
 	resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
 				      version, id);
@@ -478,9 +483,35 @@ 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 */
+	/*
+	 * Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
+	 * format/modifier codes.
+	 */
+	compositor->renderer->query_dmabuf_formats(compositor, &formats,
+						   &num_formats);
+
+	for (i = 0; i < num_formats; i++) {
+		compositor->renderer->query_dmabuf_modifiers(compositor,
+							     formats[i],
+							     &modifiers,
+							     &num_modifiers);
+
+		/* send DRM_FORMAT_MOD_INVALID token when no modifiers are supported
+		 * for this format */
+		if (num_modifiers == 0) {
+			num_modifiers = 1;
+			modifiers = &modifier_invalid;
+		}
+		for (j = 0; j < num_modifiers; j++) {
+			uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
+			uint32_t modifier_hi = modifiers[j] >> 32;
+			zwp_linux_dmabuf_v1_send_modifier(resource, formats[i],
+							  modifier_hi,
+							  modifier_lo);
+		}
+		free(modifiers);
+	}
+	free(formats);
 }
 
 /** Advertise linux_dmabuf support
@@ -498,7 +529,7 @@ WL_EXPORT int
 linux_dmabuf_setup(struct weston_compositor *compositor)
 {
 	if (!wl_global_create(compositor->wl_display,
-			      &zwp_linux_dmabuf_v1_interface, 2,
+			      &zwp_linux_dmabuf_v1_interface, 3,
 			      compositor, bind_linux_dmabuf))
 		return -1;
 
diff --git a/libweston/linux-dmabuf.h b/libweston/linux-dmabuf.h
index 64f43e5..f4ab52c 100644
--- a/libweston/linux-dmabuf.h
+++ b/libweston/linux-dmabuf.h
@@ -29,6 +29,9 @@
 #include <stdint.h>
 
 #define MAX_DMABUF_PLANES 4
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
 
 struct linux_dmabuf_buffer;
 typedef void (*dmabuf_user_data_destroy_func)(
-- 
2.10.0



More information about the wayland-devel mailing list