Skip to main content

euv_core/app/runner/
struct.rs

1use super::*;
2
3/// Top-level cross-platform application configuration.
4#[derive(Clone, Data, Debug, PartialEq)]
5pub struct AppConfig {
6    /// Primary window creation settings.
7    pub(crate) window: WindowConfig,
8    /// Clear background color drawn beneath the root scene node.
9    #[get(type(copy))]
10    pub(crate) clear_color: Color,
11}
12
13/// Opt-in per-phase microsecond breakdown for a single `App::step_frame` execution.
14#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
15pub struct FramePhaseMetrics {
16    /// Window command flushing, event polling, and input dispatch duration in microseconds.
17    #[get(type(copy))]
18    pub(crate) input_us: u64,
19    /// Reactive effect flushing, animation/gesture/scroll ticking, and damage collection duration in microseconds.
20    #[get(type(copy))]
21    pub(crate) reactive_us: u64,
22    /// `LayoutEngine::compute` pass duration in microseconds.
23    #[get(type(copy))]
24    pub(crate) layout_us: u64,
25    /// Display-list compilation duration in microseconds when timed separately (`0` when combined into `raster_us`).
26    #[get(type(copy))]
27    pub(crate) paint_list_us: u64,
28    /// Unified render pass (`Renderer::render_frame`) duration in microseconds.
29    #[get(type(copy))]
30    pub(crate) raster_us: u64,
31    /// Native surface / framebuffer region presentation duration in microseconds.
32    #[get(type(copy))]
33    pub(crate) present_us: u64,
34}
35
36/// Unified per-frame diagnostic telemetry covering phase timings, damage ratio, redraw cause, and idle-aware FPS.
37#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
38pub struct FrameTelemetry {
39    /// Monotonic frame identifier matching `FrameStats::get_frame_index()`.
40    #[get(type(copy))]
41    pub(crate) frame_id: u64,
42    /// Microsecond breakdown across pipeline phases (zeroed when telemetry timing is disabled).
43    #[get(type(copy))]
44    pub(crate) phases: FramePhaseMetrics,
45    /// Fraction of physical viewport area rasterized (`0.0` when idle, `(0.0..=1.0]` when rendered).
46    #[get(type(copy))]
47    pub(crate) dirty_area_ratio: f32,
48    /// Diagnostic reason when the frame promoted to full-viewport redraw (`FullRedrawReason::None` for partial or idle).
49    #[get(type(copy))]
50    pub(crate) full_redraw_reason: FullRedrawReason,
51    /// Effective target cadence in Hertz (`min(fps_limit, display_refresh_rate_hz)` or `display_refresh_rate_hz`).
52    #[get(type(copy))]
53    pub(crate) target_hz: f32,
54    /// Active presented frames per second (`0.0` while idle, smoothed active present cadence while rendering).
55    #[get(type(copy))]
56    pub(crate) present_fps: f32,
57    /// Whether this frame skipped rendering because the scene was clean or rate-capped.
58    #[get(type(copy))]
59    pub(crate) is_idle: bool,
60    /// Number of scene nodes recomputed during layout.
61    #[get(type(copy))]
62    pub(crate) layout_nodes: usize,
63    /// Number of display-list draw commands executed.
64    #[get(type(copy))]
65    pub(crate) draw_commands: usize,
66    /// Number of physical pixels shaded.
67    #[get(type(copy))]
68    pub(crate) pixels_shaded: usize,
69}
70
71/// Unified cross-platform application runtime orchestrating platform events, reactivity, layout, and rendering.
72#[derive(CustomDebug, Data)]
73pub struct App {
74    /// Application configuration.
75    pub(crate) config: AppConfig,
76    /// Active direct OS or headless platform backend.
77    #[debug(skip)]
78    #[get(skip)]
79    pub(crate) platform: Box<dyn PlatformBackend>,
80    /// Primary window live state.
81    #[get(type(copy))]
82    pub(crate) window_state: WindowState,
83    /// Shared scene tree handle.
84    pub(crate) scene: SceneHandle,
85    /// Framework context carrying reactive breakpoint, theme, gesture, and safe-area signals.
86    pub(crate) context: Context,
87    /// Deterministic cross-platform layout engine.
88    pub(crate) layout_engine: LayoutEngine,
89    /// Multi-mode rendering pipeline (`Auto`, `Software`, `Hardware`, `Hybrid`).
90    pub(crate) renderer: Renderer,
91    /// Queued imperative window commands awaiting dispatch.
92    pub(crate) command_queue: WindowCommandQueue,
93    /// Local key-value storage service.
94    pub(crate) storage: StorageStore,
95    /// Flag indicating whether the application loop should keep running.
96    #[get(type(copy))]
97    pub(crate) running: bool,
98    /// Pending damage region for the next rendered frame.
99    #[get(type(copy))]
100    pub(crate) pending_damage: DamageRegion,
101    /// Real-time polled keyboard, pointer, and scroll state for game loops and interactive viewports.
102    pub(crate) input_state: InputState,
103    /// Fixed-timestep accumulator and FPS telemetry clock for real-time game rendering.
104    #[get(type(copy))]
105    pub(crate) frame_clock: FrameClock,
106    /// Platform-native services hub (permissions, protocol registration, Dynamic Island, haptics, tray, A11y).
107    pub(crate) services: PlatformServiceHub,
108    /// Reactive signal carrying the most recently received custom-scheme or universal deep link.
109    #[get(type(copy))]
110    pub(crate) deep_link: Signal<Option<DeepLinkEvent>>,
111    /// Shared dynamic update hub for live component-level and page-level OTA updates.
112    pub(crate) dynamic_hub: DynamicUpdateHub,
113    /// Last scene revision that was rasterized and presented, enabling zero-cost idle frame skipping.
114    #[get(type(copy))]
115    pub(crate) last_rendered_revision: u64,
116    /// Most recently submitted OS/Web cursor icon to avoid redundant platform cursor calls.
117    #[get(type(copy))]
118    pub(crate) last_cursor: CursorIcon,
119    /// Attached real-time game engine hosts receiving automatic OS input forwarding.
120    #[debug(skip)]
121    pub(crate) game_hosts: Vec<GameEngineHost>,
122    /// Active touch pointer identifier currently driving single-finger pan scrolling.
123    #[get(skip)]
124    pub(crate) touch_drag_pointer_id: Option<u64>,
125    /// Starting touch coordinate for mobile pan-to-scroll detection.
126    #[get(skip)]
127    pub(crate) touch_drag_origin: Option<Point>,
128    /// Previous touch coordinate for incremental mobile scroll deltas.
129    #[get(skip)]
130    pub(crate) touch_drag_last: Option<Point>,
131    /// Whether the active touch gesture has crossed tap slop into pan-scrolling.
132    #[get(type(copy))]
133    pub(crate) touch_dragging: bool,
134    /// Cumulative post-slop drag displacement in logical pixels for the active touch scroll gesture.
135    #[get(type(copy))]
136    pub(crate) touch_drag_travel: f32,
137    /// Locked scroll axis for the active touch drag (`0` = unlocked, `1` = vertical, `2` = horizontal, `3` = free).
138    #[get(type(copy))]
139    pub(crate) touch_scroll_axis: u8,
140    /// Touch pan displacement accumulated during the current frame for jitter-free velocity estimation.
141    #[get(type(copy))]
142    pub(crate) touch_vel_accum_delta: Point,
143    /// Fixed 8-entry stack ring buffer of `(dt_secs, dx, dy)` frame samples preventing thumb-lift backward fling reversals.
144    #[get(skip)]
145    #[get_mut(skip)]
146    #[set(skip)]
147    pub(crate) touch_vel_ring: [(f32, f32, f32); 8],
148    /// Ring buffer index of the oldest live velocity sample in `0..8`.
149    #[get(type(copy))]
150    pub(crate) touch_vel_head: usize,
151    /// Number of live samples currently stored in `touch_vel_ring` (`0..=8`).
152    #[get(type(copy))]
153    pub(crate) touch_vel_len: usize,
154    /// Elapsed idle seconds since the last touch pan movement while a finger remains held down.
155    #[get(type(copy))]
156    pub(crate) touch_vel_idle_secs: f32,
157    /// Whether the active pointer press grabbed a scrollbar track for thumb dragging.
158    #[get(type(copy))]
159    pub(crate) scrollbar_dragging: bool,
160    /// Active scrollbar thumb drag axis (`0` = none, `1` = vertical, `2` = horizontal).
161    #[get(type(copy))]
162    pub(crate) scrollbar_drag_axis: u8,
163    /// Active selectable `NodeKind::Text` node currently undergoing pointer drag selection.
164    #[get(skip)]
165    pub(crate) text_selecting_node: Option<NodeId>,
166    /// Starting character index anchored at pointer-down for drag text selection.
167    #[get(type(copy))]
168    pub(crate) text_select_anchor_char: usize,
169    /// Consecutive click count on the same selectable text node (`1` = caret, `2` = word, `3` = full node).
170    #[get(type(copy))]
171    pub(crate) text_click_count: u8,
172    /// Most recently clicked selectable text node for multi-click detection.
173    #[get(skip)]
174    pub(crate) text_last_click_node: Option<NodeId>,
175    /// Coordinates of the most recent click on a selectable text node.
176    #[get(skip)]
177    pub(crate) text_last_click_pos: Option<Point>,
178    /// Elapsed seconds since the most recent click on a selectable text node.
179    #[get(type(copy))]
180    pub(crate) text_last_click_age_secs: f32,
181    /// Active multi-touch / pointer contact map keyed by `pointer_id` for pinch & swipe recognition.
182    pub(crate) active_pointers: HashMap<u64, Point>,
183    /// Device kind recorded per active `pointer_id` for deterministic touch vs mouse separation.
184    pub(crate) active_pointer_devices: HashMap<u64, PointerDevice>,
185    /// Initial contact point of the active single-pointer gesture stroke.
186    #[get(skip)]
187    pub(crate) gesture_origin: Option<Point>,
188    /// Baseline two-finger distance recorded when a pinch gesture starts.
189    #[get(type(copy))]
190    pub(crate) pinch_base_dist: f32,
191    /// Accumulated hold duration in seconds for long-press gesture detection.
192    #[get(type(copy))]
193    pub(crate) gesture_hold_secs: f32,
194    /// Whether `GestureEventKind::LongPress` has already fired for the current press.
195    #[get(type(copy))]
196    pub(crate) long_press_fired: bool,
197    /// Coordinates of the most recent completed clean tap for double-tap detection.
198    #[get(skip)]
199    pub(crate) last_tap_pos: Option<Point>,
200    /// Elapsed seconds since the most recent completed clean tap.
201    #[get(type(copy))]
202    pub(crate) last_tap_age_secs: f32,
203    /// Monotonic gesture event sequence counter.
204    #[get(type(copy))]
205    pub(crate) gesture_seq: u64,
206    /// Inertial touch-scroll fling velocity in logical pixels per second.
207    #[get(type(copy))]
208    pub(crate) scroll_velocity: Point,
209    /// Pointer coordinates where inertial touch-scroll fling originated for hit-target resolution.
210    #[get(type(copy))]
211    pub(crate) scroll_fling_pos: Point,
212    /// Locked innermost scrollable node captured at touch-down to prevent nested scroll penetration.
213    #[get(skip)]
214    pub(crate) touch_scroll_target: Option<NodeId>,
215    /// Remaining smooth-scroll interpolation delta for discrete mouse-wheel notches.
216    #[get(type(copy))]
217    pub(crate) smooth_scroll_pending: Point,
218    /// Pointer coordinates captured when smooth wheel scrolling started.
219    #[get(type(copy))]
220    pub(crate) smooth_scroll_pos: Point,
221    /// Locked scroll container target for active smooth wheel interpolation.
222    #[get(skip)]
223    pub(crate) smooth_scroll_target: Option<NodeId>,
224    /// Re-entrancy guard preventing nested `step_frame` execution during macOS live-resize callbacks.
225    #[get(type(copy))]
226    pub(crate) in_step_frame: bool,
227    /// Accumulated blink phase timer in seconds for the focused `NodeKind::Input` caret.
228    #[get(type(copy))]
229    pub(crate) caret_blink_secs: f32,
230    /// When `true`, global swipe gestures are suppressed because the active stroke started in a canvas, slider, or isolated region.
231    #[get(type(copy))]
232    pub(crate) gesture_suppressed: bool,
233    /// Elapsed seconds accumulated for smoothed live FPS telemetry publication.
234    #[get(type(copy))]
235    pub(crate) fps_accum_secs: f32,
236    /// Rendered frame count accumulated inside the current FPS sampling window.
237    #[get(type(copy))]
238    pub(crate) fps_accum_frames: u32,
239    /// Accumulated frame time in seconds used to pace frames when an explicit FPS cap is configured.
240    #[get(type(copy))]
241    pub(crate) fps_budget_accum: f32,
242    /// Whether an editable `NodeKind::Input` currently holds focus and requests the system IME keyboard.
243    #[get(type(copy))]
244    pub(crate) last_ime_active: bool,
245    /// Handle of the `NodeKind::Input` that most recently activated the system IME keyboard.
246    #[get(skip)]
247    pub(crate) last_ime_node: Option<NodeId>,
248    /// Damage region rasterized during the most recent rendered frame for partial native surface presentation.
249    #[get(type(copy))]
250    pub(crate) last_frame_damage: DamageRegion,
251    /// Detected native hardware display refresh rate in Hertz (`60.0` fallback, `120.0`/`144.0`/`180.0`+ on high-refresh screens).
252    #[get(type(copy))]
253    pub(crate) display_refresh_rate_hz: f32,
254    /// Whether motion animations, smooth scrolling, inertia, or active games were running on the previous frame.
255    #[get(type(copy))]
256    pub(crate) was_animating: bool,
257    /// Cross-platform lifecycle and system event normalizer deduplicating OS notifications.
258    pub(crate) system_event_normalizer: SystemEventNormalizer,
259    /// Opt-in flag enabling per-phase microsecond timing instrumentation inside `step_frame` (zero syscall overhead when `false`).
260    #[get(type(copy))]
261    #[set(skip)]
262    pub(crate) telemetry_enabled: bool,
263    /// Most recently recorded `FrameTelemetry` snapshot.
264    #[get(type(copy))]
265    pub(crate) last_frame_telemetry: FrameTelemetry,
266    /// Pending diagnostic reason associated with `pending_damage` when full-viewport damage was queued before `step_frame`.
267    #[get(type(copy))]
268    pub(crate) pending_full_redraw_reason: FullRedrawReason,
269    /// Logical viewport size rasterized during the most recent rendered frame.
270    #[get(type(copy))]
271    pub(crate) last_rendered_viewport: Size,
272    /// Display DPI scale factor rasterized during the most recent rendered frame.
273    #[get(type(copy))]
274    pub(crate) last_rendered_scale: f32,
275    /// Active presented frames-per-second rate (`0.0` once idle beyond the sampling window).
276    #[get(type(copy))]
277    pub(crate) active_present_fps: f32,
278    /// Continuous idle seconds elapsed since the most recent rendered frame.
279    #[get(type(copy))]
280    pub(crate) idle_secs_since_present: f32,
281    /// Whether the most recent `step_frame` call skipped rendering due to a clean idle scene.
282    #[get(type(copy))]
283    pub(crate) is_idle_frame: bool,
284    /// Toggle enabling surgical pre/post-layout conservative bounds diffing instead of full-screen layout fallback (default `true`).
285    #[get(type(copy))]
286    #[set(skip)]
287    pub(crate) partial_layout_damage: bool,
288    /// Root reactive scope created by `App::mount` so root effects freeze cleanly in background.
289    #[get(skip)]
290    #[get_mut(skip)]
291    #[set(skip)]
292    pub(crate) mount_scope: Option<Scope>,
293    /// True while the application is frozen in background (zero CPU ticks, zero layout/paint/GPU work).
294    #[get(pub(crate), type(copy))]
295    #[set(pub(crate))]
296    pub(crate) background_frozen: bool,
297    /// True on the first frame after returning from background so elapsed sleep time clamps to `dt = 0.0`.
298    #[get(pub(crate), type(copy))]
299    #[set(pub(crate))]
300    pub(crate) resume_zero_dt_pending: bool,
301    /// Reactive scope handles frozen exclusively by background entry (leaving pre-frozen router pages untouched).
302    #[get(pub(crate))]
303    #[get_mut(pub(crate))]
304    #[set(pub(crate))]
305    pub(crate) background_frozen_scopes: Vec<ScopeId>,
306    /// Deterministic gesture arbitration arena enforcing priority tiers and touch-slop disambiguation.
307    #[get(pub(crate))]
308    #[get_mut(pub(crate))]
309    #[set(pub(crate))]
310    pub(crate) gesture_arena: GestureArena,
311    /// Last immersive fullscreen state synchronized with the platform backend.
312    #[get(pub(crate), type(copy))]
313    #[set(pub(crate))]
314    pub(crate) last_immersive_fullscreen: bool,
315}
316
317/// Fused single-borrow pre-tick snapshot collected at the start of `App::step_frame`.
318#[derive(Debug, Default)]
319pub(crate) struct FramePreTick {
320    /// Whether a live `NodeKind::Input` currently holds keyboard focus.
321    pub(crate) has_focused_input: bool,
322    /// Whether `ime_node_id` holds a visible non-disabled input node requesting OS IME presentation.
323    pub(crate) has_ime_node: bool,
324    /// Focused input node handle requesting OS IME presentation when `has_ime_node` is `true`.
325    pub(crate) ime_node_id: NodeId,
326    /// Screen-space logical bounds of `ime_node_id`.
327    pub(crate) ime_rect: Rect,
328    /// Dirty viewport rectangles reported by active `GameEngineHost` instances.
329    pub(crate) game_damage_rects: Vec<Rect>,
330    /// Visible top-layer portals `(is_dirty, screen_bounds)` collected from `SceneTree::portal_nodes()`.
331    pub(crate) visible_portals: Vec<(bool, Rect)>,
332    /// Indices into `App::game_hosts` that are actively rendering this frame.
333    pub(crate) active_host_indices: Vec<usize>,
334    /// Resolved frame animation timestep in seconds.
335    pub(crate) step_dt: f32,
336    /// Whether one or more `NodeTransition`s ticked inside the fused borrow.
337    pub(crate) anim_ticked: bool,
338    /// Whether active transitions were deferred until after `GameEngineHost::step`.
339    pub(crate) pending_game_transitions: bool,
340}
341
342/// Stack-first ancestor chain buffer avoiding heap allocations up to 32 tree levels deep.
343#[derive(Debug)]
344pub(crate) struct AncestorChain {
345    /// Inline stack buffer holding the first 32 ancestors (leaf first).
346    pub(crate) inline: [NodeId; 32],
347    /// Number of valid entries in `inline` when `spill` is empty.
348    pub(crate) len: usize,
349    /// Heap overflow buffer used only when ancestor depth exceeds 32.
350    pub(crate) spill: Vec<NodeId>,
351}