Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
native_view_host.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pulp/view/view.hpp>
4
5#include <cstdint>
6#include <functional>
7#include <vector>
8
9namespace pulp::view {
10
11class WindowHost;
12class PluginViewHost;
13
14// Platform-native child-view handle (NSView* / UIView* / HWND / X11 Window),
15// mirroring the identical alias in plugin_view_host.hpp / web_view.hpp. Declared
16// locally so this header stays light (it does not pull in the full host
17// headers); a repeated `using` to the same type is a legal, harmless
18// redeclaration when those headers are also included.
19using NativeViewHandle = void*;
20
72class NativeViewHost : public View {
73 friend class PluginViewHost;
74 friend class WindowHost;
75
76public:
80 using SnapshotFn = std::function<std::vector<uint8_t>(uint32_t width,
81 uint32_t height)>;
82
83 NativeViewHost() = default;
84 ~NativeViewHost() override;
85
92 void set_native_child(NativeViewHandle handle, SnapshotFn snapshot = {});
93
97
99 NativeViewHandle native_child() const { return handle_; }
100
104 bool is_native_attached() const { return attached_; }
105
106 // ── Introspection (headless tests) ──────────────────────────────────────
111 Rect computed_child_frame() const { return last_frame_; }
118 Rect computed_child_frame_host() const { return last_frame_host_; }
122 Rect computed_visible_rect() const { return last_visible_; }
125 bool is_clipped() const { return last_clipped_; }
130
131 // ── View overrides ──────────────────────────────────────────────────────
132 std::vector<uint8_t> capture_native_overlay_png(uint32_t width,
133 uint32_t height) override;
137
138private:
139 enum class HostKind { none, plugin, window };
140
144 void compute_geometry(Rect& frame, Rect& visible, bool& clipped) const;
145
149 bool active_viewport_transform(float& sx, float& sy, float& tx,
150 float& ty) const;
151
154 static void apply_viewport(Rect& r, float sx, float sy, float tx, float ty) {
155 r = {r.x * sx + tx, r.y * sy + ty, r.width * sx, r.height * sy};
156 }
157
159 bool try_attach();
162 void detach_from_host();
168 void on_host_destroyed();
170 void reconcile_host();
172 void push_geometry(const Rect& frame, const Rect& visible, bool clipped);
173
174 NativeViewHandle handle_ = nullptr;
175 SnapshotFn snapshot_;
176
177 bool attached_ = false;
178 HostKind attached_kind_ = HostKind::none;
179 PluginViewHost* attached_plugin_ = nullptr;
180 WindowHost* attached_window_ = nullptr;
181
182 // Last computed geometry in ROOT/design space (introspection getters; kept
183 // current every layout pump regardless of platform / attach state).
184 Rect last_frame_{};
185 Rect last_visible_{};
186 bool last_clipped_ = false;
187 // Last computed frame in HOST space (design frame after the active
188 // viewport transform). Equal to last_frame_ when no viewport is active.
189 Rect last_frame_host_{};
190
191 // Last geometry actually pushed to the host (HOST space), to skip
192 // redundant per-frame host calls.
193 Rect pushed_frame_{};
194 Rect pushed_visible_{};
195 bool pushed_clipped_ = false;
196 bool have_pushed_ = false;
197};
198
199} // namespace pulp::view
Definition canvas.hpp:240
Rect computed_visible_rect() const
The last visible sub-rectangle in root/host coordinates after intersecting with clipping ancestors.
Definition native_view_host.hpp:122
bool is_clipped() const
True when the native child is trimmed by a clipping ancestor (the visible rect is a strict subset of ...
Definition native_view_host.hpp:125
void clear_native_child()
Detach and forget the native child (does not destroy the underlying OS view — ownership stays with th...
void update_native_layout()
Recompute geometry and push it to the host now (also attaches lazily when a host + handle are present...
friend class PluginViewHost
Definition native_view_host.hpp:73
void set_window_host(WindowHost *host) override
Back-reference to the WindowHost that owns this view tree.
NativeViewHandle native_child() const
The currently-set native handle (null if none).
Definition native_view_host.hpp:99
std::vector< uint8_t > capture_native_overlay_png(uint32_t width, uint32_t height) override
When this view owns a native overlay (a WebView pane), it overrides this to return an in-process PNG ...
Rect computed_child_frame_host() const
The native child's absolute frame in HOST (window) coordinates — the design-space frame after the act...
Definition native_view_host.hpp:118
void set_plugin_view_host(PluginViewHost *host) override
Back-reference to the PluginViewHost that owns this editor tree.
Rect computed_child_frame() const
The native child's absolute frame in ROOT (design-space) coordinates as last computed from Yoga layou...
Definition native_view_host.hpp:111
void paint_all(canvas::Canvas &canvas) override
friend class WindowHost
Definition native_view_host.hpp:74
bool is_native_attached() const
True while the native child is embedded in a host.
Definition native_view_host.hpp:104
std::function< std::vector< uint8_t >(uint32_t width, uint32_t height)> SnapshotFn
Returns a PNG-encoded snapshot of the native child at the requested pixel size, or empty bytes when u...
Definition native_view_host.hpp:80
void set_native_child(NativeViewHandle handle, SnapshotFn snapshot={})
Supply the native child view to embed.
Definition plugin_view_host.hpp:64
bool visible() const
Definition view.hpp:333
Definition window_host.hpp:113
Definition affine_transform.hpp:24
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ r
Definition input_events.hpp:41
@ height
Definition css_animation.hpp:128
@ width
Definition css_animation.hpp:127
void * NativeViewHandle
Definition native_view_host.hpp:19
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52