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
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
11 Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
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
23 diff --git a/meson.build b/meson.build
24 index 0daf943..34c26f9 100644
27 @@ -193,6 +193,12 @@ elif policy_to_install == 'rba'
28 message('Installing rba policy')
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')
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(
46 description: 'Default policy when no specific policy was set'
53 + description: 'Support for running weston with a leased DRM Master'
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
60 #include <waltham-transmitter/transmitter_api.h>
63 +#include "drm-lease.h"
65 static int cached_tm_mday = -1;
66 static struct weston_log_scope *log_scope;
68 @@ -877,11 +879,13 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
71 bool without_input = false;
72 + char *drm_lease_name = NULL;
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[])
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;
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[])
92 free(config.gbm_format);
94 + free(drm_lease_name);
98 @@ -1789,6 +1795,7 @@ error_compositor:
102 + release_drm_lease(ivi.drm_lease);
103 weston_compositor_destroy(ivi.compositor);
105 weston_log_scope_destroy(log_scope);
106 diff --git a/src/drm-lease.c b/src/drm-lease.c
108 index 0000000..887277d
110 +++ b/src/drm-lease.c
113 + * Copyright © 2022 IGEL Co., Ltd.
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:
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.
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
137 +#include "drm-lease.h"
139 +#include <libweston/libweston.h>
141 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
142 + if (!drm_lease_name)
146 + struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
148 + drm_fd = dlm_lease_fd(lease);
150 + dlm_release_lease(lease);
153 + weston_log("Could not get DRM lease %s\n", drm_lease_name);
155 + *drm_lease = lease;
159 +void release_drm_lease(struct dlm_lease *lease) {
161 + dlm_release_lease(lease);
164 diff --git a/src/drm-lease.h b/src/drm-lease.h
166 index 0000000..9fdc428
168 +++ b/src/drm-lease.h
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);
181 +static int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
184 +static void release_drm_lease(struct dlm_lease *drm_lease) {
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
194 #include <libweston-desktop/libweston-desktop.h>
197 +#include "drm-lease.h"
199 #include "agl-shell-server-protocol.h"
201 @@ -106,6 +107,8 @@ struct ivi_compositor {
202 struct weston_layer panel;
203 struct weston_layer popup;
204 struct weston_layer fullscreen;
206 + struct dlm_lease *drm_lease;