From 0eeca6c2c52b626fc9d4c9ccf22ee72330e2106a Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Tue, 11 Apr 2023 02:10:38 +1000 Subject: [PATCH] fix(wayland): register frame callback then commit (fixes #3468) (#3485) fix(wayland): register frame callback then commit (fixes #3468) Co-authored-by: Wez Furlong --- window/src/os/wayland/window.rs | 37 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 189d3b5ee..db66d7d26 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -801,27 +801,26 @@ impl WaylandWindowInner { } self.invalidated = false; - self.events.dispatch(WindowEvent::NeedRepaint); - if self.gl_state.is_some() { - // Ask the compositor to wake us up when it is time to paint - // the next frame. - // We don't do this when we're using WebGPU because we don't - // always get a timely wakeup. We configure wgpu to use a - // vsync-equivalent PresentMode so we should already be - // respecting the maximum frame rate, making it less critical - // to rely on Wayland's frame scheduling. - // - let window_id = self.window_id; - let callback = self.surface.frame(); - callback.quick_assign(move |_source, _event, _data| { - WaylandConnection::with_window_inner(window_id, |inner| { - inner.next_frame_is_ready(); - Ok(()) - }); + // Ask the compositor to wake us up when its time to paint the next frame, + // note that this only happens _after_ the next commit + let window_id = self.window_id; + let callback = self.surface.frame(); + callback.quick_assign(move |_source, _event, _data| { + WaylandConnection::with_window_inner(window_id, |inner| { + inner.next_frame_is_ready(); + Ok(()) }); - self.frame_callback.replace(callback); - } + }); + self.frame_callback.replace(callback); + + // The repaint has the side of effect of committing the surface, + // which is necessary for the frame callback to get triggered. + // Ordering the repaint after requesting the callback ensures that + // we will get woken at the appropriate time. + // + // + self.events.dispatch(WindowEvent::NeedRepaint); Ok(()) }