diff --git a/anvil/src/drawing.rs b/anvil/src/drawing.rs index 0fa62201ed02..cd62d454b675 100644 --- a/anvil/src/drawing.rs +++ b/anvil/src/drawing.rs @@ -126,6 +126,7 @@ pub static FPS_NUMBERS_PNG: &[u8] = include_bytes!("../resources/numbers.png"); #[derive(Debug, Clone)] pub struct FpsElement { id: Id, + fps: fps_ticker::Fps, value: u32, texture: T, commit_counter: CommitCounter, @@ -137,14 +138,17 @@ impl FpsElement { FpsElement { id: Id::new(), texture, + fps: fps_ticker::Fps::default(), value: 0, commit_counter: CommitCounter::default(), } } - pub fn update_fps(&mut self, fps: u32) { - if self.value != fps { - self.value = fps; + pub fn tick(&mut self) { + self.fps.tick(); + let value = self.fps.avg().round() as u32; + if self.value != value { + self.value = value; self.commit_counter.increment(); } } diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 58e6e9f9da99..b482527f6e3f 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -754,8 +754,6 @@ struct SurfaceData { global: Option, compositor: SurfaceComposition, #[cfg(feature = "debug")] - fps: fps_ticker::Fps, - #[cfg(feature = "debug")] fps_element: Option>, dmabuf_feedback: Option, } @@ -1109,8 +1107,6 @@ impl AnvilState { global: Some(global), compositor, #[cfg(feature = "debug")] - fps: fps_ticker::Fps::default(), - #[cfg(feature = "debug")] fps_element, dmabuf_feedback, }; @@ -1681,9 +1677,8 @@ fn render_surface<'a>( #[cfg(feature = "debug")] if let Some(element) = surface.fps_element.as_mut() { - element.update_fps(surface.fps.avg().round() as u32); - surface.fps.tick(); custom_elements.push(CustomRenderElements::Fps(element.clone())); + element.tick(); } let (elements, clear_color) = diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index f2ca111966ed..57e24f5614ae 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -57,8 +57,6 @@ pub struct WinitData { damage_tracker: OutputDamageTracker, dmabuf_state: (DmabufState, DmabufGlobal, Option), full_redraw: u8, - #[cfg(feature = "debug")] - pub fps: fps_ticker::Fps, } impl DmabufHandler for AnvilState { @@ -194,8 +192,6 @@ pub fn run_winit() { damage_tracker, dmabuf_state, full_redraw: 0, - #[cfg(feature = "debug")] - fps: fps_ticker::Fps::default(), } }; let mut state = AnvilState::init(display, event_loop.handle(), data, true); @@ -259,11 +255,6 @@ pub fn run_winit() { pointer_element.set_status(state.cursor_status.clone()); - #[cfg(feature = "debug")] - let fps = state.backend_data.fps.avg().round() as u32; - #[cfg(feature = "debug")] - fps_element.update_fps(fps); - let full_redraw = &mut state.backend_data.full_redraw; *full_redraw = full_redraw.saturating_sub(1); let space = &mut state.space; @@ -448,6 +439,6 @@ pub fn run_winit() { } #[cfg(feature = "debug")] - state.backend_data.fps.tick(); + fps_element.tick(); } } diff --git a/anvil/src/x11.rs b/anvil/src/x11.rs index 50e3ce1c92aa..c3b4f092455c 100644 --- a/anvil/src/x11.rs +++ b/anvil/src/x11.rs @@ -66,8 +66,6 @@ pub struct X11Data { dmabuf_state: DmabufState, _dmabuf_global: DmabufGlobal, _dmabuf_default_feedback: DmabufFeedback, - #[cfg(feature = "debug")] - fps: fps_ticker::Fps, } impl DmabufHandler for AnvilState { @@ -244,8 +242,6 @@ pub fn run_x11() { dmabuf_state, _dmabuf_global: dmabuf_global, _dmabuf_default_feedback: dmabuf_default_feedback, - #[cfg(feature = "debug")] - fps: fps_ticker::Fps::default(), }; let mut state = AnvilState::init(display, event_loop.handle(), data, true); @@ -308,10 +304,6 @@ pub fn run_x11() { let backend_data = &mut state.backend_data; // We need to borrow everything we want to refer to inside the renderer callback otherwise rustc is unhappy. - #[cfg(feature = "debug")] - let fps = backend_data.fps.avg().round() as u32; - #[cfg(feature = "debug")] - fps_element.update_fps(fps); let (buffer, age) = backend_data.surface.buffer().expect("gbm device was destroyed"); if let Err(err) = backend_data.renderer.bind(buffer) { @@ -464,7 +456,7 @@ pub fn run_x11() { } #[cfg(feature = "debug")] - state.backend_data.fps.tick(); + fps_element.tick(); window.set_cursor_visible(cursor_visible); profiling::finish_frame!(); }