Present new frame only when damaged in iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2023-04-05 18:41:40 +02:00
parent 1bba9a080f
commit 4ede482ab5
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 12 additions and 8 deletions

View file

@ -50,7 +50,7 @@ impl Backend {
viewport: &Viewport,
background_color: Color,
overlay: &[T],
) {
) -> bool {
let physical_size = viewport.physical_size();
let damage = if self.last_background_color == background_color
@ -62,7 +62,7 @@ impl Backend {
};
if damage.is_empty() {
return;
return false;
}
self.last_primitives = primitives.to_vec();
@ -179,6 +179,8 @@ impl Backend {
#[cfg(feature = "svg")]
self.vector_pipeline.trim_cache();
true
}
fn draw_primitive(

View file

@ -106,7 +106,7 @@ pub fn present<Theme, T: AsRef<str>>(
) -> Result<(), compositor::SurfaceError> {
let physical_size = viewport.physical_size();
backend.draw(
let drawn = backend.draw(
&mut tiny_skia::PixmapMut::from_bytes(
bytemuck::cast_slice_mut(&mut surface.buffer),
physical_size.width,
@ -120,11 +120,13 @@ pub fn present<Theme, T: AsRef<str>>(
overlay,
);
surface.window.set_buffer(
&surface.buffer,
physical_size.width as u16,
physical_size.height as u16,
);
if drawn {
surface.window.set_buffer(
&surface.buffer,
physical_size.width as u16,
physical_size.height as u16,
);
}
Ok(())
}