From a4f0666659b0b72f35b0efad95f8d39972391c16 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Wed, 11 Jan 2023 17:03:49 +0100
Subject: [PATCH] libweston, compositor: let weston_compositor_load_backend
return backend
Let weston_compositor_load_backend() return a backend pointer and remove
the backend pointer from struct weston_compositor.
Signed-off-by: Philipp Zabel
---
compositor/main.c | 16 +++++-----------
include/libweston/libweston.h | 3 +--
libweston/compositor.c | 18 +++++++++---------
3 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/compositor/main.c b/compositor/main.c
index dcb657708..1d8d86d3f 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -2971,7 +2971,6 @@ wet_compositor_load_backend(struct weston_compositor *compositor,
{
struct wet_compositor *wet = to_wet_compositor(compositor);
struct wet_backend *wb;
- int ret;
wb = xzalloc(sizeof *wb);
@@ -2983,20 +2982,15 @@ wet_compositor_load_backend(struct weston_compositor *compositor,
&wb->heads_changed_listener);
}
- ret = weston_compositor_load_backend(compositor, backend, config_base);
-
- if (ret == 0) {
- /*
- * At this point compositor->backend should point to the last
- * loaded backend.
- */
- wb->backend = compositor->backend;
- wl_list_insert(wet->backend_list.prev, &wb->compositor_link);
- } else {
+ wb->backend = weston_compositor_load_backend(compositor, backend,
+ config_base);
+ if (!wb->backend) {
free(wb);
return NULL;
}
+ wl_list_insert(wet->backend_list.prev, &wb->compositor_link);
+
return wb;
}
diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
index cc76eb684..90b6ec913 100644
--- a/include/libweston/libweston.h
+++ b/include/libweston/libweston.h
@@ -1439,7 +1439,6 @@ struct weston_compositor {
struct weston_renderer *renderer;
const struct pixel_format_info *read_format;
- struct weston_backend *backend;
struct wl_list backend_list;
struct weston_launcher *launcher;
@@ -2331,7 +2330,7 @@ enum weston_renderer_type {
WESTON_RENDERER_GL = 3,
};
-int
+struct weston_backend *
weston_compositor_load_backend(struct weston_compositor *compositor,
enum weston_compositor_backend backend,
struct weston_backend_config *config_base);
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 32d0f35f2..8ae1d3d91 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -9537,35 +9537,35 @@ static const char * const backend_map[] = {
* \param config_base A pointer to a backend-specific configuration
* structure's 'base' member.
*
- * \return 0 on success, or -1 on error.
+ * \return A new \c weston_backend on success, or NULL on error.
*
* \ingroup compositor
*/
-WL_EXPORT int
+WL_EXPORT struct weston_backend *
weston_compositor_load_backend(struct weston_compositor *compositor,
enum weston_compositor_backend backend,
struct weston_backend_config *config_base)
{
int (*backend_init)(struct weston_compositor *c,
struct weston_backend_config *config_base);
+ struct weston_backend *b;
if (backend >= ARRAY_LENGTH(backend_map))
- return -1;
+ return NULL;
backend_init = weston_load_module(backend_map[backend],
"weston_backend_init",
LIBWESTON_MODULEDIR);
if (!backend_init)
- return -1;
+ return NULL;
if (backend_init(compositor, config_base) < 0)
- return -1;
+ return NULL;
- /* Point compositor->backend to the last loaded backend. */
- compositor->backend = wl_container_of(compositor->backend_list.next,
- compositor->backend, link);
+ /* Return the last loaded backend. */
+ b = wl_container_of(compositor->backend_list.next, b, link);
- return 0;
+ return b;
}
WL_EXPORT int