backend/headless: handle renderer destroy

When the headless backend uses an already-existing renderer, it doesn't
have ownership over the renderer. When the renderer is destroyed, the
headless backend needs to destroy itself.
This commit is contained in:
Simon Ser 2020-05-02 16:44:34 +02:00 committed by Drew DeVault
parent 7720ce7827
commit 46c83cbf3d
2 changed files with 14 additions and 1 deletions

View file

@ -47,6 +47,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
}
wl_list_remove(&backend->display_destroy.link);
wl_list_remove(&backend->renderer_destroy.link);
struct wlr_headless_output *output, *output_tmp;
wl_list_for_each_safe(output, output_tmp, &backend->outputs, link) {
@ -61,8 +62,8 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
wlr_signal_emit_safe(&wlr_backend->events.destroy, backend);
wlr_renderer_destroy(backend->renderer);
if (backend->egl == &backend->priv_egl) {
wlr_renderer_destroy(backend->renderer);
wlr_egl_finish(&backend->priv_egl);
}
free(backend);
@ -87,6 +88,12 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
backend_destroy(&backend->backend);
}
static void handle_renderer_destroy(struct wl_listener *listener, void *data) {
struct wlr_headless_backend *backend =
wl_container_of(listener, backend, renderer_destroy);
backend_destroy(&backend->backend);
}
static bool backend_init(struct wlr_headless_backend *backend,
struct wl_display *display, struct wlr_renderer *renderer) {
wlr_backend_init(&backend->backend, &backend_impl);
@ -112,6 +119,8 @@ static bool backend_init(struct wlr_headless_backend *backend,
backend->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &backend->display_destroy);
wl_list_init(&backend->renderer_destroy.link);
return true;
}
@ -173,6 +182,9 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer(
return NULL;
}
backend->renderer_destroy.notify = handle_renderer_destroy;
wl_signal_add(&renderer->events.destroy, &backend->renderer_destroy);
return &backend->backend;
}

View file

@ -17,6 +17,7 @@ struct wlr_headless_backend {
size_t last_output_num;
struct wl_list input_devices;
struct wl_listener display_destroy;
struct wl_listener renderer_destroy;
bool started;
GLenum internal_format;
};