wayland-ivi-extension: disable building EGLWLMockNavigation example
[AGL/meta-agl.git] / meta-agl-profile-graphical / recipes-graphics / wayland / weston / 0019-compositor-drm-introduce-drm_get_dmafd_from_view.patch
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
5
6 This API enables to get dmafd from weston_view
7
8 Signed-off-by: Wataru Mizuno <wmizuno@jp.adit-jv.com>
9 ---
10  libweston/compositor-drm.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++
11  libweston/compositor-drm.h |  7 ++++
12  2 files changed, 87 insertions(+)
13
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,
19  }
20  
21  static int
22 +drm_get_dma_fd_from_view(struct weston_output *base,
23 +                          struct weston_view *ev)
24 +{
25 +       struct drm_backend *b = to_drm_backend(base->compositor);
26 +       struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
27 +       struct gbm_bo *bo;
28 +       struct drm_fb *current;
29 +       struct linux_dmabuf_buffer *dmabuf;
30 +       uint32_t format;
31 +       int fd, ret;
32 +
33 +       if(!buffer) {
34 +               weston_log("buffer is NULL\n");
35 +               return -1;
36 +       }
37 +
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
45 +               };
46 +
47 +               bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD,
48 +                                  &gbm_dmabuf, GBM_BO_USE_SCANOUT);
49 +               if (!bo) {
50 +                       weston_log("failed to get gbm_bo\n");
51 +                       return -1;
52 +               }
53 +
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");
58 +                       return -1;
59 +               }
60 +       }
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);
64 +
65 +               if (!bo) {
66 +                       weston_log("failed to get gbm_bo\n");
67 +                       return -1;
68 +               }
69 +
70 +               format = gbm_bo_get_format(bo);
71 +               if (!format) {
72 +                       weston_log("failed to get format\n");
73 +                       gbm_bo_destroy(bo);
74 +                       return -1;
75 +               }
76 +
77 +               current = drm_fb_get_from_bo(bo, b, format);
78 +               if (!current) {
79 +                       weston_log("failed to get drm_fb\n");
80 +                       gbm_bo_destroy(bo);
81 +                       return -1;
82 +               }
83 +       }
84 +       else {
85 +               weston_log("Buffer is not supported\n");
86 +               return -1;
87 +       }
88 +
89 +       ret = drmPrimeHandleToFD(b->drm.fd, current->handle,
90 +                                DRM_CLOEXEC, &fd);
91 +       free(current);
92 +       if (ret) {
93 +               weston_log("failed to create prime fd for front buffer\n");
94 +               return -1;
95 +       }
96 +
97 +       return fd;
98 +}
99 +
100 +static int
101  drm_output_enable(struct weston_output *base)
102  {
103         struct drm_output *output = to_drm_output(base);
104 @@ -3199,6 +3278,7 @@ static const struct weston_drm_output_api api = {
105         drm_output_set_mode,
106         drm_output_set_gbm_format,
107         drm_output_set_seat,
108 +       drm_get_dma_fd_from_view,
109  };
110  
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 {
117          */
118         void (*set_seat)(struct weston_output *output,
119                          const char *seat);
120 +
121 +       /** Get the dma fd from drm view.
122 +        *
123 +         *  The dma fd is got from weston_view.
124 +        *  Returns fd on success, -1 on failure.
125 +        */
126 +       int (*get_dma_fd_from_view)(struct weston_output *output, struct weston_view *view);
127  };
128  
129  static inline const struct weston_drm_output_api *
130 -- 
131 2.7.4
132