Skip to content

Commit

Permalink
fix: smooth resizing on Linux and macOS (#218)
Browse files Browse the repository at this point in the history
* Add ready to present flag

* Add platform checks

---------

Co-authored-by: Wu Yuwei <Wu Yu Wei>
Co-authored-by: Jason Tsai <[email protected]>
  • Loading branch information
wusyong and Jason Tsai authored Nov 6, 2024
1 parent 58fe656 commit 40aea41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1998,6 +2002,7 @@ impl IOCompositor {
}

self.composition_request = CompositionRequest::NoCompositingNecessary;
self.ready_to_present = true;

self.process_animations(true);

Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ impl ApplicationHandler<EventLoopProxyMessage> 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}");
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 40aea41

Please sign in to comment.