Skip to content

Commit

Permalink
anvil/udev: Dynamic support for pixman rendererer
Browse files Browse the repository at this point in the history
The `RendererRef` and `Texture` enums provide one way to abstract over
different renderers.

This splits `FpsElement` into a seperate `Fps` that isn't a render
element, and isn't specific to one renderer/texture type.
  • Loading branch information
ids1024 committed Dec 7, 2024
1 parent c3ffa32 commit af7e077
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 119 deletions.
35 changes: 27 additions & 8 deletions anvil/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,28 @@ where
pub static FPS_NUMBERS_PNG: &[u8] = include_bytes!("../resources/numbers.png");

#[cfg(feature = "debug")]
#[derive(Debug, Clone)]
pub struct FpsElement<T: Texture> {
#[derive(Debug)]
pub struct Fps {
id: Id,
fps: fps_ticker::Fps,
value: u32,
texture: T,
commit_counter: CommitCounter,
}

#[cfg(feature = "debug")]
impl<T: Texture> FpsElement<T> {
pub fn new(texture: T) -> Self {
FpsElement {
impl Default for Fps {
fn default() -> Self {
Self {
id: Id::new(),
texture,
fps: fps_ticker::Fps::default(),
value: 0,
commit_counter: CommitCounter::default(),
}
}
}

#[cfg(feature = "debug")]
impl Fps {
pub fn tick(&mut self) {
self.fps.tick();
let value = self.fps.avg().round() as u32;
Expand All @@ -152,6 +153,24 @@ impl<T: Texture> FpsElement<T> {
self.commit_counter.increment();
}
}

pub fn render_element<T: Texture>(&self, texture: T) -> FpsElement<T> {
FpsElement {
id: self.id.clone(),
value: self.value,
commit_counter: self.commit_counter,
texture,
}
}
}

#[cfg(feature = "debug")]
#[derive(Debug)]
pub struct FpsElement<T: Texture> {
id: Id,
value: u32,
commit_counter: CommitCounter,
texture: T,
}

#[cfg(feature = "debug")]
Expand Down Expand Up @@ -198,7 +217,7 @@ where
impl<R> RenderElement<R> for FpsElement<<R as Renderer>::TextureId>
where
R: Renderer + ImportAll,
<R as Renderer>::TextureId: 'static,
<R as Renderer>::TextureId: Send + 'static,
{
fn draw(
&self,
Expand Down
8 changes: 5 additions & 3 deletions anvil/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use crate::{

smithay::backend::renderer::element::render_elements! {
pub CustomRenderElements<R> where
R: ImportAll + ImportMem;
R: ImportAll + ImportMem,
<R as Renderer>::TextureId: Send;
Pointer=PointerRenderElement<R>,
Surface=WaylandSurfaceRenderElement<R>,
#[cfg(feature = "debug")]
Expand All @@ -51,7 +52,8 @@ impl<R: Renderer> std::fmt::Debug for CustomRenderElements<R> {
}

smithay::backend::renderer::element::render_elements! {
pub OutputRenderElements<R, E> where R: ImportAll + ImportMem;
pub OutputRenderElements<R, E> where R: ImportAll + ImportMem,
<R as Renderer>::TextureId: Send;
Space=SpaceRenderElements<R, E>,
Window=Wrap<E>,
Custom=CustomRenderElements<R>,
Expand Down Expand Up @@ -201,7 +203,7 @@ pub fn render_output<'a, 'd, R>(
) -> Result<RenderOutputResult<'d>, OutputDamageTrackerError<R>>
where
R: Renderer + ImportAll + ImportMem,
R::TextureId: Clone + 'static,
R::TextureId: Clone + Send + 'static,
{
let (elements, clear_color) =
output_elements(output, space, custom_elements, renderer, show_window_preview);
Expand Down
Loading

0 comments on commit af7e077

Please sign in to comment.