libweston: add weston_backend::shutdown callback

Add a weston_backend::shutdown callback to split out the part of
weston_backend::destroy that needs to be done before compositor
shutdown.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
Philipp Zabel 2023-06-21 10:46:14 +02:00 committed by Daniel Stone
parent f9ef4e64ea
commit 6d699c3f54
7 changed files with 64 additions and 18 deletions

View file

@ -3203,17 +3203,13 @@ udev_drm_event(int fd, uint32_t mask, void *data)
return 1;
}
void
drm_destroy(struct weston_backend *backend)
static void
drm_shutdown(struct weston_backend *backend)
{
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct weston_compositor *ec = b->compositor;
struct drm_device *device = b->drm;
struct weston_head *base, *next;
struct weston_output *output_base;
struct drm_output *output;
struct drm_crtc *crtc, *crtc_tmp;
struct drm_writeback *writeback, *writeback_tmp;
udev_input_destroy(&b->input);
@ -3252,6 +3248,18 @@ drm_destroy(struct weston_backend *backend)
weston_log_scope_destroy(b->debug);
b->debug = NULL;
}
void
drm_destroy(struct weston_backend *backend)
{
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct weston_compositor *ec = b->compositor;
struct drm_device *device = b->drm;
struct weston_head *base, *next;
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)
@ -3861,6 +3869,7 @@ drm_backend_create(struct weston_compositor *compositor,
goto err_udev_dev;
}
b->base.shutdown = drm_shutdown;
b->base.destroy = drm_destroy;
b->base.repaint_begin = drm_repaint_begin;
b->base.repaint_flush = drm_repaint_flush;

View file

@ -692,12 +692,10 @@ rdp_head_destroy(struct weston_head *base)
free(head);
}
void
rdp_destroy(struct weston_backend *backend)
static void
rdp_shutdown(struct weston_backend *backend)
{
struct rdp_backend *b = container_of(backend, struct rdp_backend, base);
struct weston_compositor *ec = b->compositor;
struct weston_head *base, *next;
struct rdp_peers_item *rdp_peer, *tmp;
int i;
@ -713,6 +711,15 @@ rdp_destroy(struct weston_backend *backend)
if (b->listener_events[i])
wl_event_source_remove(b->listener_events[i]);
}
void
rdp_destroy(struct weston_backend *backend)
{
struct rdp_backend *b = container_of(backend, struct rdp_backend, base);
struct weston_compositor *ec = b->compositor;
struct weston_head *base, *next;
if (b->clipboard_debug) {
weston_log_scope_destroy(b->clipboard_debug);
b->clipboard_debug = NULL;
@ -1880,6 +1887,7 @@ rdp_backend_create(struct weston_compositor *compositor,
b = xzalloc(sizeof *b);
b->compositor_tid = gettid();
b->compositor = compositor;
b->base.shutdown = rdp_shutdown;
b->base.destroy = rdp_destroy;
b->base.create_output = rdp_output_create;
b->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;

View file

@ -869,6 +869,14 @@ vnc_create_output(struct weston_backend *backend, const char *name)
return &output->base;
}
static void
vnc_shutdown(struct weston_backend *base)
{
struct vnc_backend *backend = container_of(base, struct vnc_backend, base);
nvnc_close(backend->server);
}
static void
vnc_destroy(struct weston_backend *base)
{
@ -876,8 +884,6 @@ vnc_destroy(struct weston_backend *base)
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
nvnc_close(backend->server);
weston_compositor_shutdown(ec);
wl_event_source_remove(backend->aml_event);
@ -1217,6 +1223,7 @@ vnc_backend_create(struct weston_compositor *compositor,
return NULL;
backend->compositor = compositor;
backend->base.shutdown = vnc_shutdown;
backend->base.destroy = vnc_destroy;
backend->base.create_output = vnc_create_output;
backend->vnc_monitor_refresh_rate = config->refresh_rate * 1000;

View file

@ -2739,6 +2739,14 @@ wayland_backend_handle_event(int fd, uint32_t mask, void *data)
return count;
}
static void
wayland_shutdown(struct weston_backend *backend)
{
struct wayland_backend *b = to_wayland_backend(backend);
wl_event_source_remove(b->parent.wl_source);
}
static void
wayland_destroy(struct weston_backend *backend)
{
@ -2748,8 +2756,6 @@ wayland_destroy(struct weston_backend *backend)
struct wayland_parent_output *output, *next_output;
struct wayland_input *input, *next_input;
wl_event_source_remove(b->parent.wl_source);
weston_compositor_shutdown(ec);
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
@ -2928,6 +2934,7 @@ wayland_backend_create(struct weston_compositor *compositor,
}
}
b->base.shutdown = wayland_shutdown;
b->base.destroy = wayland_destroy;
b->base.create_output = wayland_output_create;

View file

@ -1829,14 +1829,20 @@ x11_backend_get_wm_info(struct x11_backend *c)
}
static void
x11_destroy(struct weston_backend *base)
x11_shutdown(struct weston_backend *base)
{
struct x11_backend *backend = container_of(base, struct x11_backend, base);
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
struct x11_backend *backend = to_x11_backend(base);
wl_event_source_remove(backend->xcb_source);
x11_input_destroy(backend);
}
static void
x11_destroy(struct weston_backend *base)
{
struct x11_backend *backend = to_x11_backend(base);
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
weston_compositor_shutdown(ec); /* destroys outputs, too */
@ -1923,6 +1929,7 @@ x11_backend_create(struct weston_compositor *compositor,
goto err_xdisplay;
}
b->base.shutdown = x11_shutdown;
b->base.destroy = x11_destroy;
b->base.create_output = x11_output_create;

View file

@ -35,6 +35,11 @@
struct weston_hdr_metadata_type1;
struct weston_backend {
/** Prepare for compositor shutdown (optional)
*
* This will be called before weston_compositor_shutdown()
*/
void (*shutdown)(struct weston_backend *backend);
void (*destroy)(struct weston_backend *backend);
/** Begin a repaint sequence

View file

@ -9088,6 +9088,9 @@ weston_compositor_destroy(struct weston_compositor *compositor)
weston_compositor_xkb_destroy(compositor);
if (compositor->backend && compositor->backend->shutdown)
compositor->backend->shutdown(compositor->backend);
if (compositor->backend)
compositor->backend->destroy(compositor->backend);