From aab4307d83b3af50c955e9fbb626ce5e3b07a707 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 5 Dec 2024 15:18:14 -0800 Subject: [PATCH] Anvil FPS texture Compiles, should work. Consider best way to abstract renderes, textures. --- anvil/src/drawing.rs | 30 +++++++++++++++++++++++------- anvil/src/udev.rs | 32 +++++++++++++++++++++++++------- anvil/src/winit.rs | 6 +++--- anvil/src/x11.rs | 6 +++--- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/anvil/src/drawing.rs b/anvil/src/drawing.rs index ac0d3ed02064..c94835c6cb53 100644 --- a/anvil/src/drawing.rs +++ b/anvil/src/drawing.rs @@ -123,21 +123,19 @@ where pub static FPS_NUMBERS_PNG: &[u8] = include_bytes!("../resources/numbers.png"); #[cfg(feature = "debug")] -#[derive(Debug, Clone)] -pub struct FpsElement { +#[derive(Debug)] +pub struct Fps { id: Id, fps: fps_ticker::Fps, value: u32, - texture: T, commit_counter: CommitCounter, } #[cfg(feature = "debug")] -impl FpsElement { - pub fn new(texture: T) -> Self { - FpsElement { +impl Fps { + pub fn new() -> Self { + Fps { id: Id::new(), - texture, fps: fps_ticker::Fps::default(), value: 0, commit_counter: CommitCounter::default(), @@ -152,6 +150,24 @@ impl FpsElement { self.commit_counter.increment(); } } + + pub fn render_element(&self, texture: T) -> FpsElement { + FpsElement { + id: self.id.clone(), + value: self.value, + commit_counter: self.commit_counter, + texture, + } + } +} + +#[cfg(feature = "debug")] +#[derive(Debug)] +pub struct FpsElement { + id: Id, + value: u32, + commit_counter: CommitCounter, + texture: T, } #[cfg(feature = "debug")] diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 49bc642651e3..2cc73998b93a 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -463,7 +463,7 @@ pub fn run_udev() { for backend in state.backend_data.backends.values_mut() { for surface in backend.surfaces.values_mut() { - surface.fps_element = Some(FpsElement::new(fps_texture.clone())); + surface.fps = Fps::new(); } } state.backend_data.fps_texture = Some(fps_texture); @@ -824,7 +824,7 @@ struct SurfaceData { global: Option, compositor: SurfaceComposition, #[cfg(feature = "debug")] - fps_element: Option>, + fps: Fps, dmabuf_feedback: Option, } @@ -1102,7 +1102,7 @@ impl AnvilState { }); #[cfg(feature = "debug")] - let fps_element = self.backend_data.fps_texture.clone().map(FpsElement::new); + let fps = Fps::new(); let allocator = GbmAllocator::new( device.gbm.clone(), @@ -1189,7 +1189,7 @@ impl AnvilState { global: Some(global), compositor, #[cfg(feature = "debug")] - fps_element, + fps, dmabuf_feedback, }; @@ -1568,6 +1568,14 @@ impl AnvilState { &self.dnd_icon, &mut self.cursor_status, self.show_window_preview, + #[cfg(feature = "debug")] + self.backend_data.fps_texture.clone().map(|texture| { + if let Texture::Multi(texture) = texture { + texture + } else { + panic!("Invalid texture for renderer") + } + }), ), RendererRef::Pixman(renderer) => render_surface::<_, PixmanRenderBuffer>( surface, @@ -1580,6 +1588,14 @@ impl AnvilState { &self.dnd_icon, &mut self.cursor_status, self.show_window_preview, + #[cfg(feature = "debug")] + self.backend_data.fps_texture.clone().map(|texture| { + if let Texture::Pixman(texture) = texture { + texture + } else { + panic!("Invalid texture for renderer") + } + }), ), }; let reschedule = match result { @@ -1697,6 +1713,7 @@ fn render_surface<'a, R, Target>( dnd_icon: &Option, cursor_status: &mut CursorImageStatus, show_window_preview: bool, + #[cfg(feature = "debug")] fps_texture: Option, ) -> Result<(bool, RenderElementStates), SwapBuffersError> where R: Renderer @@ -1779,10 +1796,11 @@ where } #[cfg(feature = "debug")] - if let Some(element) = surface.fps_element.as_mut() { - custom_elements.push(CustomRenderElements::Fps(element.clone())); - element.tick(); + if let Some(texture) = fps_texture { + custom_elements.push(CustomRenderElements::Fps(surface.fps.render_element(texture))); } + #[cfg(feature = "debug")] + surface.fps.tick(); let (elements, clear_color) = output_elements(output, space, custom_elements, renderer, show_window_preview); diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 57e24f5614ae..a8b944af005c 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -139,7 +139,7 @@ pub fn run_winit() { ) .expect("Unable to upload FPS texture"); #[cfg(feature = "debug")] - let mut fps_element = FpsElement::new(fps_texture); + let mut fps = Fps::new(); let render_node = EGLDevice::device_for_display(backend.renderer().egl_context().display()) .and_then(|device| device.try_get_render_node()); @@ -337,7 +337,7 @@ pub fn run_winit() { } #[cfg(feature = "debug")] - elements.push(CustomRenderElements::Fps(fps_element.clone())); + elements.push(CustomRenderElements::Fps(fps.render_element(fps_texture.clone()))); render_output( &output, @@ -439,6 +439,6 @@ pub fn run_winit() { } #[cfg(feature = "debug")] - fps_element.tick(); + fps.tick(); } } diff --git a/anvil/src/x11.rs b/anvil/src/x11.rs index c3b4f092455c..b11c8dd32a0b 100644 --- a/anvil/src/x11.rs +++ b/anvil/src/x11.rs @@ -217,7 +217,7 @@ pub fn run_x11() { ) .expect("Unable to upload FPS texture"); #[cfg(feature = "debug")] - let mut fps_element = FpsElement::new(fps_texture); + let mut fps = Fps::new(); let output = Output::new( OUTPUT_NAME.to_string(), PhysicalProperties { @@ -378,7 +378,7 @@ pub fn run_x11() { } #[cfg(feature = "debug")] - elements.push(CustomRenderElements::Fps(fps_element.clone())); + elements.push(CustomRenderElements::Fps(fps.render_element(fps_texture.clone()))); let render_res = render_output( &output, @@ -456,7 +456,7 @@ pub fn run_x11() { } #[cfg(feature = "debug")] - fps_element.tick(); + fps.tick(); window.set_cursor_visible(cursor_visible); profiling::finish_frame!(); }