16 float x = 0,
y = 0,
w = 0,
h = 0;
19 return x < other.x + other.w &&
x +
w > other.x &&
20 y < other.y + other.h &&
y +
h > other.y;
25 float nx = std::min(
x, other.x);
26 float ny = std::min(
y, other.y);
28 std::max(
x +
w, other.x + other.w) - nx,
29 std::max(
y +
h, other.y + other.h) - ny};
37 if (rect.
w <= 0 || rect.
h <= 0)
return;
38 dirty_rects_.push_back(rect);
54 bool is_dirty()
const {
return full_repaint_ || !dirty_rects_.empty(); }
60 const std::vector<Rect>&
dirty_rects()
const {
return dirty_rects_; }
66 full_repaint_ =
false;
72 if (dirty_rects_.empty())
return {};
73 Rect b = dirty_rects_[0];
74 for (
size_t i = 1; i < dirty_rects_.size(); ++i)
75 b = b.merged(dirty_rects_[i]);
81 void set_viewport(
float width,
float height,
float full_repaint_threshold = 0.6f) {
84 full_repaint_threshold_ = full_repaint_threshold;
95 void coalesce_if_needed() {
97 if (dirty_rects_.size() > max_rects_) {
102 if (viewport_w_ > 0 && viewport_h_ > 0) {
103 float total_area = 0;
104 for (
auto& r : dirty_rects_) total_area += r.area();
105 if (total_area > viewport_w_ * viewport_h_ * full_repaint_threshold_) {
116 for (
size_t i = 0;
i < dirty_rects_.size(); ++
i) {
117 for (
size_t j = i + 1;
j < dirty_rects_.size(); ++
j) {
118 auto combined = dirty_rects_[
i].merged(dirty_rects_[j]);
120 float sum_area = dirty_rects_[
i].area() + dirty_rects_[
j].area();
121 if (combined.area() < sum_area * 1.5f ||
122 dirty_rects_[i].intersects(dirty_rects_[j])) {
123 dirty_rects_[
i] = combined;
124 dirty_rects_.erase(dirty_rects_.begin() +
static_cast<long>(j));
134 std::vector<Rect> dirty_rects_;
135 bool full_repaint_ =
true;
136 bool debug_overlay_ =
false;
137 float viewport_w_ = 0;
138 float viewport_h_ = 0;
139 float full_repaint_threshold_ = 0.6f;
140 uint64_t frame_count_ = 0;
141 static constexpr size_t max_rects_ = 16;
Tracks rectangular regions that need repainting.
Definition dirty_tracker.hpp:13
void set_viewport(float width, float height, float full_repaint_threshold=0.6f)
Set the viewport size.
Definition dirty_tracker.hpp:81
Rect bounds() const
Get the bounding rect of all dirty regions (for partial repaints).
Definition dirty_tracker.hpp:71
bool needs_full_repaint() const
Returns true if the entire viewport needs repainting.
Definition dirty_tracker.hpp:57
uint64_t frame_count() const
Frame counter for multi-frame history tracking.
Definition dirty_tracker.hpp:92
const std::vector< Rect > & dirty_rects() const
Get the list of dirty rectangles (empty if full repaint).
Definition dirty_tracker.hpp:60
void invalidate_all()
Mark the entire viewport as dirty (forces full repaint).
Definition dirty_tracker.hpp:48
void set_debug_overlay(bool enabled)
Enable/disable debug overlay (draws dirty regions with colored flash).
Definition dirty_tracker.hpp:88
void invalidate(const Rect &rect)
Mark a rectangular region as needing repaint.
Definition dirty_tracker.hpp:36
bool debug_overlay() const
Definition dirty_tracker.hpp:89
bool is_dirty() const
Returns true if any region needs repainting.
Definition dirty_tracker.hpp:54
void invalidate(float x, float y, float w, float h)
Mark a rectangular region as needing repaint (convenience overload).
Definition dirty_tracker.hpp:43
void clear()
Clear all dirty state after a frame has been painted.
Definition dirty_tracker.hpp:64
Definition gpu_fwd.hpp:31
@ i
Definition formant_filter_bank.hpp:20
@ j
Definition input_events.hpp:40
Definition dirty_tracker.hpp:15
Rect merged(const Rect &other) const
Merge two rects into their bounding box.
Definition dirty_tracker.hpp:24
bool intersects(const Rect &other) const
Definition dirty_tracker.hpp:18
float area() const
Definition dirty_tracker.hpp:32
float x
Definition dirty_tracker.hpp:16
float y
Definition dirty_tracker.hpp:16
float h
Definition dirty_tracker.hpp:16
float w
Definition dirty_tracker.hpp:16