Skip to main content

euv_core/platform/harmony/
struct.rs

1use super::*;
2
3/// Visual-equivalence invariant checklist gating channel selection across HarmonyOS, Wearables, MiniApps, and QuickApps.
4#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
5pub struct HostVisualEquivalenceGate {
6    /// Font shaping and glyph metrics match across candidate channels.
7    #[get(type(copy))]
8    pub(crate) fonts_equivalent: bool,
9    /// Layout geometry and wrapping match across candidate channels.
10    #[get(type(copy))]
11    pub(crate) layout_equivalent: bool,
12    /// Color space and premultiplication match across candidate channels.
13    #[get(type(copy))]
14    pub(crate) color_equivalent: bool,
15    /// Anti-aliasing quality matches across candidate channels.
16    #[get(type(copy))]
17    pub(crate) aa_equivalent: bool,
18    /// Box and text shadows match across candidate channels.
19    #[get(type(copy))]
20    pub(crate) shadow_equivalent: bool,
21    /// Backdrop and Gaussian blur fidelity match across candidate channels.
22    #[get(type(copy))]
23    pub(crate) blur_equivalent: bool,
24    /// Visible tiles and clipping regions match across candidate channels.
25    #[get(type(copy))]
26    pub(crate) visible_tiles_equivalent: bool,
27    /// Embedded media/image decoding quality matches across candidate channels.
28    #[get(type(copy))]
29    pub(crate) media_quality_equivalent: bool,
30}
31
32/// Host-declared channel capability matrix unifying HarmonyOS, Wearables, MiniApps, and QuickApps.
33#[derive(Clone, Data, Debug, Eq, PartialEq)]
34pub struct HostChannelCapabilities {
35    /// Lowercase host or vendor runtime identifier.
36    #[get(type(copy))]
37    pub(crate) host_name: &'static str,
38    /// Exact rendering channels declared available by the host (length `<= 1` locks single-channel mode with zero probing).
39    pub(crate) supported_channels: Vec<HostRenderChannel>,
40    /// Default preferred channel when no override is requested.
41    #[get(type(copy))]
42    pub(crate) preferred_channel: HostRenderChannel,
43    /// Visual-equivalence contract gating channel switching.
44    #[get(type(copy))]
45    pub(crate) visual_equivalence: HostVisualEquivalenceGate,
46    /// True when executing against a host-simulated or off-device profile rather than live hardware.
47    #[get(type(copy))]
48    pub(crate) simulated_profile: bool,
49    /// True ONLY when direct GPU presentation has been verified on real hardware (always `false` when `simulated_profile == true`).
50    #[get(type(copy))]
51    pub(crate) direct_gpu_verified_on_device: bool,
52}
53
54/// Resolved channel selection decision enforcing single-channel non-probing, visual equivalence, and simulated-profile honesty.
55#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
56pub struct HostChannelSelection {
57    /// Concrete rendering channel selected for execution.
58    #[get(type(copy))]
59    pub(crate) selected: HostRenderChannel,
60    /// True when `supported_channels.len() <= 1` locked the host to its sole channel.
61    #[get(type(copy))]
62    pub(crate) single_channel_locked: bool,
63    /// True when probing alternate rendering modes is strictly forbidden.
64    #[get(type(copy))]
65    pub(crate) probing_disabled: bool,
66    /// True when all 8 visual-equivalence invariants hold for this channel.
67    #[get(type(copy))]
68    pub(crate) visual_equivalence_passed: bool,
69    /// True when running on a simulated or off-device profile.
70    #[get(type(copy))]
71    pub(crate) simulated_profile: bool,
72    /// True ONLY when direct GPU presentation was verified on a real physical device (`false` on simulated profiles).
73    #[get(type(copy))]
74    pub(crate) direct_gpu_verified_on_device: bool,
75}
76
77/// Opaque OpenHarmony `OHNativeWindow` FFI handle from `libnative_window.so`.
78#[repr(C)]
79pub struct OhNativeWindow {
80    /// Zero-sized private marker enforcing opaque FFI semantics.
81    pub(crate) _private: [u8; 0],
82}
83
84/// Opaque OpenHarmony `OH_NativeXComponent` FFI handle from `libace_ndk.z.so`.
85#[repr(C)]
86pub struct OhNativeXComponent {
87    /// Zero-sized private marker enforcing opaque FFI semantics.
88    pub(crate) _private: [u8; 0],
89}
90
91/// Opaque OpenHarmony `OHNativeWindowBuffer` FFI handle returned by `OH_NativeWindow_NativeWindowRequestBuffer`.
92#[repr(C)]
93pub struct OhNativeWindowBuffer {
94    /// Zero-sized private marker enforcing opaque FFI semantics.
95    pub(crate) _private: [u8; 0],
96}
97
98/// Opaque OpenHarmony `napi_env` handle from `libace_napi.z.so`.
99#[repr(C)]
100pub struct OhNapiEnv {
101    /// Zero-sized private marker enforcing opaque FFI semantics.
102    pub(crate) _private: [u8; 0],
103}
104
105/// Opaque OpenHarmony `napi_value` handle from `libace_napi.z.so`.
106#[repr(C)]
107pub struct OhNapiValue {
108    /// Zero-sized private marker enforcing opaque FFI semantics.
109    pub(crate) _private: [u8; 0],
110}
111
112/// Opaque OpenHarmony `OH_NativeVSync` handle from `libnative_vsync.so`.
113#[repr(C)]
114pub struct OhNativeVSync {
115    /// Zero-sized private marker enforcing opaque FFI semantics.
116    pub(crate) _private: [u8; 0],
117}
118
119/// POSIX `pollfd` ABI layout used to await OpenHarmony acquire fence FDs before pixel upload.
120#[cfg(target_env = "ohos")]
121#[repr(C)]
122#[derive(Clone, Copy, Debug)]
123pub(crate) struct HarmonyPollFd {
124    /// Acquire sync fence file descriptor.
125    pub(crate) fd: i32,
126    /// Requested poll events (`HARMONY_POLLIN`).
127    pub(crate) events: i16,
128    /// Returned poll events.
129    pub(crate) revents: i16,
130}
131
132/// OpenHarmony `OH_NativeWindow` `BufferHandle` header layout matching `<buffer_handle.h>`.
133#[repr(C)]
134#[derive(Clone, Copy, Debug)]
135pub struct OhBufferHandle {
136    /// Shared memory buffer file descriptor (`-1` if unmapped).
137    pub(crate) fd: i32,
138    /// Physical buffer width in pixels.
139    pub(crate) width: i32,
140    /// Row stride in bytes.
141    pub(crate) stride: i32,
142    /// Physical buffer height in pixels.
143    pub(crate) height: i32,
144    /// Allocated buffer byte size.
145    pub(crate) size: i32,
146    /// Pixel format code (`HARMONY_PIXEL_FMT_RGBA_8888 = 12`).
147    pub(crate) format: i32,
148    /// Buffer usage bitflags.
149    pub(crate) usage: u64,
150    /// Mapped virtual address pointer (`0` when unmapped).
151    pub(crate) vir_addr: usize,
152    /// Physical memory address (`0` when virtual-only).
153    pub(crate) phy_addr: u64,
154}
155
156/// Single damaged rectangle inside OpenHarmony `Region` for `OH_NativeWindow_NativeWindowFlushBuffer`.
157#[repr(C)]
158#[derive(Clone, Copy, Debug, Default)]
159pub struct OhRegionRect {
160    /// Left pixel coordinate.
161    pub(crate) origin_x: i32,
162    /// Top pixel coordinate.
163    pub(crate) origin_y: i32,
164    /// Rectangle width in pixels.
165    pub(crate) width: u32,
166    /// Rectangle height in pixels.
167    pub(crate) height: u32,
168}
169
170/// OpenHarmony `Region` damage descriptor passed to `OH_NativeWindow_NativeWindowFlushBuffer`.
171#[repr(C)]
172#[derive(Clone, Copy, Debug)]
173pub struct OhRegion {
174    /// Pointer to contiguous array of `OhRegionRect` items (null for full-surface damage).
175    pub(crate) rects: *const OhRegionRect,
176    /// Number of rectangles in `rects` (`0` for full-surface flush).
177    pub(crate) rect_number: i32,
178}
179
180/// ABI-compatible OpenHarmony `OH_NativeXComponent_TouchPoint` structure.
181#[repr(C)]
182#[derive(Clone, Copy, Debug, Default)]
183pub struct OhNativeXComponentTouchPoint {
184    /// Hardware touch contact identifier.
185    pub(crate) id: i32,
186    /// Screen-space X coordinate in physical pixels.
187    pub(crate) screen_x: f32,
188    /// Screen-space Y coordinate in physical pixels.
189    pub(crate) screen_y: f32,
190    /// Component-local X coordinate in physical pixels.
191    pub(crate) x: f32,
192    /// Component-local Y coordinate in physical pixels.
193    pub(crate) y: f32,
194    /// Touch action type (`HARMONY_TOUCH_DOWN`..`HARMONY_TOUCH_CANCEL`).
195    pub(crate) touch_type: i32,
196    /// Contact area size.
197    pub(crate) size: f64,
198    /// Normalized touch pressure force.
199    pub(crate) force: f32,
200    /// Monotonic event timestamp in nanoseconds.
201    pub(crate) time_stamp: i64,
202    /// True when this point is the active pressed contact.
203    pub(crate) is_pressed: bool,
204}
205
206/// ABI-compatible OpenHarmony `OH_NativeXComponent_TouchEvent` payload.
207#[repr(C)]
208#[derive(Clone, Copy, Debug)]
209pub struct OhNativeXComponentTouchEvent {
210    /// Active primary contact identifier.
211    pub(crate) id: i32,
212    /// Primary screen-space X coordinate in physical pixels.
213    pub(crate) screen_x: f32,
214    /// Primary screen-space Y coordinate in physical pixels.
215    pub(crate) screen_y: f32,
216    /// Primary component-local X coordinate in physical pixels.
217    pub(crate) x: f32,
218    /// Primary component-local Y coordinate in physical pixels.
219    pub(crate) y: f32,
220    /// Action type (`HARMONY_TOUCH_DOWN`..`HARMONY_TOUCH_CANCEL`).
221    pub(crate) touch_type: i32,
222    /// Contact size.
223    pub(crate) size: f64,
224    /// Contact force.
225    pub(crate) force: f32,
226    /// Input device identifier.
227    pub(crate) device_id: i64,
228    /// Event timestamp in nanoseconds.
229    pub(crate) time_stamp: i64,
230    /// Up to 10 simultaneous multi-touch points matching `OH_MAX_TOUCH_POINTS_NUMBER`.
231    pub(crate) touch_points: [OhNativeXComponentTouchPoint; 10],
232    /// Count of valid entries in `touch_points`.
233    pub(crate) num_points: u32,
234}
235
236/// ABI-compatible OpenHarmony `OH_NativeXComponent_MouseEvent` structure for HarmonyOS PC / Tablet pointer input.
237#[repr(C)]
238#[derive(Clone, Copy, Debug, Default)]
239pub struct OhNativeXComponentMouseEvent {
240    /// Component-local X coordinate in physical pixels.
241    pub(crate) x: f32,
242    /// Component-local Y coordinate in physical pixels.
243    pub(crate) y: f32,
244    /// Screen-space X coordinate in vp.
245    pub(crate) screen_x: f32,
246    /// Screen-space Y coordinate in vp.
247    pub(crate) screen_y: f32,
248    /// Monotonic timestamp in nanoseconds.
249    pub(crate) timestamp: i64,
250    /// Mouse action (`HARMONY_MOUSE_PRESS`..`HARMONY_MOUSE_CANCEL`).
251    pub(crate) action: i32,
252    /// Active button bitmask (`HARMONY_MOUSE_BUTTON_*`).
253    pub(crate) button: i32,
254}
255
256/// ABI-compatible OpenHarmony `OH_NativeXComponent_MouseEvent_Callback` table for PC hover and mouse events.
257#[repr(C)]
258#[derive(Clone, Copy)]
259pub struct OhNativeXComponentMouseCallback {
260    /// Callback fired when a mouse press, release, or drag occurs on the XComponent.
261    pub(crate) dispatch_mouse_event:
262        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
263    /// Callback fired when the pointer enters or exits the XComponent hover region.
264    pub(crate) dispatch_hover_event: Option<unsafe extern "C" fn(*mut OhNativeXComponent, bool)>,
265}
266
267/// ABI-compatible OpenHarmony `OH_NativeXComponent_Callback` table registered with `libace_ndk.z.so`.
268#[repr(C)]
269#[derive(Clone, Copy)]
270pub struct OhNativeXComponentCallback {
271    /// Callback fired when ArkUI attaches a live `OHNativeWindow` surface.
272    pub(crate) on_surface_created:
273        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
274    /// Callback fired when the XComponent surface dimensions change.
275    pub(crate) on_surface_changed:
276        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
277    /// Callback fired before ArkUI destroys the `OHNativeWindow` surface.
278    pub(crate) on_surface_destroyed:
279        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
280    /// Callback fired when ArkUI dispatches a touch event to the XComponent.
281    pub(crate) dispatch_touch_event:
282        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
283}
284
285/// Normalized HarmonyOS `window.AvoidArea` insets combining system bars, camera cutout, gesture bar, and IME.
286#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
287pub struct HarmonyAvoidArea {
288    /// Top status bar / cutout avoid inset in physical pixels.
289    #[get(type(copy))]
290    pub(crate) top_px: u32,
291    /// Right landscape cutout / gesture avoid inset in physical pixels.
292    #[get(type(copy))]
293    pub(crate) right_px: u32,
294    /// Bottom navigation indicator / keyboard avoid inset in physical pixels.
295    #[get(type(copy))]
296    pub(crate) bottom_px: u32,
297    /// Left landscape cutout avoid inset in physical pixels.
298    #[get(type(copy))]
299    pub(crate) left_px: u32,
300    /// Active soft keyboard height in physical pixels (`0` when hidden).
301    #[get(type(copy))]
302    pub(crate) keyboard_px: u32,
303}
304
305/// Device form-factor hardware profile for HarmonyOS / OpenHarmony targets.
306#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
307pub struct HarmonyDeviceProfile {
308    /// Concrete HarmonyOS device category (Phone, Tablet, PC/2-in-1, Foldable, Watch, TV, Automotive).
309    #[get(type(copy))]
310    pub(crate) device_type: HarmonyDeviceType,
311    /// Initial logical viewport width in HarmonyOS `vp`.
312    #[get(type(copy))]
313    pub(crate) logical_width: u32,
314    /// Initial logical viewport height in HarmonyOS `vp`.
315    #[get(type(copy))]
316    pub(crate) logical_height: u32,
317    /// Display density scaling `vp -> px`.
318    #[get(type(copy))]
319    pub(crate) density: f32,
320    /// Uncapped hardware display refresh rate in Hertz reported by `OH_NativeVSync` or the device profile.
321    #[get(type(copy))]
322    pub(crate) refresh_rate_hz: f32,
323    /// Preferred native graphics API (`Vulkan`, `OpenGlEs3`, or `SoftwareBuffer`).
324    #[get(type(copy))]
325    pub(crate) graphics_api: HarmonyGraphicsApi,
326}
327
328/// Live ArkUI XComponent window record held by `HarmonyPlatform`.
329#[derive(Clone, Data, Debug)]
330pub struct HarmonyWindowRecord {
331    /// Window configuration snapshot.
332    pub(crate) config: WindowConfig,
333    /// Live window state with safe-area and display refresh metadata.
334    #[get(type(copy))]
335    pub(crate) state: WindowState,
336    /// ArkUI `<XComponent>` instance identifier string.
337    pub(crate) xcomponent_id: String,
338    /// Attached `OHNativeWindow*` raw pointer (`0` before `onSurfaceCreated` or after teardown).
339    #[get(type(copy))]
340    pub(crate) native_window: usize,
341    /// Attached `OH_NativeXComponent*` raw pointer (`0` when running offscreen/simulated).
342    #[get(type(copy))]
343    pub(crate) xcomponent: usize,
344    /// Active graphics API driving this XComponent surface.
345    #[get(type(copy))]
346    pub(crate) graphics_api: HarmonyGraphicsApi,
347    /// Cached surface pixel width to avoid redundant `SET_BUFFER_GEOMETRY` calls.
348    #[get(type(copy))]
349    pub(crate) surface_width: u32,
350    /// Cached surface pixel height.
351    #[get(type(copy))]
352    pub(crate) surface_height: u32,
353    /// Last presented RGBA8 framebuffer snapshot.
354    pub(crate) last_frame: Framebuffer,
355    /// Total frames presented to this XComponent surface.
356    #[get(type(copy))]
357    pub(crate) present_count: u64,
358}
359
360/// Unified HarmonyOS / OpenHarmony platform backend bridging ArkUI XComponent, `OHNativeWindow`, EGL/GLES3/Vulkan, and NAPI.
361#[derive(Clone, Data, Debug)]
362pub struct HarmonyPlatform {
363    /// Active HarmonyOS device form-factor profile.
364    #[get(type(copy))]
365    pub(crate) profile: HarmonyDeviceProfile,
366    /// Active foldable hinge posture (relevant when `device_type == HarmonyDeviceType::Foldable`).
367    #[get(type(copy))]
368    pub(crate) fold_state: HarmonyFoldState,
369    /// Active Stage-Model window mode (`Floating` / `Maximized` / `Fullscreen` / `Split*` on HarmonyOS PC & Tablet).
370    #[get(type(copy))]
371    pub(crate) window_mode: HarmonyWindowMode,
372    /// Tracked physical keyboard modifiers (`Shift` / `Ctrl` / `Alt` / `Meta`) for HarmonyOS PC shortcuts.
373    #[get(type(copy))]
374    pub(crate) active_modifiers: Modifiers,
375    /// Last applied desktop cursor icon hint for HarmonyOS PC pointer synchronization.
376    #[get(type(copy))]
377    pub(crate) last_cursor: CursorIcon,
378    /// Outbound ArkTS / N-API host bridge commands drained after frame and window updates.
379    pub(crate) outbound_commands: Vec<HarmonyHostCommand>,
380    /// Active `OHNativeWindow*` pointer attached by ArkUI XComponent.
381    #[get(type(copy))]
382    pub(crate) attached_native_window: usize,
383    /// Active `OH_NativeXComponent*` pointer attached by NAPI `Init`.
384    #[get(type(copy))]
385    pub(crate) attached_xcomponent: usize,
386    /// Latest resolved `SafeAreaInsets` in logical `vp`.
387    #[get(type(copy))]
388    pub(crate) safe_area: SafeAreaInsets,
389    /// Generation-stamped mobile/ability lifecycle coordinator preventing exit/re-entry races.
390    pub(crate) lifecycle: MobileSessionLifecycle,
391    /// Monotonic window identifier allocator.
392    #[get(pub(crate), type(copy))]
393    #[get_mut(pub(crate))]
394    #[set(pub(crate))]
395    pub(crate) next_id: u64,
396    /// Primary XComponent window handle, if created.
397    #[get(skip)]
398    pub(crate) primary_window: Option<WindowId>,
399    /// Active HarmonyOS windows indexed by `WindowId`.
400    pub(crate) windows: HashMap<WindowId, HarmonyWindowRecord>,
401    /// Queued normalized `WindowEvent` and `SystemEvent`s awaiting `poll_events()`.
402    pub(crate) pending_events: Vec<WindowEvent>,
403    /// Cached system pasteboard UTF-8 text.
404    #[get(skip)]
405    pub(crate) clipboard: Option<String>,
406    /// In-memory sandbox `preferences` / `KVStore` storage backing `PlatformStorage`.
407    pub(crate) storage: HashMap<String, String>,
408    /// Logical ArkUI router navigation stack backing `PlatformNavigation`.
409    pub(crate) route_stack: Vec<String>,
410    /// Active OS light/dark appearance mode.
411    #[get(type(copy))]
412    pub(crate) theme: ThemeMode,
413    /// Whether the HarmonyOS VSync (`OH_NativeVSync`) frame pump is currently paused for background freeze.
414    #[get(type(copy))]
415    pub(crate) pump_paused: bool,
416    /// Whether `present_framebuffer` retains a cloned RGBA8 snapshot for diagnostic inspection (default `false`).
417    #[get(type(copy))]
418    pub(crate) capture_last_frame: bool,
419    /// Active `OH_NativeVSync*` handle allocated by `libnative_vsync.so` (`0` when running off-device).
420    #[get(type(copy))]
421    pub(crate) vsync_handle: usize,
422    /// Timestamp in nanoseconds of the previous `OH_NativeVSync` callback for live Hz estimation.
423    #[get(type(copy))]
424    pub(crate) last_vsync_timestamp_ns: i64,
425}