Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
plugin_frame_renderer.hpp
Go to the documentation of this file.
1#pragma once
2
3// plugin_frame_renderer.hpp — the damage-aware frame pipeline shared by the
4// Windows and Linux plug-in editor hosts.
5//
6// Both hosts had their own copy of: the background fill and design-viewport
7// paint body, the damage → clip decision (hazard model, letterbox mapping,
8// pixel snapping), and the acquire → paint → readback → submit → present
9// sequence. The copies had already drifted — only one of them checked the
10// readback result — and every WAH-2 failure-semantics fix would otherwise have
11// had to be made twice, correctly, forever.
12//
13// The split here is deliberate:
14//
15// * `FrameGeometry`, `compute_frame_clip()` and `paint_plugin_scene()` are
16// pure and Skia-free, so they compile and are TESTED on macOS — which is
17// Pulp's required CI gate. Logic reachable only under `_WIN32` is logic no
18// gate ever runs (the same reasoning as win_pointer_input.hpp).
19// * `PluginFrameRenderer` owns the GPU drive and the failure policy, and only
20// exists in Skia builds.
21//
22// Native window ownership (HWND/X11), event dispatch, and attach/detach stay in
23// the platform hosts. This module never touches a native handle.
24
28
29#include <cstdint>
30
31namespace pulp::canvas {
32class Canvas;
33}
34
35namespace pulp::view {
36
37class View;
38
45 float width = 0.0f;
46 float height = 0.0f;
47 float scale = 1.0f;
48 float design_width = 0.0f;
49 float design_height = 0.0f;
50 bool design_top_align = false;
55
61 std::uint32_t physical_width = 0;
62 std::uint32_t physical_height = 0;
63
64 bool has_design_viewport() const {
65 return design_width > 0.0f && design_height > 0.0f;
66 }
67
71 std::uint32_t pixel_width() const {
72 return physical_width ? physical_width : to_pixels(width);
73 }
74 std::uint32_t pixel_height() const {
75 return physical_height ? physical_height : to_pixels(height);
76 }
77
78private:
79 std::uint32_t to_pixels(float logical) const {
80 const float p = logical * scale;
81 return static_cast<std::uint32_t>(p < 1.0f ? 1.0f : p);
82 }
83};
84
99 const FrameGeometry& geometry, Rect& out_clip);
100
108 const FrameGeometry& geometry, const Rect* clip);
109
110} // namespace pulp::view
111
112#ifdef PULP_HAS_SKIA
113
116
117#include <cstdint>
118#include <functional>
119#include <memory>
120#include <vector>
121
123
124namespace pulp::view {
125
140class PluginFrameRenderer {
141public:
146 static constexpr int kMaxConsecutiveRecreates = 3;
147
148 struct Frame {
151 bool readback_ok = true;
154 bool should_recreate_surface = false;
157 bool gpu_path_exhausted = false;
158
159 bool reached_output() const {
160 return render::frame_reached_output(outcome);
161 }
162 };
163
164 struct Request {
165 View* root = nullptr;
166 FrameGeometry geometry{};
167 bool partial_repaint = false;
170 std::function<void()> idle;
172 std::vector<std::uint8_t>* capture = nullptr;
173 std::uint32_t* capture_width = nullptr;
174 std::uint32_t* capture_height = nullptr;
175 };
176
179 Frame render(render::GpuSurface& gpu, render::SkiaSurface& skia,
180 PendingDamage& damage, const Request& request);
181
185 void note_surfaces_created() { consecutive_recreates_ = 0; }
186
187 int consecutive_recreates() const { return consecutive_recreates_; }
188
189private:
193 Frame& finish(Frame& frame, render::FrameOutcome outcome);
194
195 int consecutive_recreates_ = 0;
196};
197
200struct EditorSurfaces {
201 std::unique_ptr<render::GpuSurface> gpu;
202 std::unique_ptr<render::SkiaSurface> skia;
207 bool partial_repaint = false;
208
209 bool ok() const { return gpu != nullptr && skia != nullptr; }
210};
211
219render::GpuSurface::Config editor_surface_config(
220 void* native_handle, const FrameGeometry& geometry,
221 PluginViewHost::PresentPolicy policy, bool enable_gpu_timing);
222
245EditorSurfaces create_editor_surfaces(void* native_handle,
246 const FrameGeometry& geometry,
248 bool enable_gpu_timing,
249 bool want_partial_repaint,
250 const char* log_tag);
251
255class RasterSceneCache {
256 public:
257 RasterSceneCache();
258 ~RasterSceneCache();
259
260 RasterSceneCache(const RasterSceneCache&) = delete;
261 RasterSceneCache& operator=(const RasterSceneCache&) = delete;
262
263 private:
264 struct Impl;
265 std::unique_ptr<Impl> impl_;
266 friend std::vector<std::uint8_t> raster_plugin_scene_rgba(View&, const FrameGeometry&,
267 std::uint32_t*, std::uint32_t*,
268 canvas::TextRasterPolicy,
269 RasterSceneCache*);
270};
271
285std::vector<std::uint8_t>
286raster_plugin_scene_rgba(View& root, const FrameGeometry& geometry, std::uint32_t* out_w,
287 std::uint32_t* out_h,
289 RasterSceneCache* retained_cache = nullptr);
290
293std::vector<std::uint8_t> encode_rgba_png(const std::vector<std::uint8_t>& rgba,
294 std::uint32_t w, std::uint32_t h);
295
296} // namespace pulp::view
297
298#endif // PULP_HAS_SKIA
Definition canvas.hpp:240
One frame's damage, taken atomically out of a PendingDamage.
Definition pending_damage.hpp:39
PresentPolicy
How a host presents finished frames (WAH-13).
Definition plugin_view_host.hpp:77
Definition view.hpp:73
@ ok
Definition analyzer_provider.hpp:58
Definition affine_transform.hpp:24
TextRasterPolicy
Glyph preblend a surface is created with.
Definition text_raster_policy.hpp:33
@ legacy
Definition text_raster_policy.hpp:34
PulpsetRender render(HeadlessHost &host, const Pulpset &ps, std::size_t total_samples, std::size_t block_size=512)
Replay ps over host for total_samples, in block_size blocks.
Definition pulpset.hpp:190
@ Request
Definition capabilities.hpp:19
constexpr bool frame_reached_output(FrameOutcome outcome)
True when outcome means the frame's pixels reached their intended output, i.e.
Definition skia_surface.hpp:50
FrameOutcome
Where a frame actually ended up.
Definition skia_surface.hpp:35
@ failed
Submission failed. The surface is still usable — retry the frame.
Definition skia_surface.hpp:44
@ idle
Definition voice.hpp:17
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ gpu
Offscreen GPU (Dawn + Skia via pulp::render::HeadlessSurface).
Definition screenshot.hpp:16
@ skia
CPU Skia raster (SkSurfaces::Raster).
Definition screenshot.hpp:15
bool compute_frame_clip(View &root, const PendingDamage::Snapshot &damage, const FrameGeometry &geometry, Rect &out_clip)
Decide the clip rect for a partial repaint, in SURFACE space.
constexpr std::uint32_t kEditorHostClearRgb
The background a plug-in editor host paints when the plug-in has not declared its own (Processor::edi...
Definition plugin_view_host.hpp:48
@ h
Definition input_events.hpp:39
@ p
Definition input_events.hpp:40
@ w
Definition input_events.hpp:41
void paint_plugin_scene(canvas::Canvas &canvas, View &root, const FrameGeometry &geometry, const Rect *clip)
Paint one editor frame: background fill (geometry.background_rgb), design-viewport transform,...
The size/scale/viewport a frame is painted against, in one value.
Definition plugin_frame_renderer.hpp:44
bool design_top_align
Definition plugin_frame_renderer.hpp:50
std::uint32_t physical_height
Definition plugin_frame_renderer.hpp:62
float design_width
0 disables the design viewport
Definition plugin_frame_renderer.hpp:48
std::uint32_t background_rgb
0xRRGGBB painted under the view tree: the whole frame before the editor's document mounts,...
Definition plugin_frame_renderer.hpp:54
bool has_design_viewport() const
Definition plugin_frame_renderer.hpp:64
float scale
Definition plugin_frame_renderer.hpp:47
float height
Definition plugin_frame_renderer.hpp:46
float design_height
Definition plugin_frame_renderer.hpp:49
std::uint32_t pixel_height() const
Definition plugin_frame_renderer.hpp:74
std::uint32_t physical_width
The surface's exact physical size, when the platform reports one (the client rect a Windows WM_SIZE c...
Definition plugin_frame_renderer.hpp:61
std::uint32_t pixel_width() const
Physical-pixel dimensions: the reported physical size when there is one, else logical × scale,...
Definition plugin_frame_renderer.hpp:71
float width
Definition plugin_frame_renderer.hpp:45
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52