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: remove instant repain method when resizing #212

Merged
merged 2 commits into from
Oct 29, 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
41 changes: 7 additions & 34 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,14 +1225,13 @@ impl IOCompositor {
}
}

/// Resize the rendering context and all web views. Return true if the compositor should repaint and present
/// after this.
pub fn resize(&mut self, size: Size2D<i32, DevicePixel>, window: &mut Window) -> bool {
/// Resize the rendering context and all web views.
pub fn resize(&mut self, size: Size2D<i32, DevicePixel>, window: &mut Window) {
if size.height == 0 || size.width == 0 {
return false;
return;
}

let need_resize = self.on_resize_window_event(size, window);
self.on_resize_window_event(size, window);

if let Some(panel) = &mut window.panel {
let rect = DeviceIntRect::from_size(size);
Expand All @@ -1248,14 +1247,12 @@ impl IOCompositor {
}

self.send_root_pipeline_display_list(window);
need_resize
}

/// Handle the window resize event and return a boolean to tell embedder if it should further
/// handle the resize event.
pub fn on_resize_window_event(&mut self, new_viewport: DeviceIntSize, window: &Window) -> bool {
/// Handle the window resize event.
pub fn on_resize_window_event(&mut self, new_viewport: DeviceIntSize, window: &Window) {
if self.shutdown_state != ShutdownState::NotShuttingDown {
return false;
return;
}

let _ = self
Expand All @@ -1267,7 +1264,6 @@ impl IOCompositor {
self.webrender_api
.send_transaction(self.webrender_document, transaction);
self.composite_if_necessary(CompositingReason::Resize);
true
}

/// Handle the window scale factor event and return a boolean to tell embedder if it should further
Expand Down Expand Up @@ -2099,29 +2095,6 @@ impl IOCompositor {
}
self.shutdown_state != ShutdownState::FinishedShuttingDown
}
/// Repaints and recomposites synchronously. You must be careful when calling this, as if a
/// paint is not scheduled the compositor will hang forever.
///
/// This is used when resizing the window.
pub fn repaint_synchronously(&mut self, windows: &mut HashMap<WindowId, (Window, DocumentId)>) {
while self.shutdown_state != ShutdownState::ShuttingDown {
let msg = self.port.recv_compositor_msg();
let need_recomposite = matches!(msg, CompositorMsg::NewWebRenderFrameReady(..));
let keep_going = self.handle_browser_message(msg, windows);
if need_recomposite {
if let Some((window, _)) = windows.get(&self.current_window) {
self.composite(window);
if let Err(err) = self.rendering_context.present(&window.surface) {
log::warn!("Failed to present surface: {:?}", err);
}
}
break;
}
if !keep_going {
break;
}
}
}

fn pinch_zoom_level(&self) -> Scale<f32, DevicePixel, DevicePixel> {
Scale::new(self.viewport_zoom.get())
Expand Down
16 changes: 4 additions & 12 deletions src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,10 @@ impl Verso {
if let WindowEvent::CloseRequested = event {
// self.windows.remove(&window_id);
compositor.maybe_start_shutting_down();
} else {
let need_repaint = match self.windows.get_mut(&window_id) {
Some(window) => window.0.handle_winit_window_event(
&self.constellation_sender,
compositor,
&event,
),
None => false,
};
if need_repaint {
compositor.repaint_synchronously(&mut self.windows);
}
} else if let Some(window) = self.windows.get_mut(&window_id) {
window
.0
.handle_winit_window_event(&self.constellation_sender, compositor, &event);
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Window {
sender: &Sender<ConstellationMsg>,
compositor: &mut IOCompositor,
event: &winit::event::WindowEvent,
) -> bool {
) {
match event {
WindowEvent::RedrawRequested => {
if let Err(err) = compositor.rendering_context.present(&self.surface) {
Expand All @@ -191,7 +191,7 @@ impl Window {
}
WindowEvent::Resized(size) => {
let size = Size2D::new(size.width, size.height);
return compositor.resize(size.to_i32(), self);
compositor.resize(size.to_i32(), self);
}
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
compositor.on_scale_factor_event(*scale_factor as f32, self);
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Window {
Some(position) => Point2D::new(position.x as f32, position.y as f32),
None => {
log::trace!("Mouse position is None, skipping MouseInput event.");
return false;
return;
}
};

Expand All @@ -244,7 +244,7 @@ impl Window {
log::trace!(
"Verso Window isn't supporting this mouse button yet: {button:?}"
);
return false;
return;
}
};

Expand All @@ -268,7 +268,7 @@ impl Window {
Some(position) => position,
None => {
log::trace!("Mouse position is None, skipping MouseWheel event.");
return false;
return;
}
};

Expand Down Expand Up @@ -321,7 +321,6 @@ impl Window {
}
e => log::trace!("Verso Window isn't supporting this window event yet: {e:?}"),
}
false
}

/// Handle servo messages. Return true if it requests a new window
Expand Down