Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
host_frame_pump.hpp
Go to the documentation of this file.
1#pragma once
2
63
64#include <atomic>
65#include <cstdint>
66
69
70namespace pulp::view {
71
72class View;
73
80public:
81 static constexpr float kDefaultNominalDt = 1.0f / 60.0f;
82 static constexpr float kDefaultWakeThreshold = 0.25f;
83
92 float measure(double now_seconds);
93
98 void suspend();
99
108 void note_frame_skipped() { skipped_.store(true, std::memory_order_release); }
109
113 void set_nominal_dt(float dt);
114 float nominal_dt() const { return nominal_dt_; }
115
117 void set_wake_threshold(float seconds);
118 float wake_threshold() const { return wake_threshold_; }
119
122 bool suspended() const {
123 return !have_last_ || skipped_.load(std::memory_order_acquire);
124 }
125
127 std::uint64_t resumes() const { return resumes_; }
128
130 double last_timestamp() const { return last_; }
131
132 void reset();
133
134private:
135 double last_ = 0;
136 bool have_last_ = false;
137 float nominal_dt_ = kDefaultNominalDt;
138 float wake_threshold_ = kDefaultWakeThreshold;
139 std::uint64_t resumes_ = 0;
140 // Set on the vsync thread by note_frame_skipped(), consumed on the UI thread
141 // by measure(). The only cross-thread state in the pump.
142 std::atomic<bool> skipped_{false};
143};
144
149 float dt = 0.0f;
152 bool should_render = false;
158 bool continuous = false;
167 bool animating = false;
169 bool resumed = false;
170};
171
192bool should_dispatch_host_frame(HostFramePump& pump, bool needs_repaint,
193 bool continuous, bool has_idle_callback);
194
204 double now_seconds, bool needs_repaint);
205
216void advance_host_frame(View* root, FrameClock& clock, float dt);
217
224inline bool host_frame_composites(const HostFrameTick& tick, bool damaged) noexcept {
225 return damaged || tick.animating;
226}
227
233
234} // namespace pulp::view
Definition frame_clock.hpp:14
Converts a host's monotonic presentation timestamps into per-frame deltas.
Definition host_frame_pump.hpp:79
float wake_threshold() const
Definition host_frame_pump.hpp:118
void set_nominal_dt(float dt)
Nominal frame interval used for the first frame and for resumes.
void suspend()
Tell the pump the host is about to stop pumping frames (idle at 0 fps, display link stopped,...
double last_timestamp() const
Timestamp of the last measured frame (undefined while suspended()).
Definition host_frame_pump.hpp:130
float measure(double now_seconds)
Measure the delta for the frame presented at now_seconds (monotonic, seconds).
bool suspended() const
True while the next measure() would be a resume (before the first frame, after suspend(),...
Definition host_frame_pump.hpp:122
std::uint64_t resumes() const
Number of resumes so far, first frame included. Observability + tests.
Definition host_frame_pump.hpp:127
void set_wake_threshold(float seconds)
Gap above which a frame is treated as a resume rather than a slow frame.
float nominal_dt() const
Definition host_frame_pump.hpp:114
static constexpr float kDefaultNominalDt
Definition host_frame_pump.hpp:81
void note_frame_skipped()
Tell the pump the host had a vsync it deliberately did NOT turn into a frame (nothing dirty,...
Definition host_frame_pump.hpp:108
static constexpr float kDefaultWakeThreshold
Definition host_frame_pump.hpp:82
Definition view.hpp:73
Predicate that decides whether a view tree still needs per-vsync frames.
Single authoritative time source for the view system.
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
bool should_dispatch_host_frame(HostFramePump &pump, bool needs_repaint, bool continuous, bool has_idle_callback)
Step 0 of a host tick, on the VSYNC SOURCE'S OWN THREAD: does this vsync need to reach the UI thread ...
bool host_frame_composites(const HostFrameTick &tick, bool damaged) noexcept
Step 3 of a host tick, after advance_host_frame: does this frame composite?
Definition host_frame_pump.hpp:224
HostFrameTick begin_host_frame(View *root, FrameClock &clock, HostFramePump &pump, double now_seconds, bool needs_repaint)
Step 1 of a host tick: measure dt, pump the FrameClock's activity probes with it, then decide whether...
void advance_widget_animations(View *view, float dt)
Advance the built-in widget animations and the CSS animation timeline for view and every descendant.
void advance_host_frame(View *root, FrameClock &clock, float dt)
Step 2 of a host tick, run only when HostFrameTick::should_render: advance every dt-integrating consu...
Result of begin_host_frame.
Definition host_frame_pump.hpp:146
bool animating
True if the tree paints something new every frame WITHOUT requesting a repaint (needs_continuous_fram...
Definition host_frame_pump.hpp:167
bool resumed
True if this frame was a resume (first frame or wake-from-idle).
Definition host_frame_pump.hpp:169
bool continuous
True if the tree still wants continuous per-vsync frames (something is animating, or a render subscri...
Definition host_frame_pump.hpp:158
float dt
The measured dt for this frame.
Definition host_frame_pump.hpp:149
bool should_render
True if the host should advance this frame (advance_host_frame).
Definition host_frame_pump.hpp:152