[PATCH 6/7] compositor-drm: dmabuf GBM import

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Fri Dec 12 13:51:07 PST 2014


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

---
 src/compositor-drm.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 44fc912..d3e8b34 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -839,7 +839,9 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 	struct weston_compositor *ec = output_base->compositor;
 	struct drm_compositor *c =(struct drm_compositor *) ec;
 	struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
+	struct wl_resource *buffer_resource;
 	struct drm_sprite *s;
+	struct linux_dmabuf_buffer *dmabuf;
 	int found = 0;
 	struct gbm_bo *bo;
 	pixman_region32_t dest_rect, src_rect;
@@ -864,11 +866,12 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 
 	if (ev->surface->buffer_ref.buffer == NULL)
 		return NULL;
+	buffer_resource = ev->surface->buffer_ref.buffer->resource;
 
 	if (ev->alpha != 1.0f)
 		return NULL;
 
-	if (wl_shm_buffer_get(ev->surface->buffer_ref.buffer->resource))
+	if (wl_shm_buffer_get(buffer_resource))
 		return NULL;
 
 	if (!drm_view_transform_supported(ev))
@@ -888,9 +891,24 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 	if (!found)
 		return NULL;
 
-	bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER,
-			   ev->surface->buffer_ref.buffer->resource,
-			   GBM_BO_USE_SCANOUT);
+	if ((dmabuf = linux_dmabuf_buffer_get(buffer_resource))) {
+		struct gbm_import_fd_data gbm_dmabuf = {
+			.fd     = dmabuf->dmabuf_fd[0],
+			.width  = dmabuf->width,
+			.height = dmabuf->height,
+			.stride = dmabuf->stride[0],
+			.format = dmabuf->format
+		};
+
+		if (dmabuf->n_planes != 1 || dmabuf->offset[0] != 0)
+			return NULL;
+
+		bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_FD, &gbm_dmabuf,
+				   GBM_BO_USE_SCANOUT);
+	} else {
+		bo = gbm_bo_import(c->gbm, GBM_BO_IMPORT_WL_BUFFER,
+				   buffer_resource, GBM_BO_USE_SCANOUT);
+	}
 	if (!bo)
 		return NULL;
 
-- 
2.1.0



More information about the wayland-devel mailing list