mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
backend/wayland: use a separate event queue for busy loops
This avoids processing events which we're not interested in. Specifically, this fixes a case where output_commit() could be indirectly called from itself either from import_dmabuf() or while waiting for a configure event when enabling the output.
This commit is contained in:
parent
35ff09a754
commit
b13fe9b3a1
3 changed files with 38 additions and 7 deletions
|
|
@ -555,6 +555,7 @@ static void backend_destroy(struct wlr_backend *backend) {
|
|||
wl_compositor_destroy(wl->compositor);
|
||||
wl_registry_destroy(wl->registry);
|
||||
wl_display_flush(wl->remote_display);
|
||||
wl_event_queue_destroy(wl->busy_loop_queue);
|
||||
if (wl->own_remote_display) {
|
||||
wl_display_disconnect(wl->remote_display);
|
||||
}
|
||||
|
|
@ -610,10 +611,16 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_event_loop *loop,
|
|||
wl->own_remote_display = true;
|
||||
}
|
||||
|
||||
wl->busy_loop_queue = wl_display_create_queue(wl->remote_display);
|
||||
if (wl->busy_loop_queue == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Could not create a Wayland event queue");
|
||||
goto error_display;
|
||||
}
|
||||
|
||||
wl->registry = wl_display_get_registry(wl->remote_display);
|
||||
if (!wl->registry) {
|
||||
wlr_log_errno(WLR_ERROR, "Could not obtain reference to remote registry");
|
||||
goto error_display;
|
||||
goto error_queue;
|
||||
}
|
||||
wl_registry_add_listener(wl->registry, ®istry_listener, wl);
|
||||
|
||||
|
|
@ -715,6 +722,8 @@ error_registry:
|
|||
xdg_wm_base_destroy(wl->xdg_wm_base);
|
||||
}
|
||||
wl_registry_destroy(wl->registry);
|
||||
error_queue:
|
||||
wl_event_queue_destroy(wl->busy_loop_queue);
|
||||
error_display:
|
||||
if (wl->own_remote_display) {
|
||||
wl_display_disconnect(wl->remote_display);
|
||||
|
|
|
|||
|
|
@ -243,15 +243,24 @@ static struct wl_buffer *import_dmabuf(struct wlr_wl_backend *wl,
|
|||
zwp_linux_buffer_params_v1_add_listener(params, &dmabuf_listener, &data);
|
||||
zwp_linux_buffer_params_v1_create(params, dmabuf->width, dmabuf->height, dmabuf->format, 0);
|
||||
|
||||
struct wl_event_queue *display_queue =
|
||||
wl_proxy_get_queue((struct wl_proxy *)wl->remote_display);
|
||||
wl_proxy_set_queue((struct wl_proxy *)params, wl->busy_loop_queue);
|
||||
|
||||
while (!data.done) {
|
||||
if (wl_display_dispatch(wl->remote_display) < 0) {
|
||||
wlr_log(WLR_ERROR, "wl_display_dispatch() failed");
|
||||
if (wl_display_dispatch_queue(wl->remote_display, wl->busy_loop_queue) < 0) {
|
||||
wlr_log(WLR_ERROR, "wl_display_dispatch_queue() failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct wl_buffer *buffer = data.wl_buffer;
|
||||
if (buffer != NULL) {
|
||||
wl_proxy_set_queue((struct wl_proxy *)buffer, display_queue);
|
||||
}
|
||||
|
||||
zwp_linux_buffer_params_v1_destroy(params);
|
||||
return data.wl_buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static struct wl_buffer *import_shm(struct wlr_wl_backend *wl,
|
||||
|
|
@ -747,13 +756,25 @@ static bool output_commit(struct wlr_output *wlr_output, const struct wlr_output
|
|||
wl_surface_commit(output->surface);
|
||||
output->initialized = true;
|
||||
|
||||
struct wl_event_queue *display_queue =
|
||||
wl_proxy_get_queue((struct wl_proxy *)wl->remote_display);
|
||||
wl_proxy_set_queue((struct wl_proxy *)output->xdg_surface, wl->busy_loop_queue);
|
||||
wl_proxy_set_queue((struct wl_proxy *)output->xdg_toplevel, wl->busy_loop_queue);
|
||||
|
||||
wl_display_flush(wl->remote_display);
|
||||
while (!output->configured) {
|
||||
if (wl_display_dispatch(wl->remote_display) == -1) {
|
||||
wlr_log(WLR_ERROR, "wl_display_dispatch() failed");
|
||||
return false;
|
||||
if (wl_display_dispatch_queue(wl->remote_display, wl->busy_loop_queue) == -1) {
|
||||
wlr_log(WLR_ERROR, "wl_display_dispatch_queue() failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wl_proxy_set_queue((struct wl_proxy *)output->xdg_surface, display_queue);
|
||||
wl_proxy_set_queue((struct wl_proxy *)output->xdg_toplevel, display_queue);
|
||||
|
||||
if (!output->configured) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
struct wlr_wl_buffer *buffer = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue