Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pending_damage.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <algorithm>
6
7namespace pulp::view {
8
33public:
39 class Snapshot {
40 public:
41 bool is_full() const noexcept { return full_; }
42 bool has_bounds() const noexcept { return have_bounds_; }
43 Rect bounds() const noexcept { return bounds_; }
44
48 bool is_bounded() const noexcept { return !full_ && have_bounds_; }
49
50 private:
51 friend class PendingDamage;
52 bool full_ = true;
53 bool have_bounds_ = false;
54 Rect bounds_{};
55 };
56
58 void mark_full() { full_ = true; }
59
61 void mark(const Rect& root_rect) {
62 if (root_rect.width <= 0 || root_rect.height <= 0) {
63 mark_full(); // degenerate region → be conservative
64 return;
65 }
66 if (full_) return; // sticky: never widen back out of a full repaint
67 if (!have_bounds_) {
68 bounds_ = root_rect;
69 have_bounds_ = true;
70 return;
71 }
72 const float nx = std::min(bounds_.x, root_rect.x);
73 const float ny = std::min(bounds_.y, root_rect.y);
74 bounds_ = {nx, ny,
75 std::max(bounds_.right(), root_rect.right()) - nx,
76 std::max(bounds_.bottom(), root_rect.bottom()) - ny};
77 }
78
79 bool is_full() const { return full_; }
80 bool has_bounds() const { return have_bounds_; }
81 Rect bounds() const { return bounds_; }
82
84 void clear() {
85 full_ = false;
86 have_bounds_ = false;
87 bounds_ = {};
88 }
89
96 Snapshot s;
97 s.full_ = full_;
98 s.have_bounds_ = have_bounds_;
99 s.bounds_ = bounds_;
100 clear();
101 return s;
102 }
103
110 void restore(const Snapshot& s) {
111 if (s.full_) {
112 mark_full();
113 return;
114 }
115 if (s.have_bounds_) mark(s.bounds_);
116 }
117
118private:
119 bool full_ = true;
120 bool have_bounds_ = false;
121 Rect bounds_{};
122};
123
124} // namespace pulp::view
One frame's damage, taken atomically out of a PendingDamage.
Definition pending_damage.hpp:39
Rect bounds() const noexcept
Definition pending_damage.hpp:43
bool is_bounded() const noexcept
True when this snapshot describes a clippable region — bounded damage with a real rect.
Definition pending_damage.hpp:48
bool has_bounds() const noexcept
Definition pending_damage.hpp:42
friend class PendingDamage
Definition pending_damage.hpp:51
bool is_full() const noexcept
Definition pending_damage.hpp:41
Accumulated repaint damage for one frame, in root/window coordinates.
Definition pending_damage.hpp:32
void mark_full()
Whole-surface repaint. Any structural change uses this.
Definition pending_damage.hpp:58
bool has_bounds() const
Definition pending_damage.hpp:80
void clear()
Called by the host once it has painted and submitted the frame.
Definition pending_damage.hpp:84
void restore(const Snapshot &s)
Put a taken snapshot back after a frame failed to reach its output.
Definition pending_damage.hpp:110
Snapshot take()
Read this frame's damage AND clear it, in one step.
Definition pending_damage.hpp:95
Rect bounds() const
Definition pending_damage.hpp:81
void mark(const Rect &root_rect)
Union a bounded region (root coords) into this frame's damage.
Definition pending_damage.hpp:61
bool is_full() const
Definition pending_damage.hpp:79
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ s
Definition input_events.hpp:41
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52
float x
Definition geometry.hpp:53
constexpr float right() const
Definition geometry.hpp:55
float height
Definition geometry.hpp:53
float width
Definition geometry.hpp:53
float y
Definition geometry.hpp:53
constexpr float bottom() const
Definition geometry.hpp:56