From 205b97d5edbca6f24b189b564ec5f7129ba40228 Mon Sep 17 00:00:00 2001 From: Simon B / GrausamkeitEnjoyer / God's Eye View Developer <56446615+DevGev@users.noreply.github.com> Date: Thu, 13 Mar 2025 03:03:46 +0100 Subject: [PATCH] compositing: Move `cursor_pos` member and update it in `update_cursor()` (#35934) Previously a member of IOCompositor, the `cursor_pos` DevicePoint did not reflect the true position of the cursor. This caused flickering on mouse hover, see [issue #35875.] The value of `cursor_pos` within IOCompositor was always (x=0, y=0) regardless of the true cursor position (it was never updated, must be a bug or an oversight?). Moving `cursor_pos` to `ServoRenderer`, updating `cursor_pos` on `dispatch_input_event()`, and storing cursor position in `ServoRenderer` through method `update_cursor()` fixes the flickering previously observed. Signed-off-by: devgev --- components/compositing/compositor.rs | 17 ++++++++++------- components/compositing/webview.rs | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index ffc9f417384..8de9a74427d 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -127,6 +127,9 @@ pub struct ServoRenderer { /// Current mouse cursor. cursor: Cursor, + + /// Current cursor position. + cursor_pos: DevicePoint, } /// NB: Never block on the constellation, because sometimes the constellation blocks on us. @@ -172,9 +175,6 @@ pub struct IOCompositor { /// The coordinates of the native window, its view and the screen. embedder_coordinates: EmbedderCoordinates, - /// Current cursor position. - cursor_pos: DevicePoint, - /// The number of frames pending to receive from WebRender. pending_frames: usize, @@ -382,7 +382,9 @@ impl ServoRenderer { .send_transaction(self.webrender_document, transaction); } - pub(crate) fn update_cursor(&mut self, result: &CompositorHitTestResult) { + pub(crate) fn update_cursor(&mut self, pos: DevicePoint, result: &CompositorHitTestResult) { + self.cursor_pos = pos; + let cursor = match result.cursor { Some(cursor) if cursor != self.cursor => cursor, _ => return, @@ -429,6 +431,7 @@ impl IOCompositor { webxr_main_thread: state.webxr_main_thread, convert_mouse_to_touch, cursor: Cursor::None, + cursor_pos: DevicePoint::new(0.0, 0.0), })), webviews: WebViewManager::default(), embedder_coordinates: window.get_coordinates(), @@ -443,7 +446,6 @@ impl IOCompositor { ready_to_save_state: ReadyState::Unknown, webrender: Some(state.webrender), rendering_context: state.rendering_context, - cursor_pos: DevicePoint::new(0.0, 0.0), pending_frames: 0, last_animation_tick: Instant::now(), }; @@ -598,15 +600,16 @@ impl IOCompositor { CompositorMsg::NewWebRenderFrameReady(_document_id, recomposite_needed) => { self.pending_frames -= 1; + let point: DevicePoint = self.global.borrow().cursor_pos; if recomposite_needed { let details_for_pipeline = |pipeline_id| self.details_for_pipeline(pipeline_id); let result = self .global .borrow() - .hit_test_at_point(self.cursor_pos, details_for_pipeline); + .hit_test_at_point(point, details_for_pipeline); if let Some(result) = result { - self.global.borrow_mut().update_cursor(&result); + self.global.borrow_mut().update_cursor(point, &result); } } diff --git a/components/compositing/webview.rs b/components/compositing/webview.rs index a0989c24b0a..b6f81258205 100644 --- a/components/compositing/webview.rs +++ b/components/compositing/webview.rs @@ -285,7 +285,7 @@ impl WebView { return; }; - self.global.borrow_mut().update_cursor(&result); + self.global.borrow_mut().update_cursor(point, &result); if let Err(error) = self.global