From 90c11cf40e5c81e7dfc7549ac6e47235a5d84db8 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Wed, 21 Jun 2023 10:49:20 +0200
Subject: [PATCH] libweston: move weston_compositor_shutdown call out of
backends
If we want to support multiple backends, the compositor must take care
to call this once, at the appropriate moment, so stop letting the
backends handle compositor shutdown themselves.
Move the weston_compositor_shutdown() calls from the backend::destroy
callbacks into weston_compositor_destroy() and the calls in the backend
creation error paths into weston_compositor_load_backend().
Signed-off-by: Philipp Zabel
---
libweston/backend-drm/drm.c | 3 ---
libweston/backend-headless/headless.c | 4 ----
libweston/backend-pipewire/pipewire.c | 4 ----
libweston/backend-rdp/rdp.c | 4 ----
libweston/backend-vnc/vnc.c | 3 ---
libweston/backend-wayland/wayland.c | 4 ----
libweston/backend-x11/x11.c | 2 --
libweston/compositor.c | 5 ++++-
libweston/libweston-internal.h | 2 --
9 files changed, 4 insertions(+), 27 deletions(-)
diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
index 7134c809..647e3dc7 100644
--- a/libweston/backend-drm/drm.c
+++ b/libweston/backend-drm/drm.c
@@ -3260,8 +3260,6 @@ drm_destroy(struct weston_backend *backend)
struct drm_crtc *crtc, *crtc_tmp;
struct drm_writeback *writeback, *writeback_tmp;
- weston_compositor_shutdown(ec);
-
wl_list_for_each_safe(crtc, crtc_tmp, &b->drm->crtc_list, link)
drm_crtc_destroy(crtc);
@@ -4021,7 +4019,6 @@ err_udev:
err_launcher:
weston_launcher_destroy(compositor->launcher);
err_compositor:
- weston_compositor_shutdown(compositor);
#ifdef BUILD_DRM_GBM
if (b->gbm)
gbm_device_destroy(b->gbm);
diff --git a/libweston/backend-headless/headless.c b/libweston/backend-headless/headless.c
index 40c51d61..9ddfa402 100644
--- a/libweston/backend-headless/headless.c
+++ b/libweston/backend-headless/headless.c
@@ -506,8 +506,6 @@ headless_destroy(struct weston_backend *backend)
struct weston_compositor *ec = b->compositor;
struct weston_head *base, *next;
- weston_compositor_shutdown(ec);
-
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
if (to_headless_head(base))
headless_head_destroy(base);
@@ -625,8 +623,6 @@ headless_backend_create(struct weston_compositor *compositor,
err_input:
if (b->theme)
theme_destroy(b->theme);
-
- weston_compositor_shutdown(compositor);
err_free:
free(b);
return NULL;
diff --git a/libweston/backend-pipewire/pipewire.c b/libweston/backend-pipewire/pipewire.c
index b45037f3..93ac835c 100644
--- a/libweston/backend-pipewire/pipewire.c
+++ b/libweston/backend-pipewire/pipewire.c
@@ -645,8 +645,6 @@ pipewire_destroy(struct weston_backend *base)
weston_log_scope_destroy(b->debug);
b->debug = NULL;
- weston_compositor_shutdown(ec);
-
pw_loop_leave(b->loop);
pw_loop_destroy(b->loop);
wl_event_source_remove(b->loop_source);
@@ -1098,8 +1096,6 @@ pipewire_backend_create(struct weston_compositor *compositor,
return backend;
err_compositor:
- weston_compositor_shutdown(compositor);
-
free(backend);
return NULL;
}
diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c
index 02c5135e..92ac7100 100644
--- a/libweston/backend-rdp/rdp.c
+++ b/libweston/backend-rdp/rdp.c
@@ -740,8 +740,6 @@ rdp_destroy(struct weston_backend *backend)
b->verbose = NULL;
}
- weston_compositor_shutdown(ec);
-
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
if (to_rdp_head(base))
rdp_head_destroy(base);
@@ -2035,8 +2033,6 @@ err_compositor:
if (to_rdp_head(base))
rdp_head_destroy(base);
}
-
- weston_compositor_shutdown(compositor);
err_free_strings:
if (b->clipboard_debug)
weston_log_scope_destroy(b->clipboard_debug);
diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c
index 050bddef..05154c66 100644
--- a/libweston/backend-vnc/vnc.c
+++ b/libweston/backend-vnc/vnc.c
@@ -884,8 +884,6 @@ vnc_destroy(struct weston_backend *base)
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
- weston_compositor_shutdown(ec);
-
wl_event_source_remove(backend->aml_event);
aml_unref(backend->aml);
@@ -1344,7 +1342,6 @@ err_output:
wl_list_for_each_safe(base, next, &compositor->head_list, compositor_link)
vnc_head_destroy(base);
err_compositor:
- weston_compositor_shutdown(compositor);
free(backend);
return NULL;
}
diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c
index 53e53ebb..5730a5d3 100644
--- a/libweston/backend-wayland/wayland.c
+++ b/libweston/backend-wayland/wayland.c
@@ -2756,8 +2756,6 @@ wayland_destroy(struct weston_backend *backend)
struct wayland_parent_output *output, *next_output;
struct wayland_input *input, *next_input;
- weston_compositor_shutdown(ec);
-
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
if (to_wayland_head(base))
wayland_head_destroy(base);
@@ -2961,7 +2959,6 @@ err_renderer:
err_display:
wl_display_disconnect(b->parent.wl_display);
err_compositor:
- weston_compositor_shutdown(compositor);
free(b->formats);
free(b);
return NULL;
@@ -2978,7 +2975,6 @@ wayland_backend_destroy(struct wayland_backend *b)
cairo_device_destroy(b->frame_device);
wl_cursor_theme_destroy(b->cursor_theme);
- weston_compositor_shutdown(b->compositor);
cleanup_after_cairo();
free(b->formats);
free(b);
diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c
index dc42c95d..19983c14 100644
--- a/libweston/backend-x11/x11.c
+++ b/libweston/backend-x11/x11.c
@@ -1844,8 +1844,6 @@ x11_destroy(struct weston_backend *base)
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
- weston_compositor_shutdown(ec); /* destroys outputs, too */
-
wl_list_for_each_safe(head, next, &ec->head_list, compositor_link) {
if (to_x11_head(head))
x11_head_destroy(head);
diff --git a/libweston/compositor.c b/libweston/compositor.c
index f95a3eff..766ebd52 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -8714,7 +8714,7 @@ fail:
/** weston_compositor_shutdown
* \ingroup compositor
*/
-WL_EXPORT void
+static void
weston_compositor_shutdown(struct weston_compositor *ec)
{
struct weston_output *output, *next;
@@ -9091,6 +9091,8 @@ weston_compositor_destroy(struct weston_compositor *compositor)
if (compositor->backend && compositor->backend->shutdown)
compositor->backend->shutdown(compositor->backend);
+ weston_compositor_shutdown(compositor);
+
if (compositor->backend)
compositor->backend->destroy(compositor->backend);
@@ -9196,6 +9198,7 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
if (backend_init(compositor, config_base) < 0) {
compositor->backend = NULL;
+ weston_compositor_shutdown(compositor);
return -1;
}
diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h
index aaf94366..e43f484a 100644
--- a/libweston/libweston-internal.h
+++ b/libweston/libweston-internal.h
@@ -243,8 +243,6 @@ weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
int
weston_compositor_set_presentation_clock_software(
struct weston_compositor *compositor);
-void
-weston_compositor_shutdown(struct weston_compositor *ec);
void
weston_compositor_xkb_destroy(struct weston_compositor *ec);