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.
This commit is contained in:
Ryan Dwyer 2018-10-05 19:46:07 +10:00
parent c1f09939ae
commit 54ad1a5832

View file

@ -369,11 +369,20 @@ static void damage_handle_frame(struct wl_listener *listener, void *data) {
pixman_region32_t damage; pixman_region32_t damage;
pixman_region32_init(&damage); pixman_region32_init(&damage);
if (!wlr_output_damage_make_current(output->damage, &needs_swap, &damage)) { if (!wlr_output_damage_make_current(output->damage, &needs_swap, &damage)) {
pixman_region32_fini(&damage);
return; return;
} }
if (needs_swap) { if (needs_swap) {
output_render(output, &now, &damage); 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); pixman_region32_fini(&damage);