From 20c5b4527ced5c258c48ceb8d4cff105227061b3 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Tue, 16 Mar 2021 16:28:20 +0100
Subject: [PATCH] libweston: allow loading multiple backends
Before loading a backend, clear the weston_compositor::backend pointer
to check whether the backend supports multi-backend operation and adds
itself to the weston_compositor::backend_list.
Keep weston_compositor::backend pointing to the last loaded backend
either way, to allow the calling compositor code to store it away for
later, to check whether a head belongs to a given backend in the output
configuration code. This workaround can be removed after all backends
are converted to be multi-backend aware.
Signed-off-by: Philipp Zabel
---
include/libweston/libweston.h | 3 +++
libweston/compositor.c | 22 ++++++++++++++++------
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
index 69481ed20..cc76eb684 100644
--- a/include/libweston/libweston.h
+++ b/include/libweston/libweston.h
@@ -1480,6 +1480,9 @@ struct weston_compositor {
/* Whether to let the compositor run without any input device. */
bool require_input;
+ /* Whether to load multiple backends. */
+ bool multi_backend;
+
/* Test suite data */
struct weston_testsuite_data test_data;
diff --git a/libweston/compositor.c b/libweston/compositor.c
index dc9769cf4..7c97d61dd 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -9545,14 +9545,12 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
int (*backend_init)(struct weston_compositor *c,
struct weston_backend_config *config_base);
- if (compositor->backend) {
- weston_log("Error: attempt to load a backend when one is already loaded\n");
- return -1;
- }
-
if (backend >= ARRAY_LENGTH(backend_map))
return -1;
+ /* Clear backend pointer to catch multi-backend incapable backends. */
+ compositor->backend = NULL;
+
backend_init = weston_load_module(backend_map[backend],
"weston_backend_init",
LIBWESTON_MODULEDIR);
@@ -9564,7 +9562,19 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
return -1;
}
- wl_list_insert(&compositor->backend_list, &compositor->backend->link);
+ /* Multi-backend capable backends add themselves to the backend_list. */
+ if (compositor->backend) {
+ if (compositor->multi_backend) {
+ weston_log("error: backend does not support multi-backend operation\n");
+ return -1;
+ }
+ wl_list_insert(&compositor->backend_list,
+ &compositor->backend->link);
+ }
+
+ /* Point compositor->backend to the last loaded backend. */
+ compositor->backend = wl_container_of(compositor->backend_list.next,
+ compositor->backend, link);
return 0;
}