wayland-ivi-extension: disable building EGLWLMockNavigation example
[AGL/meta-agl.git] / meta-agl-profile-graphical / recipes-graphics / wayland / weston / 0017-compositor-drm-introduce-drm_get_dmafd_from_view.patch
1 From 020508b35b2bf6c89d62961eb95e2f81d6381ab5 Mon Sep 17 00:00:00 2001
2 From: Veeresh Kadasani <external.vkadasani@jp.adit-jv.com>
3 Date: Mon, 29 Jul 2019 17:07:00 +0900
4 Subject: [PATCH 2/3] compositor-drm: introduce drm_get_dmafd_from_view
5
6 This API enables to get dmafd from weston_view
7
8 Signed-off-by: Veeresh Kadasani <external.vkadasani@jp.adit-jv.com>
9 ---
10  libweston/compositor-drm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++
11  libweston/compositor-drm.h |  7 ++++++
12  2 files changed, 64 insertions(+)
13
14 diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
15 index 26a480c..2b99db5 100644
16 --- a/libweston/compositor-drm.c
17 +++ b/libweston/compositor-drm.c
18 @@ -5420,6 +5420,62 @@ 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 +       bool is_opaque = drm_view_is_opaque(ev);
31 +       uint32_t format;
32 +       int fd, ret;
33 +
34 +       if(!buffer) {
35 +               weston_log("buffer is NULL\n");
36 +               return -1;
37 +       }
38 +
39 +       if(dmabuf = linux_dmabuf_buffer_get(buffer->resource)) {
40 +               current = drm_fb_get_from_dmabuf(dmabuf, b, is_opaque);
41 +               if (!current)
42 +               {
43 +                       fprintf(stderr, "failed to get drm_fb from dmabuf\n");
44 +                       return -1;
45 +               }
46 +       }
47 +       else if(ev->surface->buffer_ref.buffer->legacy_buffer) {
48 +               bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
49 +                                  buffer->resource, GBM_BO_USE_SCANOUT);
50 +               if (!bo) {
51 +                       weston_log("failed to get gbm_bo\n");
52 +                       return -1;
53 +               }
54 +               current = drm_fb_get_from_bo(bo, b, is_opaque, BUFFER_CLIENT);
55 +
56 +               if (!current) {
57 +                       weston_log("failed to get drm_fb from bo\n");
58 +                       return -1;
59 +               }
60 +
61 +       }
62 +       else {
63 +               weston_log("Buffer is not supported\n");
64 +               return -1;
65 +       }
66 +
67 +       ret = drmPrimeHandleToFD(b->drm.fd, current->handles[0],
68 +                                DRM_CLOEXEC, &fd);
69 +       free(current);
70 +       if (ret) {
71 +               weston_log("failed to create prime fd for front buffer\n");
72 +               return -1;
73 +       }
74 +
75 +       return fd;
76 +}
77 +static int
78  drm_output_init_gamma_size(struct drm_output *output)
79  {
80         struct drm_backend *backend = to_drm_backend(output->base.compositor);
81 @@ -6696,6 +6752,7 @@ static const struct weston_drm_output_api api = {
82         drm_output_set_mode,
83         drm_output_set_gbm_format,
84         drm_output_set_seat,
85 +       drm_get_dma_fd_from_view,
86  };
87  
88  static struct drm_backend *
89 diff --git a/libweston/compositor-drm.h b/libweston/compositor-drm.h
90 index 9c37c15..a82a2a9 100644
91 --- a/libweston/compositor-drm.h
92 +++ b/libweston/compositor-drm.h
93 @@ -78,6 +78,13 @@ struct weston_drm_output_api {
94          */
95         void (*set_seat)(struct weston_output *output,
96                          const char *seat);
97 +
98 +        /** Get the dma fd from drm view.
99 +        *
100 +         *  The dma fd is got from weston_view.
101 +        *  Returns fd on success, -1 on failure.
102 +        */
103 +       int (*get_dma_fd_from_view)(struct weston_output *output, struct weston_view *view);
104  };
105  
106  static inline const struct weston_drm_output_api *
107 -- 
108 2.7.4
109