From 54ad1a583260662d508f303f5fd5650603ef2a6d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 5 Oct 2018 19:46:07 +1000 Subject: [PATCH] Prevent excessive frame events when we ignore a frame In wlroots, if the compositor doesn't swap the output's buffers in response to a frame event then wlroots would emit a frame event whenever the Wayland event loop becomes idle, and do so repeatedly, because the idle event source is only removed when the buffers are swapped. A proper fix for this is to make wlroots request frames from the backend, but in the interim this patch disables the idle event source if we're ignoring the frame event. This prevents sway from throttling the CPU when mpv displays album art when mpv is using the wayland backend. This also adds a missing call to pixman_region32_fini. --- sway/desktop/output.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index cfb5a710f..a6f984375 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -369,11 +369,20 @@ static void damage_handle_frame(struct wl_listener *listener, void *data) { pixman_region32_t damage; pixman_region32_init(&damage); if (!wlr_output_damage_make_current(output->damage, &needs_swap, &damage)) { + pixman_region32_fini(&damage); return; } if (needs_swap) { output_render(output, &now, &damage); + } else { + // TODO: Remove this once wlroots is changed to schedule frames using + // backends. + output->wlr_output->frame_pending = true; + if (output->wlr_output->idle_frame) { + wl_event_source_remove(output->wlr_output->idle_frame); + output->wlr_output->idle_frame = NULL; + } } pixman_region32_fini(&damage);