diff --git a/src/compositor.rs b/src/compositor.rs index 97231ec9..27689b40 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -140,6 +140,9 @@ pub struct IOCompositor { /// Tracks whether we should composite this frame. composition_request: CompositionRequest, + /// check if the surface is ready to present. + pub ready_to_present: bool, + /// Tracks whether we are in the process of shutting down, or have shut down and should close /// the compositor. pub shutdown_state: ShutdownState, @@ -382,6 +385,7 @@ impl IOCompositor { pending_frames: 0, last_animation_tick: Instant::now(), is_animating: false, + ready_to_present: false, }; // Make sure the GL state is OK @@ -1998,6 +2002,7 @@ impl IOCompositor { } self.composition_request = CompositionRequest::NoCompositingNecessary; + self.ready_to_present = true; self.process_animations(true); diff --git a/src/main.rs b/src/main.rs index 50a2ddf8..1bf4c691 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,13 +21,20 @@ impl ApplicationHandler for App { fn window_event( &mut self, - event_loop: &winit::event_loop::ActiveEventLoop, + _event_loop: &winit::event_loop::ActiveEventLoop, window_id: winit::window::WindowId, event: winit::event::WindowEvent, ) { if let Some(v) = self.verso.as_mut() { v.handle_winit_window_event(window_id, event); - v.handle_servo_messages(event_loop); + // XXX: Windows seems to be able to handle servo directly. + // We can think about how to handle all platforms the same way in the future. + #[cfg(windows)] + v.handle_servo_messages(_event_loop); + #[cfg(not(windows))] + if let Err(e) = self.proxy.send_event(EventLoopProxyMessage::Wake) { + log::error!("Failed to send wake message to Verso: {e}"); + } } } diff --git a/src/window.rs b/src/window.rs index fb336586..a6b809b5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -199,8 +199,11 @@ impl Window { ) { match event { WindowEvent::RedrawRequested => { - if let Err(err) = compositor.rendering_context.present(&self.surface) { - log::warn!("Failed to present surface: {:?}", err); + if compositor.ready_to_present { + if let Err(err) = compositor.rendering_context.present(&self.surface) { + log::warn!("Failed to present surface: {:?}", err); + } + compositor.ready_to_present = false; } } WindowEvent::Focused(focused) => {