render: only update fps counter when we need it
This commit is contained in:
parent
e9bbdd13c2
commit
5c2fa005c7
@ -54,7 +54,8 @@ pub struct Renderer<T: Output, S: Surfaces> {
|
|||||||
surfaces: S,
|
surfaces: S,
|
||||||
fps: RealTimeRunningAverage<u32>,
|
fps: RealTimeRunningAverage<u32>,
|
||||||
fps_display: Periodically,
|
fps_display: Periodically,
|
||||||
frame: usize
|
frame: usize,
|
||||||
|
frame_count: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Output, S: Surfaces> Renderer<T, S> {
|
impl<T: Output, S: Surfaces> Renderer<T, S> {
|
||||||
@ -64,7 +65,8 @@ impl<T: Output, S: Surfaces> Renderer<T, S> {
|
|||||||
surfaces: surfaces,
|
surfaces: surfaces,
|
||||||
fps: RealTimeRunningAverage::default(),
|
fps: RealTimeRunningAverage::default(),
|
||||||
fps_display: Periodically::new_every_n_seconds(5),
|
fps_display: Periodically::new_every_n_seconds(5),
|
||||||
frame: 0
|
frame: 0,
|
||||||
|
frame_count: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,10 +83,12 @@ impl<T: Output, S: Surfaces> Task for Renderer<T, S> {
|
|||||||
|
|
||||||
self.output.commit();
|
self.output.commit();
|
||||||
|
|
||||||
self.fps.insert(1);
|
|
||||||
self.frame += 1;
|
self.frame += 1;
|
||||||
self.fps_display.run(|| {
|
self.fps_display.run(|| {
|
||||||
log::info!("FPS: {}", self.fps.measurement());
|
self.fps.insert((self.frame - self.frame_count) as u32);
|
||||||
|
self.frame_count = self.frame;
|
||||||
|
let fps = self.fps.measurement();
|
||||||
|
bus.push(Event::new_property_change("output.fps", fps.rate() as u32));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
_ => self.output.on_event(event)
|
_ => self.output.on_event(event)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user