drm-lease: Update support for weston 10.0
[AGL/meta-agl-devel.git] / meta-agl-drm-lease / recipes-graphics / weston / weston / 0002-Add-DRM-lease-support.patch
1 From 5c315a4e4ab5e0d0376508f72c6f8a8070251c3f Mon Sep 17 00:00:00 2001
2 From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
3 Date: Mon, 11 Apr 2022 18:43:06 +0900
4 Subject: [PATCH 2/3] Add DRM lease support
5
6 Add a command line option to use a DRM lease instead of a primary node for
7 output when using the DRM backend.
8
9 %% original patch: 0002-Add-DRM-lease-support.patch
10 ---
11  compositor/drm-lease.c      | 53 +++++++++++++++++++++++++++++++++++++
12  compositor/drm-lease.h      | 40 ++++++++++++++++++++++++++++
13  compositor/main.c           | 10 +++++++
14  compositor/meson.build      |  5 ++++
15  libweston/backend-drm/drm.c |  1 +
16  meson_options.txt           |  7 +++++
17  6 files changed, 116 insertions(+)
18  create mode 100644 compositor/drm-lease.c
19  create mode 100644 compositor/drm-lease.h
20
21 diff --git a/compositor/drm-lease.c b/compositor/drm-lease.c
22 new file mode 100644
23 index 0000000..fdb1f5e
24 --- /dev/null
25 +++ b/compositor/drm-lease.c
26 @@ -0,0 +1,53 @@
27 +/*
28 + * Copyright © 2021 IGEL Co., Ltd.
29 + *
30 + * Permission is hereby granted, free of charge, to any person obtaining
31 + * a copy of this software and associated documentation files (the
32 + * "Software"), to deal in the Software without restriction, including
33 + * without limitation the rights to use, copy, modify, merge, publish,
34 + * distribute, sublicense, and/or sell copies of the Software, and to
35 + * permit persons to whom the Software is furnished to do so, subject to
36 + * the following conditions:
37 + *
38 + * The above copyright notice and this permission notice (including the
39 + * next paragraph) shall be included in all copies or substantial
40 + * portions of the Software.
41 + *
42 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
46 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
47 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
48 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49 + * SOFTWARE.
50 + */
51 +
52 +#include "drm-lease.h"
53 +
54 +#include <libweston/libweston.h>
55 +
56 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
57 +       if (!drm_lease_name)
58 +               return -1;
59 +
60 +       int drm_fd;
61 +       struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
62 +       if (lease) {
63 +               drm_fd = dlm_lease_fd(lease);
64 +               if (drm_fd < 0)
65 +                       dlm_release_lease(lease);
66 +       }
67 +       if (drm_fd < 0)
68 +           weston_log("Could not get DRM lease %s\n", drm_lease_name);
69 +
70 +        *drm_lease = lease;
71 +       return drm_fd;
72 +}
73 +
74 +void release_drm_lease(struct dlm_lease *lease) {
75 +       if (lease)
76 +               dlm_release_lease(lease);
77 +}
78 +
79 +
80 diff --git a/compositor/drm-lease.h b/compositor/drm-lease.h
81 new file mode 100644
82 index 0000000..a102e4c
83 --- /dev/null
84 +++ b/compositor/drm-lease.h
85 @@ -0,0 +1,40 @@
86 +/*
87 + * Copyright © 2021 IGEL Co., Ltd.
88 + *
89 + * Permission is hereby granted, free of charge, to any person obtaining
90 + * a copy of this software and associated documentation files (the
91 + * "Software"), to deal in the Software without restriction, including
92 + * without limitation the rights to use, copy, modify, merge, publish,
93 + * distribute, sublicense, and/or sell copies of the Software, and to
94 + * permit persons to whom the Software is furnished to do so, subject to
95 + * the following conditions:
96 + *
97 + * The above copyright notice and this permission notice (including the
98 + * next paragraph) shall be included in all copies or substantial
99 + * portions of the Software.
100 + *
101 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
102 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
103 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
104 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
105 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
106 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
107 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
108 + * SOFTWARE.
109 + */
110 +
111 +#include "config.h"
112 +
113 +#ifdef BUILD_DRM_LEASE_CLIENT
114 +#include <dlmclient.h>
115 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name);
116 +void release_drm_lease(struct dlm_lease *drm_lease);
117 +#else
118 +struct dlm_lease;
119 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
120 +       return -1;
121 +}
122 +void release_drm_lease(struct dlm_lease *drm_lease) {
123 +}
124 +
125 +#endif
126 diff --git a/compositor/main.c b/compositor/main.c
127 index 322f2ff..419ad06 100644
128 --- a/compositor/main.c
129 +++ b/compositor/main.c
130 @@ -65,6 +65,7 @@
131  #include <libweston/weston-log.h>
132  #include <libweston/remoting-plugin.h>
133  #include <libweston/pipewire-plugin.h>
134 +#include "drm-lease.h"
135  
136  #define WINDOW_TITLE "Weston Compositor"
137  /* flight recorder size (in bytes) */
138 @@ -127,6 +128,7 @@ struct wet_compositor {
139         pid_t autolaunch_pid;
140         bool autolaunch_watch;
141         bool use_color_manager;
142 +       struct dlm_lease *drm_lease;
143  };
144  
145  static FILE *weston_logfile = NULL;
146 @@ -687,6 +689,9 @@ usage(int error_code)
147                 "  --seat=SEAT\t\tThe seat that weston should run on, instead of the seat defined in XDG_SEAT\n"
148                 "  --tty=TTY\t\tThe tty to use\n"
149                 "  --drm-device=CARD\tThe DRM device to use, e.g. \"card0\".\n"
150 +#ifdef BUILD_DRM_LEASE_CLIENT
151 +               "  --drm-lease=lease\tUse the specified DRM lease. e.g \"card0-HDMI-A-1\"\n"
152 +#endif
153                 "  --use-pixman\t\tUse the pixman (CPU) renderer\n"
154                 "  --current-mode\tPrefer current KMS mode over EDID preferred mode\n"
155                 "  --continue-without-input\tAllow the compositor to start without input devices\n\n");
156 @@ -2626,6 +2631,7 @@ load_drm_backend(struct weston_compositor *c,
157         struct wet_compositor *wet = to_wet_compositor(c);
158         bool without_input = false;
159         int ret = 0;
160 +       char *drm_lease_name = NULL;
161  
162         wet->drm_use_current_mode = false;
163  
164 @@ -2637,6 +2643,7 @@ load_drm_backend(struct weston_compositor *c,
165                 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
166                 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
167                 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
168 +               { WESTON_OPTION_STRING, "drm-lease", 0, &drm_lease_name },
169                 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
170                 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
171                 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
172 @@ -2658,6 +2665,7 @@ load_drm_backend(struct weston_compositor *c,
173         config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
174         config.base.struct_size = sizeof(struct weston_drm_backend_config);
175         config.configure_device = configure_input_device;
176 +       config.device_fd = get_drm_lease(&wet->drm_lease, drm_lease_name);
177  
178         wet->heads_changed_listener.notify = drm_heads_changed;
179         weston_compositor_add_heads_changed_listener(c,
180 @@ -2675,6 +2683,7 @@ load_drm_backend(struct weston_compositor *c,
181         free(config.gbm_format);
182         free(config.seat_id);
183         free(config.specific_device);
184 +       free(drm_lease_name);
185  
186         return ret;
187  }
188 @@ -3577,6 +3586,7 @@ out:
189  
190         /* free(NULL) is valid, and it won't be NULL if it's used */
191         free(wet.parsed_options);
192 +       release_drm_lease(wet.drm_lease);
193  
194         if (protologger)
195                 wl_protocol_logger_destroy(protologger);
196 diff --git a/compositor/meson.build b/compositor/meson.build
197 index 8a54ea9..5700d25 100644
198 --- a/compositor/meson.build
199 +++ b/compositor/meson.build
200 @@ -25,6 +25,11 @@ if get_option('xwayland')
201         srcs_weston += 'xwayland.c'
202         config_h.set_quoted('XSERVER_PATH', get_option('xwayland-path'))
203  endif
204 +if get_option('drm-lease')
205 +       deps_weston += dependency('libdlmclient')
206 +       srcs_weston += 'drm-lease.c'
207 +       config_h.set('BUILD_DRM_LEASE_CLIENT', '1')
208 +endif
209  
210  libexec_weston = shared_library(
211         'exec_weston',
212 diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
213 index 0707db7..03e80ce 100644
214 --- a/libweston/backend-drm/drm.c
215 +++ b/libweston/backend-drm/drm.c
216 @@ -3267,6 +3267,7 @@ static void
217  config_init_to_defaults(struct weston_drm_backend_config *config)
218  {
219         config->use_pixman_shadow = true;
220 +       config->device_fd = -1;
221  }
222  
223  WL_EXPORT int
224 diff --git a/meson_options.txt b/meson_options.txt
225 index 8a527d7..db9f19b 100644
226 --- a/meson_options.txt
227 +++ b/meson_options.txt
228 @@ -106,6 +106,13 @@ option(
229         description: 'Virtual remote output with Pipewire on DRM backend'
230  )
231  
232 +option(
233 +        'drm-lease',
234 +        type: 'boolean',
235 +        value: false,
236 +        description: 'Support for running weston with a leased DRM Master'
237 +)
238 +
239  option(
240         'shell-desktop',
241         type: 'boolean',
242 -- 
243 2.17.1
244