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 <leifminfagel@gmail.com>
This commit is contained in:
Simon B / GrausamkeitEnjoyer / God's Eye View Developer 2025-03-13 03:03:46 +01:00 committed by GitHub
parent 98816b753c
commit 205b97d5ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View file

@ -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);
}
}

View file

@ -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