Invalidate last_primitives on resize in iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2023-04-27 15:45:02 +02:00
parent 38f82ab35f
commit eb1b2bf241
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -15,7 +15,7 @@ pub struct Surface {
window: softbuffer::GraphicsContext,
buffer: Vec<u32>,
clip_mask: tiny_skia::Mask,
last_primitives: Vec<Primitive>,
last_primitives: Option<Vec<Primitive>>,
last_background_color: Color,
}
@ -48,7 +48,7 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
buffer: vec![0; width as usize * height as usize],
clip_mask: tiny_skia::Mask::new(width, height)
.expect("Create clip mask"),
last_primitives: Vec::new(),
last_primitives: None,
last_background_color: Color::BLACK,
}
}
@ -62,8 +62,7 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
surface.buffer.resize((width * height) as usize, 0);
surface.clip_mask =
tiny_skia::Mask::new(width, height).expect("Create clip mask");
surface.last_primitives.clear();
surface.last_primitives = None;
}
fn fetch_information(&self) -> Information {
@ -121,17 +120,20 @@ pub fn present<T: AsRef<str>>(
)
.expect("Create pixel map");
let damage = if surface.last_background_color == background_color {
damage::list(&surface.last_primitives, primitives)
} else {
vec![Rectangle::with_size(viewport.logical_size())]
};
let damage = surface
.last_primitives
.as_deref()
.and_then(|last_primitives| {
(surface.last_background_color == background_color)
.then(|| damage::list(last_primitives, primitives))
})
.unwrap_or_else(|| vec![Rectangle::with_size(viewport.logical_size())]);
if damage.is_empty() {
return Ok(());
}
surface.last_primitives = primitives.to_vec();
surface.last_primitives = Some(primitives.to_vec());
surface.last_background_color = background_color;
let damage = damage::group(damage, scale_factor, physical_size);