[PATCH weston v10 49/61] compositor-drm: Support modifiers for drm_fb

Daniel Stone daniels at collabora.com
Tue Apr 4 16:55:07 UTC 2017


Use the new drmModeAddFB2WithModifiers interface to import buffers with
modifiers.

Signed-off-by: Daniel Stone <daniels at collabora.com>

Differential Revision: https://phabricator.freedesktop.org/D1526

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 configure.ac               |  3 +++
 libweston/compositor-drm.c | 25 ++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 53650d03..1a8ed9b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -210,6 +210,9 @@ if test x$enable_drm_compositor = xyes; then
   PKG_CHECK_MODULES(DRM_COMPOSITOR_ATOMIC, [libdrm >= 2.4.75],
 		    [AC_DEFINE([HAVE_DRM_ATOMIC], 1, [libdrm supports atomic API])],
 		    [AC_MSG_WARN([libdrm does not support atomic modesetting, will omit that capability])])
+  PKG_CHECK_MODULES(DRM_COMPOSITOR_MODIFIERS, [libdrm >= 2.4.71],
+		    [AC_DEFINE([HAVE_DRM_ADDFB2_MODIFIERS], 1, [libdrm supports modifiers])],
+		    [AC_MSG_WARN([libdrm does not support AddFB2 with modifiers])])
 fi
 
 
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 6eb684ca..2062fb83 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -264,6 +264,7 @@ struct drm_fb {
 	uint32_t strides[4];
 	uint32_t offsets[4];
 	const struct pixel_format_info *format;
+	uint64_t modifier;
 	int width, height;
 	int fd;
 	struct weston_buffer_reference buffer_ref;
@@ -846,7 +847,28 @@ drm_fb_destroy_gbm(struct gbm_bo *bo, void *data)
 static int
 drm_fb_addfb(struct drm_fb *fb)
 {
-	int ret;
+	int ret = -EINVAL;
+#ifdef HAVE_DRM_ADDFB2_MODIFIERS
+	uint64_t mods[4] = { };
+	int i;
+#endif
+
+	/* If we have a modifier set, we must only use the WithModifiers
+	 * entrypoint; we cannot import it through legacy ioctls. */
+	if (fb->modifier) {
+		/* KMS demands that if a modifier is set, it must be the same
+		 * for all planes. */
+#ifdef HAVE_DRM_ADDFB2_MODIFIERS
+		for (i = 0; fb->handles[i]; i++)
+			mods[i] = fb->modifier;
+		ret = drmModeAddFB2WithModifiers(fb->fd, fb->width, fb->height,
+						 fb->format->format,
+						 fb->handles, fb->strides,
+						 fb->offsets, mods, &fb->fb_id,
+						 DRM_MODE_FB_MODIFIERS);
+#endif
+		return ret;
+	}
 
 	ret = drmModeAddFB2(fb->fd, fb->width, fb->height, fb->format->format,
 			    fb->handles, fb->strides, fb->offsets, &fb->fb_id,
@@ -999,6 +1021,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
 	memcpy(fb->strides, dmabuf->attributes.stride, sizeof(fb->strides));
 	memcpy(fb->offsets, dmabuf->attributes.offset, sizeof(fb->offsets));
 	fb->format = pixel_format_get_info(dmabuf->attributes.format);
+	fb->modifier = dmabuf->attributes.modifier[0];
 	fb->size = 0;
 	fb->fd = backend->drm.fd;
 
-- 
2.12.2



More information about the wayland-devel mailing list