pub struct DamageTracker { /* private fields */ }Expand description
Accumulates dirty rectangles across a frame and emits a merged redraw region at frame time.
Two orthogonal states:
- full-damage flag — set by
mark_fullwhen something invalidates the whole viewport. In this state the individual rect list is ignored. - pending rects — added via
add.
merged unions all pending rects into one;
rects exposes the raw list for callers that want
to implement their own coalescing strategy (conservative — keep
small rects, aggressive — union everything, or threshold — fall
back to full viewport when dirty area exceeds N% of total).
Implementations§
Source§impl DamageTracker
impl DamageTracker
Sourcepub const fn with_full_damage() -> Self
pub const fn with_full_damage() -> Self
New tracker pre-flagged for full-viewport damage. Useful on startup or after a window resize.
Sourcepub fn add(&mut self, rect: DamageRect)
pub fn add(&mut self, rect: DamageRect)
Add a dirty rectangle. Ignored if the full-damage flag is set.
Sourcepub fn has_damage(&self) -> bool
pub fn has_damage(&self) -> bool
Whether there is anything to redraw (full flag or any rects).
Sourcepub fn rects(&self) -> &[DamageRect]
pub fn rects(&self) -> &[DamageRect]
Immutable view of the pending rects (empty if none or if full
flag is set — check is_full first).
Sourcepub fn merged(&self) -> Option<DamageRect>
pub fn merged(&self) -> Option<DamageRect>
Union of all pending rects, or None if the full flag is set or
there are no rects.
When the full flag is set, returns None — the caller should
consult is_full and render the whole viewport.
The library doesn’t know the viewport size so it cannot produce
the full-viewport rect on your behalf.
Sourcepub fn area_upper_bound(&self) -> f32
pub fn area_upper_bound(&self) -> f32
Sum of the individual rect areas. Over-counts overlap — if
rects A and B overlap by area X, the returned value is
area(A) + area(B) which double-counts X.
Use this as a cheap upper bound when deciding whether to fall back to full viewport redraw via a threshold.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the pending rect list is empty. Note: can return true
while is_full also returns true — use
has_damage for “anything to redraw”.
Trait Implementations§
Source§impl Clone for DamageTracker
impl Clone for DamageTracker
Source§fn clone(&self) -> DamageTracker
fn clone(&self) -> DamageTracker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more