Skip to main content

euv_example/app/
struct.rs

1use super::*;
2
3/// Independent stacked HTML `<canvas>` presentation target locked to a single browser context family.
4#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
5pub struct ShowcaseWebCanvasSlot {
6    /// Unique monotonic identifier for this `<canvas>` DOM element.
7    #[get(type(copy))]
8    pub(crate) canvas_id: u64,
9    /// Permanently locked context family (`WebGl2` or `Canvas2d`) for this `<canvas>`.
10    #[get(type(copy))]
11    pub(crate) context_family: ShowcaseWebCanvasContextFamily,
12    /// Target presentation path served by this slot.
13    #[get(type(copy))]
14    pub(crate) path: ShowcaseWebPresentationPath,
15    /// Whether this `<canvas>` is currently visible in the foreground stack.
16    #[get(type(copy))]
17    pub(crate) visible: bool,
18    /// CSS stacking `z-index` (`1` active foreground, `0` hidden standby).
19    #[get(type(copy))]
20    pub(crate) z_index: i32,
21    /// Physical canvas width in pixels.
22    #[get(type(copy))]
23    pub(crate) width: u32,
24    /// Physical canvas height in pixels.
25    #[get(type(copy))]
26    pub(crate) height: u32,
27    /// Scene revision rendered into this slot (`0` before first frame).
28    #[get(type(copy))]
29    pub(crate) scene_version: u64,
30    /// Whether the candidate's first frame has completed and is ready for atomic handoff.
31    #[get(type(copy))]
32    pub(crate) ready: bool,
33}
34
35/// Stacked dual-canvas handoff controller guaranteeing independent `<canvas>` targets and honest `SubmissionProxy` telemetry.
36#[derive(Clone, Data, Debug, Eq, PartialEq)]
37pub struct ShowcaseWebDualCanvasCoordinator {
38    /// Foreground visible `<canvas>` currently presenting frames.
39    #[get(type(copy))]
40    pub(crate) active: ShowcaseWebCanvasSlot,
41    /// Optional hidden sibling `<canvas>` pre-warming a candidate backend before atomic frame-boundary swap.
42    #[get(skip)]
43    pub(crate) standby: Option<ShowcaseWebCanvasSlot>,
44    /// Explicit CPU-mirror flag (`false` for `GpuDirect`; `true` for `GpuUpload` and `Canvas2d`).
45    #[get(type(copy))]
46    pub(crate) cpu_mirror_active: bool,
47    /// Truthful timing source (browser rAF always reports `SubmissionProxy`).
48    #[get(type(copy))]
49    pub(crate) timing_source: ShowcaseWebTimingSource,
50    /// Next unique `<canvas>` ID allocator.
51    #[get(type(copy))]
52    pub(crate) next_canvas_id: u64,
53    /// Total atomic frame-boundary handoff swaps committed.
54    #[get(type(copy))]
55    pub(crate) completed_swaps: u64,
56    /// Total aborted candidate handoffs leaving the previous canvas active.
57    #[get(type(copy))]
58    pub(crate) aborted_swaps: u64,
59    /// Total browser rAF ticks recorded strictly as `SubmissionProxy`.
60    #[get(type(copy))]
61    pub(crate) raf_proxy_ticks: u64,
62    /// Exact framebuffer upload bytes reported on the latest frame (`0` on `GpuDirect`).
63    #[get(type(copy))]
64    pub(crate) last_upload_bytes: u64,
65    /// Ordered history of retired `<canvas>` IDs removed only after atomic commit.
66    pub(crate) retired_canvas_ids: Vec<u64>,
67}
68
69/// Zero-allocation stack snapshot of adaptive renderer telemetry used to skip redundant signal/string updates when unchanged.
70#[derive(Clone, Copy, Debug, Eq, Getter, PartialEq)]
71pub struct ShowcaseAdaptiveSyncKey {
72    /// Active `/settings` auto-switch toggle state.
73    #[get(type(copy))]
74    pub(crate) auto_switch: bool,
75    /// Active low-level graphics backend.
76    #[get(type(copy))]
77    pub(crate) active_backend: GraphicsBackend,
78    /// Active adaptive render candidate.
79    #[get(type(copy))]
80    pub(crate) active_candidate: RenderBackendCandidate,
81    /// Recommended adaptive render candidate.
82    #[get(type(copy))]
83    pub(crate) recommended_candidate: RenderBackendCandidate,
84    /// Active CPU mirror flag reported by the renderer.
85    #[get(type(copy))]
86    pub(crate) cpu_mirror_active: bool,
87    /// Honest present timing source reported by the renderer.
88    #[get(type(copy))]
89    pub(crate) timing_source: PresentTimingSource,
90    /// Active pixel/instance upload strategy.
91    #[get(type(copy))]
92    pub(crate) upload_strategy: UploadStrategy,
93    /// Cumulative seamless handoff successes on the native/core router.
94    #[get(type(copy))]
95    pub(crate) handoff_successes: u64,
96    /// Cumulative handoff aborts on the native/core router.
97    #[get(type(copy))]
98    pub(crate) handoff_aborts: u64,
99    /// Active Web dual-canvas presentation path (`Canvas2d` on non-Web targets).
100    #[get(type(copy))]
101    pub(crate) web_path: ShowcaseWebPresentationPath,
102    /// Active Web timing source (`Unobservable` on non-Web targets).
103    #[get(type(copy))]
104    pub(crate) web_timing: ShowcaseWebTimingSource,
105    /// Active Web CPU mirror flag (`false` on non-Web targets).
106    #[get(type(copy))]
107    pub(crate) web_cpu_mirror: bool,
108    /// Cumulative Web dual-canvas completed swaps.
109    #[get(type(copy))]
110    pub(crate) web_completed_swaps: u64,
111    /// Cumulative Web dual-canvas aborted swaps.
112    #[get(type(copy))]
113    pub(crate) web_aborted_swaps: u64,
114}
115
116/// Persistent zero-DOM WebAssembly canvas host runtime backing Mini-Programs, QuickApps, and WASM Wearables.
117#[cfg(target_arch = "wasm32")]
118#[derive(Data)]
119pub struct HostCanvasRuntime {
120    /// Active EUV application instance rendering into the software RGBA8 framebuffer.
121    pub(crate) app: App,
122    /// Shared reactive showcase state.
123    pub(crate) state: ShowcaseState,
124    /// Multi-touch contact tracker translating touch phases into pointer events and drag gestures.
125    pub(crate) touch_tracker: TouchPointerTracker,
126    /// Canonical host vendor identifier (e.g. `"wechat"`, `"alliance"`, `"vivo-watch"`).
127    pub(crate) vendor: String,
128    /// Active platform kind (`MiniApp`, `QuickApp`, or `Wearable`).
129    #[get(type(copy))]
130    pub(crate) platform_kind: PlatformKind,
131    /// Current logical viewport width in dp.
132    #[get(type(copy))]
133    pub(crate) logical_width: u32,
134    /// Current logical viewport height in dp.
135    #[get(type(copy))]
136    pub(crate) logical_height: u32,
137    /// Active display pixel ratio.
138    #[get(type(copy))]
139    pub(crate) dpr: f32,
140    /// Whether host lifecycle froze the frame pump (`onHide`/`onUnload`/screen-off).
141    #[get(type(copy))]
142    pub(crate) paused: bool,
143    /// Whether wearable Always-On Display (1Hz ambient) mode is active.
144    #[get(type(copy))]
145    pub(crate) ambient: bool,
146    /// Pending dirty flag requiring a software rasterization pass on the next host step.
147    #[get(type(copy))]
148    pub(crate) dirty: bool,
149    /// Whether the next rendered frame must report full-viewport damage (`[0, 0, phys_w, phys_h]`).
150    #[get(type(copy))]
151    pub(crate) force_full_dirty: bool,
152    /// Last rendered physical dirty rectangle X origin in pixels.
153    #[get(type(copy))]
154    pub(crate) dirty_x: u32,
155    /// Last rendered physical dirty rectangle Y origin in pixels.
156    #[get(type(copy))]
157    pub(crate) dirty_y: u32,
158    /// Last rendered physical dirty rectangle width in pixels.
159    #[get(type(copy))]
160    pub(crate) dirty_w: u32,
161    /// Last rendered physical dirty rectangle height in pixels.
162    #[get(type(copy))]
163    pub(crate) dirty_h: u32,
164    /// Total frames rasterized during this host session.
165    #[get(type(copy))]
166    pub(crate) frame_count: u64,
167    /// Deterministic pixel hash of the latest rasterized frame.
168    #[get(type(copy))]
169    pub(crate) last_frame_hash: u64,
170    /// Accumulated fractional crown detents for discrete wearable focus/directional stepping.
171    #[get(type(copy))]
172    pub(crate) crown_remainder: f32,
173}