euv-core 0.49.4

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
use super::*;

/// Visual-equivalence invariant checklist gating channel selection across HarmonyOS, Wearables, MiniApps, and QuickApps.
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub struct HostVisualEquivalenceGate {
    /// Font shaping and glyph metrics match across candidate channels.
    #[get(type(copy))]
    pub(crate) fonts_equivalent: bool,
    /// Layout geometry and wrapping match across candidate channels.
    #[get(type(copy))]
    pub(crate) layout_equivalent: bool,
    /// Color space and premultiplication match across candidate channels.
    #[get(type(copy))]
    pub(crate) color_equivalent: bool,
    /// Anti-aliasing quality matches across candidate channels.
    #[get(type(copy))]
    pub(crate) aa_equivalent: bool,
    /// Box and text shadows match across candidate channels.
    #[get(type(copy))]
    pub(crate) shadow_equivalent: bool,
    /// Backdrop and Gaussian blur fidelity match across candidate channels.
    #[get(type(copy))]
    pub(crate) blur_equivalent: bool,
    /// Visible tiles and clipping regions match across candidate channels.
    #[get(type(copy))]
    pub(crate) visible_tiles_equivalent: bool,
    /// Embedded media/image decoding quality matches across candidate channels.
    #[get(type(copy))]
    pub(crate) media_quality_equivalent: bool,
}

/// Host-declared channel capability matrix unifying HarmonyOS, Wearables, MiniApps, and QuickApps.
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct HostChannelCapabilities {
    /// Lowercase host or vendor runtime identifier.
    #[get(type(copy))]
    pub(crate) host_name: &'static str,
    /// Exact rendering channels declared available by the host (length `<= 1` locks single-channel mode with zero probing).
    pub(crate) supported_channels: Vec<HostRenderChannel>,
    /// Default preferred channel when no override is requested.
    #[get(type(copy))]
    pub(crate) preferred_channel: HostRenderChannel,
    /// Visual-equivalence contract gating channel switching.
    #[get(type(copy))]
    pub(crate) visual_equivalence: HostVisualEquivalenceGate,
    /// True when executing against a host-simulated or off-device profile rather than live hardware.
    #[get(type(copy))]
    pub(crate) simulated_profile: bool,
    /// True ONLY when direct GPU presentation has been verified on real hardware (always `false` when `simulated_profile == true`).
    #[get(type(copy))]
    pub(crate) direct_gpu_verified_on_device: bool,
}

/// Resolved channel selection decision enforcing single-channel non-probing, visual equivalence, and simulated-profile honesty.
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub struct HostChannelSelection {
    /// Concrete rendering channel selected for execution.
    #[get(type(copy))]
    pub(crate) selected: HostRenderChannel,
    /// True when `supported_channels.len() <= 1` locked the host to its sole channel.
    #[get(type(copy))]
    pub(crate) single_channel_locked: bool,
    /// True when probing alternate rendering modes is strictly forbidden.
    #[get(type(copy))]
    pub(crate) probing_disabled: bool,
    /// True when all 8 visual-equivalence invariants hold for this channel.
    #[get(type(copy))]
    pub(crate) visual_equivalence_passed: bool,
    /// True when running on a simulated or off-device profile.
    #[get(type(copy))]
    pub(crate) simulated_profile: bool,
    /// True ONLY when direct GPU presentation was verified on a real physical device (`false` on simulated profiles).
    #[get(type(copy))]
    pub(crate) direct_gpu_verified_on_device: bool,
}

/// Opaque OpenHarmony `OHNativeWindow` FFI handle from `libnative_window.so`.
#[repr(C)]
pub struct OhNativeWindow {
    /// Zero-sized private marker enforcing opaque FFI semantics.
    pub(crate) _private: [u8; 0],
}

/// Opaque OpenHarmony `OH_NativeXComponent` FFI handle from `libace_ndk.z.so`.
#[repr(C)]
pub struct OhNativeXComponent {
    /// Zero-sized private marker enforcing opaque FFI semantics.
    pub(crate) _private: [u8; 0],
}

/// Opaque OpenHarmony `OHNativeWindowBuffer` FFI handle returned by `OH_NativeWindow_NativeWindowRequestBuffer`.
#[repr(C)]
pub struct OhNativeWindowBuffer {
    /// Zero-sized private marker enforcing opaque FFI semantics.
    pub(crate) _private: [u8; 0],
}

/// Opaque OpenHarmony `napi_env` handle from `libace_napi.z.so`.
#[repr(C)]
pub struct OhNapiEnv {
    /// Zero-sized private marker enforcing opaque FFI semantics.
    pub(crate) _private: [u8; 0],
}

/// Opaque OpenHarmony `napi_value` handle from `libace_napi.z.so`.
#[repr(C)]
pub struct OhNapiValue {
    /// Zero-sized private marker enforcing opaque FFI semantics.
    pub(crate) _private: [u8; 0],
}

/// Opaque OpenHarmony `OH_NativeVSync` handle from `libnative_vsync.so`.
#[repr(C)]
pub struct OhNativeVSync {
    /// Zero-sized private marker enforcing opaque FFI semantics.
    pub(crate) _private: [u8; 0],
}

/// POSIX `pollfd` ABI layout used to await OpenHarmony acquire fence FDs before pixel upload.
#[cfg(target_env = "ohos")]
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub(crate) struct HarmonyPollFd {
    /// Acquire sync fence file descriptor.
    pub(crate) fd: i32,
    /// Requested poll events (`HARMONY_POLLIN`).
    pub(crate) events: i16,
    /// Returned poll events.
    pub(crate) revents: i16,
}

/// OpenHarmony `OH_NativeWindow` `BufferHandle` header layout matching `<buffer_handle.h>`.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OhBufferHandle {
    /// Shared memory buffer file descriptor (`-1` if unmapped).
    pub(crate) fd: i32,
    /// Physical buffer width in pixels.
    pub(crate) width: i32,
    /// Row stride in bytes.
    pub(crate) stride: i32,
    /// Physical buffer height in pixels.
    pub(crate) height: i32,
    /// Allocated buffer byte size.
    pub(crate) size: i32,
    /// Pixel format code (`HARMONY_PIXEL_FMT_RGBA_8888 = 12`).
    pub(crate) format: i32,
    /// Buffer usage bitflags.
    pub(crate) usage: u64,
    /// Mapped virtual address pointer (`0` when unmapped).
    pub(crate) vir_addr: usize,
    /// Physical memory address (`0` when virtual-only).
    pub(crate) phy_addr: u64,
}

/// Single damaged rectangle inside OpenHarmony `Region` for `OH_NativeWindow_NativeWindowFlushBuffer`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct OhRegionRect {
    /// Left pixel coordinate.
    pub(crate) origin_x: i32,
    /// Top pixel coordinate.
    pub(crate) origin_y: i32,
    /// Rectangle width in pixels.
    pub(crate) width: u32,
    /// Rectangle height in pixels.
    pub(crate) height: u32,
}

/// OpenHarmony `Region` damage descriptor passed to `OH_NativeWindow_NativeWindowFlushBuffer`.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OhRegion {
    /// Pointer to contiguous array of `OhRegionRect` items (null for full-surface damage).
    pub(crate) rects: *const OhRegionRect,
    /// Number of rectangles in `rects` (`0` for full-surface flush).
    pub(crate) rect_number: i32,
}

/// ABI-compatible OpenHarmony `OH_NativeXComponent_TouchPoint` structure.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct OhNativeXComponentTouchPoint {
    /// Hardware touch contact identifier.
    pub(crate) id: i32,
    /// Screen-space X coordinate in physical pixels.
    pub(crate) screen_x: f32,
    /// Screen-space Y coordinate in physical pixels.
    pub(crate) screen_y: f32,
    /// Component-local X coordinate in physical pixels.
    pub(crate) x: f32,
    /// Component-local Y coordinate in physical pixels.
    pub(crate) y: f32,
    /// Touch action type (`HARMONY_TOUCH_DOWN`..`HARMONY_TOUCH_CANCEL`).
    pub(crate) touch_type: i32,
    /// Contact area size.
    pub(crate) size: f64,
    /// Normalized touch pressure force.
    pub(crate) force: f32,
    /// Monotonic event timestamp in nanoseconds.
    pub(crate) time_stamp: i64,
    /// True when this point is the active pressed contact.
    pub(crate) is_pressed: bool,
}

/// ABI-compatible OpenHarmony `OH_NativeXComponent_TouchEvent` payload.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OhNativeXComponentTouchEvent {
    /// Active primary contact identifier.
    pub(crate) id: i32,
    /// Primary screen-space X coordinate in physical pixels.
    pub(crate) screen_x: f32,
    /// Primary screen-space Y coordinate in physical pixels.
    pub(crate) screen_y: f32,
    /// Primary component-local X coordinate in physical pixels.
    pub(crate) x: f32,
    /// Primary component-local Y coordinate in physical pixels.
    pub(crate) y: f32,
    /// Action type (`HARMONY_TOUCH_DOWN`..`HARMONY_TOUCH_CANCEL`).
    pub(crate) touch_type: i32,
    /// Contact size.
    pub(crate) size: f64,
    /// Contact force.
    pub(crate) force: f32,
    /// Input device identifier.
    pub(crate) device_id: i64,
    /// Event timestamp in nanoseconds.
    pub(crate) time_stamp: i64,
    /// Up to 10 simultaneous multi-touch points matching `OH_MAX_TOUCH_POINTS_NUMBER`.
    pub(crate) touch_points: [OhNativeXComponentTouchPoint; 10],
    /// Count of valid entries in `touch_points`.
    pub(crate) num_points: u32,
}

/// ABI-compatible OpenHarmony `OH_NativeXComponent_MouseEvent` structure for HarmonyOS PC / Tablet pointer input.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct OhNativeXComponentMouseEvent {
    /// Component-local X coordinate in physical pixels.
    pub(crate) x: f32,
    /// Component-local Y coordinate in physical pixels.
    pub(crate) y: f32,
    /// Screen-space X coordinate in vp.
    pub(crate) screen_x: f32,
    /// Screen-space Y coordinate in vp.
    pub(crate) screen_y: f32,
    /// Monotonic timestamp in nanoseconds.
    pub(crate) timestamp: i64,
    /// Mouse action (`HARMONY_MOUSE_PRESS`..`HARMONY_MOUSE_CANCEL`).
    pub(crate) action: i32,
    /// Active button bitmask (`HARMONY_MOUSE_BUTTON_*`).
    pub(crate) button: i32,
}

/// ABI-compatible OpenHarmony `OH_NativeXComponent_MouseEvent_Callback` table for PC hover and mouse events.
#[repr(C)]
#[derive(Clone, Copy)]
pub struct OhNativeXComponentMouseCallback {
    /// Callback fired when a mouse press, release, or drag occurs on the XComponent.
    pub(crate) dispatch_mouse_event:
        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
    /// Callback fired when the pointer enters or exits the XComponent hover region.
    pub(crate) dispatch_hover_event: Option<unsafe extern "C" fn(*mut OhNativeXComponent, bool)>,
}

/// ABI-compatible OpenHarmony `OH_NativeXComponent_Callback` table registered with `libace_ndk.z.so`.
#[repr(C)]
#[derive(Clone, Copy)]
pub struct OhNativeXComponentCallback {
    /// Callback fired when ArkUI attaches a live `OHNativeWindow` surface.
    pub(crate) on_surface_created:
        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
    /// Callback fired when the XComponent surface dimensions change.
    pub(crate) on_surface_changed:
        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
    /// Callback fired before ArkUI destroys the `OHNativeWindow` surface.
    pub(crate) on_surface_destroyed:
        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
    /// Callback fired when ArkUI dispatches a touch event to the XComponent.
    pub(crate) dispatch_touch_event:
        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
}

/// Normalized HarmonyOS `window.AvoidArea` insets combining system bars, camera cutout, gesture bar, and IME.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct HarmonyAvoidArea {
    /// Top status bar / cutout avoid inset in physical pixels.
    #[get(type(copy))]
    pub(crate) top_px: u32,
    /// Right landscape cutout / gesture avoid inset in physical pixels.
    #[get(type(copy))]
    pub(crate) right_px: u32,
    /// Bottom navigation indicator / keyboard avoid inset in physical pixels.
    #[get(type(copy))]
    pub(crate) bottom_px: u32,
    /// Left landscape cutout avoid inset in physical pixels.
    #[get(type(copy))]
    pub(crate) left_px: u32,
    /// Active soft keyboard height in physical pixels (`0` when hidden).
    #[get(type(copy))]
    pub(crate) keyboard_px: u32,
}

/// Device form-factor hardware profile for HarmonyOS / OpenHarmony targets.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct HarmonyDeviceProfile {
    /// Concrete HarmonyOS device category (Phone, Tablet, PC/2-in-1, Foldable, Watch, TV, Automotive).
    #[get(type(copy))]
    pub(crate) device_type: HarmonyDeviceType,
    /// Initial logical viewport width in HarmonyOS `vp`.
    #[get(type(copy))]
    pub(crate) logical_width: u32,
    /// Initial logical viewport height in HarmonyOS `vp`.
    #[get(type(copy))]
    pub(crate) logical_height: u32,
    /// Display density scaling `vp -> px`.
    #[get(type(copy))]
    pub(crate) density: f32,
    /// Preferred hardware refresh rate in Hertz (`60.0` / `90.0` / `120.0`).
    #[get(type(copy))]
    pub(crate) refresh_rate_hz: f32,
    /// Preferred native graphics API (`Vulkan`, `OpenGlEs3`, or `SoftwareBuffer`).
    #[get(type(copy))]
    pub(crate) graphics_api: HarmonyGraphicsApi,
}

/// Live ArkUI XComponent window record held by `HarmonyPlatform`.
#[derive(Clone, Data, Debug)]
pub struct HarmonyWindowRecord {
    /// Window configuration snapshot.
    pub(crate) config: WindowConfig,
    /// Live window state with safe-area and display refresh metadata.
    #[get(type(copy))]
    pub(crate) state: WindowState,
    /// ArkUI `<XComponent>` instance identifier string.
    pub(crate) xcomponent_id: String,
    /// Attached `OHNativeWindow*` raw pointer (`0` before `onSurfaceCreated` or after teardown).
    #[get(type(copy))]
    pub(crate) native_window: usize,
    /// Attached `OH_NativeXComponent*` raw pointer (`0` when running offscreen/simulated).
    #[get(type(copy))]
    pub(crate) xcomponent: usize,
    /// Active graphics API driving this XComponent surface.
    #[get(type(copy))]
    pub(crate) graphics_api: HarmonyGraphicsApi,
    /// Cached surface pixel width to avoid redundant `SET_BUFFER_GEOMETRY` calls.
    #[get(type(copy))]
    pub(crate) surface_width: u32,
    /// Cached surface pixel height.
    #[get(type(copy))]
    pub(crate) surface_height: u32,
    /// Last presented RGBA8 framebuffer snapshot.
    pub(crate) last_frame: Framebuffer,
    /// Total frames presented to this XComponent surface.
    #[get(type(copy))]
    pub(crate) present_count: u64,
}

/// Unified HarmonyOS / OpenHarmony platform backend bridging ArkUI XComponent, `OHNativeWindow`, EGL/GLES3/Vulkan, and NAPI.
#[derive(Clone, Data, Debug)]
pub struct HarmonyPlatform {
    /// Active HarmonyOS device form-factor profile.
    #[get(type(copy))]
    pub(crate) profile: HarmonyDeviceProfile,
    /// Active foldable hinge posture (relevant when `device_type == HarmonyDeviceType::Foldable`).
    #[get(type(copy))]
    pub(crate) fold_state: HarmonyFoldState,
    /// Active Stage-Model window mode (`Floating` / `Maximized` / `Fullscreen` / `Split*` on HarmonyOS PC & Tablet).
    #[get(type(copy))]
    pub(crate) window_mode: HarmonyWindowMode,
    /// Tracked physical keyboard modifiers (`Shift` / `Ctrl` / `Alt` / `Meta`) for HarmonyOS PC shortcuts.
    #[get(type(copy))]
    pub(crate) active_modifiers: Modifiers,
    /// Last applied desktop cursor icon hint for HarmonyOS PC pointer synchronization.
    #[get(type(copy))]
    pub(crate) last_cursor: CursorIcon,
    /// Outbound ArkTS / N-API host bridge commands drained after frame and window updates.
    pub(crate) outbound_commands: Vec<HarmonyHostCommand>,
    /// Active `OHNativeWindow*` pointer attached by ArkUI XComponent.
    #[get(type(copy))]
    pub(crate) attached_native_window: usize,
    /// Active `OH_NativeXComponent*` pointer attached by NAPI `Init`.
    #[get(type(copy))]
    pub(crate) attached_xcomponent: usize,
    /// Latest resolved `SafeAreaInsets` in logical `vp`.
    #[get(type(copy))]
    pub(crate) safe_area: SafeAreaInsets,
    /// Generation-stamped mobile/ability lifecycle coordinator preventing exit/re-entry races.
    pub(crate) lifecycle: MobileSessionLifecycle,
    /// Monotonic window identifier allocator.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) next_id: u64,
    /// Primary XComponent window handle, if created.
    #[get(skip)]
    pub(crate) primary_window: Option<WindowId>,
    /// Active HarmonyOS windows indexed by `WindowId`.
    pub(crate) windows: HashMap<WindowId, HarmonyWindowRecord>,
    /// Queued normalized `WindowEvent` and `SystemEvent`s awaiting `poll_events()`.
    pub(crate) pending_events: Vec<WindowEvent>,
    /// Cached system pasteboard UTF-8 text.
    #[get(skip)]
    pub(crate) clipboard: Option<String>,
    /// In-memory sandbox `preferences` / `KVStore` storage backing `PlatformStorage`.
    pub(crate) storage: HashMap<String, String>,
    /// Logical ArkUI router navigation stack backing `PlatformNavigation`.
    pub(crate) route_stack: Vec<String>,
    /// Active OS light/dark appearance mode.
    #[get(type(copy))]
    pub(crate) theme: ThemeMode,
    /// Whether the HarmonyOS VSync (`OH_NativeVSync`) frame pump is currently paused for background freeze.
    #[get(type(copy))]
    pub(crate) pump_paused: bool,
    /// Whether `present_framebuffer` retains a cloned RGBA8 snapshot for diagnostic inspection (default `false`).
    #[get(type(copy))]
    pub(crate) capture_last_frame: bool,
    /// Active `OH_NativeVSync*` handle allocated by `libnative_vsync.so` (`0` when running off-device).
    #[get(type(copy))]
    pub(crate) vsync_handle: usize,
    /// Timestamp in nanoseconds of the previous `OH_NativeVSync` callback for live Hz estimation.
    #[get(type(copy))]
    pub(crate) last_vsync_timestamp_ns: i64,
}