1 From 3dbffb783f44752ec221a2ee7a94a21934d681a2 Mon Sep 17 00:00:00 2001
2 From: Wataru Mizuno <wmizuno@jp.adit-jv.com>
3 Date: Tue, 10 Apr 2018 12:22:07 +0900
4 Subject: [PATCH 5/5] compositor-drm: introduce drm_get_dmafd_from_view
6 This API enables to get dmafd from weston_view
8 Signed-off-by: Wataru Mizuno <wmizuno@jp.adit-jv.com>
10 libweston/compositor-drm.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++
11 libweston/compositor-drm.h | 7 ++++
12 2 files changed, 87 insertions(+)
14 diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
15 index 0b5b4c4..77f2ece 100644
16 --- a/libweston/compositor-drm.c
17 +++ b/libweston/compositor-drm.c
18 @@ -2430,6 +2430,85 @@ drm_output_set_seat(struct weston_output *base,
22 +drm_get_dma_fd_from_view(struct weston_output *base,
23 + struct weston_view *ev)
25 + struct drm_backend *b = to_drm_backend(base->compositor);
26 + struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
28 + struct drm_fb *current;
29 + struct linux_dmabuf_buffer *dmabuf;
34 + weston_log("buffer is NULL\n");
38 + if(dmabuf = linux_dmabuf_buffer_get(buffer->resource)) {
39 + struct gbm_import_fd_data gbm_dmabuf = {
40 + .fd = dmabuf->attributes.fd[0],
41 + .width = dmabuf->attributes.width,
42 + .height = dmabuf->attributes.height,
43 + .stride = dmabuf->attributes.stride[0],
44 + .format = dmabuf->attributes.format
47 + bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD,
48 + &gbm_dmabuf, GBM_BO_USE_SCANOUT);
50 + weston_log("failed to get gbm_bo\n");
54 + current = zalloc(sizeof *current);
55 + current->handle = gbm_bo_get_handle(bo).s32;
56 + if (!current->handle) {
57 + fprintf(stderr, "failed to get drm_handle\n");
61 + else if(ev->surface->buffer_ref.buffer->legacy_buffer) {
62 + bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
63 + buffer->resource, GBM_BO_USE_SCANOUT);
66 + weston_log("failed to get gbm_bo\n");
70 + format = gbm_bo_get_format(bo);
72 + weston_log("failed to get format\n");
77 + current = drm_fb_get_from_bo(bo, b, format);
79 + weston_log("failed to get drm_fb\n");
85 + weston_log("Buffer is not supported\n");
89 + ret = drmPrimeHandleToFD(b->drm.fd, current->handle,
93 + weston_log("failed to create prime fd for front buffer\n");
101 drm_output_enable(struct weston_output *base)
103 struct drm_output *output = to_drm_output(base);
104 @@ -3199,6 +3278,7 @@ static const struct weston_drm_output_api api = {
106 drm_output_set_gbm_format,
108 + drm_get_dma_fd_from_view,
111 static struct drm_backend *
112 diff --git a/libweston/compositor-drm.h b/libweston/compositor-drm.h
113 index 2e2995a..fe00bd5 100644
114 --- a/libweston/compositor-drm.h
115 +++ b/libweston/compositor-drm.h
116 @@ -78,6 +78,13 @@ struct weston_drm_output_api {
118 void (*set_seat)(struct weston_output *output,
121 + /** Get the dma fd from drm view.
123 + * The dma fd is got from weston_view.
124 + * Returns fd on success, -1 on failure.
126 + int (*get_dma_fd_from_view)(struct weston_output *output, struct weston_view *view);
129 static inline const struct weston_drm_output_api *