Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: smooth resizing on Linux and macOS #218

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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