use super::{COPY_AFTER, COPY_HOLD_OFF, Damage, FrameWindow, KeptWindow, Summaries, WindowDamage};
#[derive(Default)]
pub(crate) struct ClearedImages {
pub(crate) kept: KeptWindow,
small_frames: u32,
started: bool,
pub(crate) copied: bool,
}
impl ClearedImages {
pub(crate) fn damage(
&mut self,
summaries: &mut WindowDamage,
frame: &FrameWindow<'_>,
) -> (Damage, bool) {
if !self.started {
self.started = true;
summaries.hold_off(COPY_HOLD_OFF);
}
let damage = summaries.begin_as(frame, &mut self.kept, Summaries::COPIED);
if !matches!(damage, Damage::Part(_)) {
self.small_frames = 0;
return (damage, false);
}
self.small_frames += 1;
let keeps = self.small_frames >= COPY_AFTER;
if keeps {
self.small_frames = 0;
}
(damage, keeps)
}
pub(crate) fn hand_over(&mut self, target: &mut KeptWindow) {
std::mem::swap(&mut self.kept, target);
self.kept.forget();
self.copied = true;
}
pub(crate) fn take_back(&mut self, target: &mut KeptWindow) {
std::mem::swap(&mut self.kept, target);
self.copied = false;
self.small_frames = 0;
}
}