output: don't trigger a frame immediately in schedule_frame

This desynchronizes our rendering loop with the vblank cycle.

In case a compositor doesn't swap buffers but schedules a frame,
emitting a frame event immediately enters a busy-loop.

Instead, ask the backend to send a frame when appropriate. On
Wayland we can just register a frame callback on our surface. On
DRM we can do a no-op pageflip.

Fixes #617
Fixes swaywm/sway#2748
This commit is contained in:
emersion 2018-10-05 16:14:22 +02:00
parent 4e89a21397
commit ba91422747
4 changed files with 63 additions and 3 deletions

View file

@ -192,11 +192,24 @@ void update_wl_output_cursor(struct wlr_wl_output *output) {
}
}
bool output_move_cursor(struct wlr_output *_output, int x, int y) {
static bool output_move_cursor(struct wlr_output *_output, int x, int y) {
// TODO: only return true if x == current x and y == current y
return true;
}
static void output_schedule_frame(struct wlr_output *wlr_output) {
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
if (output->frame_callback != NULL) {
wlr_log(WLR_ERROR, "Skipping frame scheduling");
return;
}
output->frame_callback = wl_surface_frame(output->surface);
wl_callback_add_listener(output->frame_callback, &frame_listener, output);
wl_surface_commit(output->surface);
}
static const struct wlr_output_impl output_impl = {
.set_custom_mode = output_set_custom_mode,
.transform = output_transform,
@ -205,6 +218,7 @@ static const struct wlr_output_impl output_impl = {
.swap_buffers = output_swap_buffers,
.set_cursor = output_set_cursor,
.move_cursor = output_move_cursor,
.schedule_frame = output_schedule_frame,
};
bool wlr_output_is_wl(struct wlr_output *wlr_output) {