From 9955988a07b6716e69165b85a5c6d71d0f970cdc Mon Sep 17 00:00:00 2001 From: "Ngo Iok Ui (Wu Yu Wei)" Date: Tue, 29 Oct 2024 13:46:20 +0900 Subject: [PATCH] Remove instant repain method when resizing (#212) Co-authored-by: Jason Tsai --- src/compositor.rs | 41 +++++++---------------------------------- src/verso.rs | 16 ++++------------ src/window.rs | 11 +++++------ 3 files changed, 16 insertions(+), 52 deletions(-) diff --git a/src/compositor.rs b/src/compositor.rs index f791d90..d641db6 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -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, window: &mut Window) -> bool { + /// Resize the rendering context and all web views. + pub fn resize(&mut self, size: Size2D, 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); @@ -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 @@ -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 @@ -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) { - 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 { Scale::new(self.viewport_zoom.get()) diff --git a/src/verso.rs b/src/verso.rs index 3a43ead..87a1cc3 100644 --- a/src/verso.rs +++ b/src/verso.rs @@ -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); } } } diff --git a/src/window.rs b/src/window.rs index d0a7b68..b94b8a3 100644 --- a/src/window.rs +++ b/src/window.rs @@ -177,7 +177,7 @@ impl Window { sender: &Sender, compositor: &mut IOCompositor, event: &winit::event::WindowEvent, - ) -> bool { + ) { match event { WindowEvent::RedrawRequested => { if let Err(err) = compositor.rendering_context.present(&self.surface) { @@ -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); @@ -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; } }; @@ -244,7 +244,7 @@ impl Window { log::trace!( "Verso Window isn't supporting this mouse button yet: {button:?}" ); - return false; + return; } }; @@ -268,7 +268,7 @@ impl Window { Some(position) => position, None => { log::trace!("Mouse position is None, skipping MouseWheel event."); - return false; + return; } }; @@ -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