From bc1da86bb032f0b6f455c7d22603ddf54094ce78 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sun, 3 Sep 2023 14:31:32 +0200 Subject: [PATCH] wayland: fix presentation time refresh The refresh represents the time till the next vblank relative to the timestamp and not the mode refresh --- anvil/src/udev.rs | 2 +- anvil/src/winit.rs | 2 +- anvil/src/x11.rs | 2 +- src/desktop/wayland/utils.rs | 6 ++++-- src/wayland/presentation/mod.rs | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index cfcfc818157c..1c8ef36a60de 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -1148,7 +1148,7 @@ impl AnvilState { clock, output .current_mode() - .map(|mode| mode.refresh as u32) + .map(|mode| Duration::from_secs_f64(1_000f64 / mode.refresh as f64)) .unwrap_or_default(), seq as u64, flags, diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index b32d865a138c..68ce466c1947 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -391,7 +391,7 @@ pub fn run_winit() { time, output .current_mode() - .map(|mode| mode.refresh as u32) + .map(|mode| Duration::from_secs_f64(1_000f64 / mode.refresh as f64)) .unwrap_or_default(), 0, wp_presentation_feedback::Kind::Vsync, diff --git a/anvil/src/x11.rs b/anvil/src/x11.rs index d43578b189d9..80672134ebbd 100644 --- a/anvil/src/x11.rs +++ b/anvil/src/x11.rs @@ -442,7 +442,7 @@ pub fn run_x11() { time, output .current_mode() - .map(|mode| mode.refresh as u32) + .map(|mode| Duration::from_secs_f64(1_000f64 / mode.refresh as f64)) .unwrap_or_default(), 0, wp_presentation_feedback::Kind::Vsync, diff --git a/src/desktop/wayland/utils.rs b/src/desktop/wayland/utils.rs index 4cece3c3b278..a8efe022f1e3 100644 --- a/src/desktop/wayland/utils.rs +++ b/src/desktop/wayland/utils.rs @@ -331,11 +331,12 @@ impl SurfacePresentationFeedback { output: &Output, clk_id: u32, time: impl Into, - refresh: u32, + refresh: impl Into, seq: u64, flags: wp_presentation_feedback::Kind, ) { let time = time.into(); + let refresh = refresh.into(); for callback in self.callbacks.drain(..) { if callback.clk_id() == clk_id { @@ -392,7 +393,7 @@ impl OutputPresentationFeedback { pub fn presented( &mut self, time: T, - refresh: u32, + refresh: impl Into, seq: u64, flags: wp_presentation_feedback::Kind, ) where @@ -400,6 +401,7 @@ impl OutputPresentationFeedback { Kind: crate::utils::NonNegativeClockSource, { let time = time.into(); + let refresh = refresh.into(); let clk_id = Kind::id() as u32; if let Some(output) = self.output.upgrade() { for mut callback in self.callbacks.drain(..) { diff --git a/src/wayland/presentation/mod.rs b/src/wayland/presentation/mod.rs index 4f1d79c2ff64..139ea89765e1 100644 --- a/src/wayland/presentation/mod.rs +++ b/src/wayland/presentation/mod.rs @@ -206,7 +206,7 @@ impl PresentationFeedbackCallback { self, output: &Output, time: impl Into, - refresh: u32, + refresh: impl Into, seq: u64, flags: wp_presentation_feedback::Kind, ) { @@ -236,6 +236,7 @@ impl PresentationFeedbackCallback { let tv_sec_hi = (time.as_secs() >> 32) as u32; let tv_sec_lo = (time.as_secs() & 0xFFFFFFFF) as u32; let tv_nsec = time.subsec_nanos(); + let refresh = refresh.into().as_nanos() as u32; let seq_hi = (seq >> 32) as u32; let seq_lo = (seq & 0xFFFFFFFF) as u32;