Expand description
Accumulate dirty rectangles and emit minimal redraw regions for partial GPU canvas updates.
Every interactive GPU-rendered app has a choice: redraw the whole frame every tick, or track which regions changed and redraw only those. The first is simple but wastes power; the second is what editors, design tools, terminals, and dashboards actually do.
This crate is the bookkeeping — you call DamageTracker::add when
state changes, and at frame time you ask for the union of pending
regions via DamageTracker::merged. It has no opinion on your
coordinate system, no viewport tracking, and no GPU dependency —
pairs with any 2D renderer (Skia, wgpu, raw Metal, softbuffer).
§Example
use damage_rects::{DamageRect, DamageTracker};
let mut tracker = DamageTracker::new();
// during state updates:
tracker.add(DamageRect::new(10.0, 20.0, 100.0, 30.0)); // a line changed
tracker.add(DamageRect::new(50.0, 30.0, 80.0, 40.0)); // cursor moved
// at frame time:
if let Some(redraw_region) = tracker.merged() {
// render(redraw_region.x, redraw_region.y, redraw_region.width, redraw_region.height)
tracker.clear();
}§Full-damage shortcut
Some events invalidate the whole viewport (window resize, theme
switch). Call DamageTracker::mark_full and subsequent
DamageTracker::merged returns None; consult
DamageTracker::is_full and render the whole viewport in that
case. The flag prevents collecting individual rects you don’t need.
Structs§
- Damage
Rect - An axis-aligned rectangle in
f32space. Coordinate system is up to the caller — the library treatsyas “down” only in the sense thatDamageRect::bottomreturnsy + height. - Damage
Tracker - Accumulates dirty rectangles across a frame and emits a merged redraw region at frame time.