20ca6eecd93a2af1fd6edf74ce071fe14da7f846
[AGL/meta-agl-devel.git] / meta-agl-drm-lease / recipes-graphics / agl-compositor / agl-compositor / 0001-Add-drm-lease-support.patch
1 From ed6cfbcf67221810f324a9889175c147728cf634 Mon Sep 17 00:00:00 2001
2 From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
3 Date: Tue, 12 Apr 2022 15:12:27 +0900
4 Subject: [PATCH] Add drm-lease support
5
6 Add an option to use a DRM lease instead of a DRM device
7 as the video output.  This will allow agl-compositor to
8 operate alongside other applications output via a DRM
9 lease.
10
11 Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
12 ---
13  meson.build          |  6 +++++
14  meson_options.txt    |  7 ++++++
15  src/compositor.c     |  7 ++++++
16  src/drm-lease.c      | 52 ++++++++++++++++++++++++++++++++++++++++++++
17  src/drm-lease.h      | 19 ++++++++++++++++
18  src/ivi-compositor.h |  3 +++
19  6 files changed, 94 insertions(+)
20  create mode 100644 src/drm-lease.c
21  create mode 100644 src/drm-lease.h
22
23 diff --git a/meson.build b/meson.build
24 index 0daf943..34c26f9 100644
25 --- a/meson.build
26 +++ b/meson.build
27 @@ -193,6 +193,12 @@ elif policy_to_install == 'rba'
28    message('Installing rba policy')
29  endif
30  
31 +if get_option('drm-lease')
32 +  deps_libweston += dependency('libdlmclient')
33 +  srcs_agl_compositor += 'src/drm-lease.c'
34 +  config_h.set('HAVE_DRM_LEASE', '1')
35 +endif
36 +
37  # From meson documentation:
38  # In order to look for headers in a specific directory you can use args :
39  # '-I/extra/include/dir, but this should only be used in exceptional cases for
40 diff --git a/meson_options.txt b/meson_options.txt
41 index dd1f3c0..89de273 100644
42 --- a/meson_options.txt
43 +++ b/meson_options.txt
44 @@ -5,3 +5,10 @@ option(
45         value: 'allow-all',
46         description: 'Default policy when no specific policy was set'
47  )
48 +
49 +option(
50 +       'drm-lease',
51 +       type: 'boolean',
52 +       value: false,
53 +       description: 'Support for running weston with a leased DRM Master'
54 +)
55 diff --git a/src/compositor.c b/src/compositor.c
56 index 7540fe3..771b7ce 100644
57 --- a/src/compositor.c
58 +++ b/src/compositor.c
59 @@ -64,6 +64,8 @@
60  #include <waltham-transmitter/transmitter_api.h>
61  #endif
62  
63 +#include "drm-lease.h"
64 +
65  static int cached_tm_mday = -1;
66  static struct weston_log_scope *log_scope;
67  
68 @@ -877,11 +879,13 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
69         int use_pixman = 0;
70         bool use_shadow;
71         bool without_input = false;
72 +       char *drm_lease_name = NULL;
73         int ret;
74  
75         const struct weston_option options[] = {
76                 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
77                 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
78 +               { WESTON_OPTION_STRING, "drm-lease", 0, &drm_lease_name },
79                 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
80                 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
81                 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
82 @@ -889,6 +893,7 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
83  
84         parse_options(options, ARRAY_LENGTH(options), argc, argv);
85         config.use_pixman = use_pixman;
86 +       config.device_fd = get_drm_lease(&ivi->drm_lease, drm_lease_name);
87         ivi->cmdline.use_current_mode = use_current_mode;
88  
89         section = weston_config_get_section(ivi->config, "core", NULL, NULL);
90 @@ -920,6 +925,7 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
91  error:
92         free(config.gbm_format);
93         free(config.seat_id);
94 +       free(drm_lease_name);
95         return ret;
96  }
97  
98 @@ -1789,6 +1795,7 @@ error_compositor:
99         free(modules);
100         modules = NULL;
101  
102 +       release_drm_lease(ivi.drm_lease);
103         weston_compositor_destroy(ivi.compositor);
104  
105         weston_log_scope_destroy(log_scope);
106 diff --git a/src/drm-lease.c b/src/drm-lease.c
107 new file mode 100644
108 index 0000000..887277d
109 --- /dev/null
110 +++ b/src/drm-lease.c
111 @@ -0,0 +1,52 @@
112 +/*
113 + * Copyright © 2022 IGEL Co., Ltd.
114 + *
115 + * Permission is hereby granted, free of charge, to any person obtaining
116 + * a copy of this software and associated documentation files (the
117 + * "Software"), to deal in the Software without restriction, including
118 + * without limitation the rights to use, copy, modify, merge, publish,
119 + * distribute, sublicense, and/or sell copies of the Software, and to
120 + * permit persons to whom the Software is furnished to do so, subject to
121 + * the following conditions:
122 + *
123 + * The above copyright notice and this permission notice (including the
124 + * next paragraph) shall be included in all copies or substantial
125 + * portions of the Software.
126 + *
127 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
128 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
129 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
130 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
131 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
132 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
133 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
134 + * SOFTWARE.
135 + */
136 +
137 +#include "drm-lease.h"
138 +
139 +#include <libweston/libweston.h>
140 +
141 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
142 +       if (!drm_lease_name)
143 +               return -1;
144 +
145 +       int drm_fd = -1;
146 +       struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
147 +       if (lease) {
148 +               drm_fd = dlm_lease_fd(lease);
149 +               if (drm_fd < 0)
150 +                       dlm_release_lease(lease);
151 +       }
152 +       if (drm_fd < 0)
153 +               weston_log("Could not get DRM lease %s\n", drm_lease_name);
154 +
155 +       *drm_lease = lease;
156 +       return drm_fd;
157 +}
158 +
159 +void release_drm_lease(struct dlm_lease *lease) {
160 +       if (lease)
161 +               dlm_release_lease(lease);
162 +}
163 +
164 diff --git a/src/drm-lease.h b/src/drm-lease.h
165 new file mode 100644
166 index 0000000..9fdc428
167 --- /dev/null
168 +++ b/src/drm-lease.h
169 @@ -0,0 +1,19 @@
170 +#ifndef DRM_LEASE_H
171 +#define DRM_LEASE_H
172 +
173 +#include "config.h"
174 +
175 +#ifdef HAVE_DRM_LEASE
176 +#include <dlmclient.h>
177 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name);
178 +void release_drm_lease(struct dlm_lease *drm_lease);
179 +#else
180 +struct dlm_lease;
181 +static int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
182 +       return -1;
183 +}
184 +static void release_drm_lease(struct dlm_lease *drm_lease) {
185 +}
186 +
187 +#endif
188 +#endif /* DRM_LEASE_H */
189 diff --git a/src/ivi-compositor.h b/src/ivi-compositor.h
190 index 78d1acd..8fe460b 100644
191 --- a/src/ivi-compositor.h
192 +++ b/src/ivi-compositor.h
193 @@ -35,6 +35,7 @@
194  #include <libweston-desktop/libweston-desktop.h>
195  
196  #include "remote.h"
197 +#include "drm-lease.h"
198  
199  #include "agl-shell-server-protocol.h"
200  
201 @@ -106,6 +107,8 @@ struct ivi_compositor {
202         struct weston_layer panel;
203         struct weston_layer popup;
204         struct weston_layer fullscreen;
205 +
206 +       struct dlm_lease *drm_lease;
207  };
208  
209  struct ivi_surface;
210 -- 
211 2.17.1
212