Skip to main content

DamageTracker

Struct DamageTracker 

Source
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_full when 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

Source

pub const fn new() -> Self

New empty tracker. Initial state: no damage.

Source

pub const fn with_full_damage() -> Self

New tracker pre-flagged for full-viewport damage. Useful on startup or after a window resize.

Source

pub fn add(&mut self, rect: DamageRect)

Add a dirty rectangle. Ignored if the full-damage flag is set.

Source

pub fn mark_full(&mut self)

Mark the entire viewport as dirty; clears individual rects.

Source

pub fn clear(&mut self)

Reset to no-damage state.

Source

pub fn is_full(&self) -> bool

Whether the full-damage flag is set.

Source

pub fn has_damage(&self) -> bool

Whether there is anything to redraw (full flag or any rects).

Source

pub fn rects(&self) -> &[DamageRect]

Immutable view of the pending rects (empty if none or if full flag is set — check is_full first).

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Number of pending rects (zero if full flag is set).

Source

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

Source§

fn clone(&self) -> DamageTracker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DamageTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DamageTracker

Source§

fn default() -> DamageTracker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.