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) x: i32,
162    /// Top pixel coordinate.
163    pub(crate) y: i32,
164    /// Rectangle width in pixels.
165    pub(crate) w: u32,
166    /// Rectangle height in pixels.
167    pub(crate) h: 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_Callback` table registered with `libace_ndk.z.so`.
237#[repr(C)]
238#[derive(Clone, Copy)]
239pub struct OhNativeXComponentCallback {
240    /// Callback fired when ArkUI attaches a live `OHNativeWindow` surface.
241    pub(crate) on_surface_created:
242        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
243    /// Callback fired when the XComponent surface dimensions change.
244    pub(crate) on_surface_changed:
245        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
246    /// Callback fired before ArkUI destroys the `OHNativeWindow` surface.
247    pub(crate) on_surface_destroyed:
248        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
249    /// Callback fired when ArkUI dispatches a touch event to the XComponent.
250    pub(crate) dispatch_touch_event:
251        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
252}
253
254/// Normalized HarmonyOS `window.AvoidArea` insets combining system bars, camera cutout, gesture bar, and IME.
255#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
256pub struct HarmonyAvoidArea {
257    /// Top status bar / cutout avoid inset in physical pixels.
258    #[get(type(copy))]
259    pub(crate) top_px: u32,
260    /// Right landscape cutout / gesture avoid inset in physical pixels.
261    #[get(type(copy))]
262    pub(crate) right_px: u32,
263    /// Bottom navigation indicator / keyboard avoid inset in physical pixels.
264    #[get(type(copy))]
265    pub(crate) bottom_px: u32,
266    /// Left landscape cutout avoid inset in physical pixels.
267    #[get(type(copy))]
268    pub(crate) left_px: u32,
269    /// Active soft keyboard height in physical pixels (`0` when hidden).
270    #[get(type(copy))]
271    pub(crate) keyboard_px: u32,
272}
273
274/// Device form-factor hardware profile for HarmonyOS / OpenHarmony targets.
275#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
276pub struct HarmonyDeviceProfile {
277    /// Concrete HarmonyOS device category (Phone, Tablet, PC/2-in-1, Foldable, Watch, TV, Automotive).
278    #[get(type(copy))]
279    pub(crate) device_type: HarmonyDeviceType,
280    /// Initial logical viewport width in HarmonyOS `vp`.
281    #[get(type(copy))]
282    pub(crate) logical_width: u32,
283    /// Initial logical viewport height in HarmonyOS `vp`.
284    #[get(type(copy))]
285    pub(crate) logical_height: u32,
286    /// Display density scaling `vp -> px`.
287    #[get(type(copy))]
288    pub(crate) density: f32,
289    /// Preferred hardware refresh rate in Hertz (`60.0` / `90.0` / `120.0`).
290    #[get(type(copy))]
291    pub(crate) refresh_rate_hz: f32,
292    /// Preferred native graphics API (`Vulkan`, `OpenGlEs3`, or `SoftwareBuffer`).
293    #[get(type(copy))]
294    pub(crate) graphics_api: HarmonyGraphicsApi,
295}
296
297/// Live ArkUI XComponent window record held by `HarmonyPlatform`.
298#[derive(Clone, Data, Debug)]
299pub struct HarmonyWindowRecord {
300    /// Window configuration snapshot.
301    pub(crate) config: WindowConfig,
302    /// Live window state with safe-area and display refresh metadata.
303    #[get(type(copy))]
304    pub(crate) state: WindowState,
305    /// ArkUI `<XComponent>` instance identifier string.
306    pub(crate) xcomponent_id: String,
307    /// Attached `OHNativeWindow*` raw pointer (`0` before `onSurfaceCreated` or after teardown).
308    #[get(type(copy))]
309    pub(crate) native_window: usize,
310    /// Attached `OH_NativeXComponent*` raw pointer (`0` when running offscreen/simulated).
311    #[get(type(copy))]
312    pub(crate) xcomponent: usize,
313    /// Active graphics API driving this XComponent surface.
314    #[get(type(copy))]
315    pub(crate) graphics_api: HarmonyGraphicsApi,
316    /// Cached surface pixel width to avoid redundant `SET_BUFFER_GEOMETRY` calls.
317    #[get(type(copy))]
318    pub(crate) surface_width: u32,
319    /// Cached surface pixel height.
320    #[get(type(copy))]
321    pub(crate) surface_height: u32,
322    /// Last presented RGBA8 framebuffer snapshot.
323    pub(crate) last_frame: Framebuffer,
324    /// Total frames presented to this XComponent surface.
325    #[get(type(copy))]
326    pub(crate) present_count: u64,
327}
328
329/// Unified HarmonyOS / OpenHarmony platform backend bridging ArkUI XComponent, `OHNativeWindow`, EGL/GLES3/Vulkan, and NAPI.
330#[derive(Clone, Data, Debug)]
331pub struct HarmonyPlatform {
332    /// Active HarmonyOS device form-factor profile.
333    #[get(type(copy))]
334    pub(crate) profile: HarmonyDeviceProfile,
335    /// Active foldable hinge posture (relevant when `device_type == HarmonyDeviceType::Foldable`).
336    #[get(type(copy))]
337    pub(crate) fold_state: HarmonyFoldState,
338    /// Active `OHNativeWindow*` pointer attached by ArkUI XComponent.
339    #[get(type(copy))]
340    pub(crate) attached_native_window: usize,
341    /// Active `OH_NativeXComponent*` pointer attached by NAPI `Init`.
342    #[get(type(copy))]
343    pub(crate) attached_xcomponent: usize,
344    /// Latest resolved `SafeAreaInsets` in logical `vp`.
345    #[get(type(copy))]
346    pub(crate) safe_area: SafeAreaInsets,
347    /// Generation-stamped mobile/ability lifecycle coordinator preventing exit/re-entry races.
348    pub(crate) lifecycle: MobileSessionLifecycle,
349    /// Monotonic window identifier allocator.
350    #[get(pub(crate), type(copy))]
351    #[get_mut(pub(crate))]
352    #[set(pub(crate))]
353    pub(crate) next_id: u64,
354    /// Primary XComponent window handle, if created.
355    #[get(skip)]
356    pub(crate) primary_window: Option<WindowId>,
357    /// Active HarmonyOS windows indexed by `WindowId`.
358    pub(crate) windows: HashMap<WindowId, HarmonyWindowRecord>,
359    /// Queued normalized `WindowEvent` and `SystemEvent`s awaiting `poll_events()`.
360    pub(crate) pending_events: Vec<WindowEvent>,
361    /// Cached system pasteboard UTF-8 text.
362    #[get(skip)]
363    pub(crate) clipboard: Option<String>,
364    /// In-memory sandbox `preferences` / `KVStore` storage backing `PlatformStorage`.
365    pub(crate) storage: HashMap<String, String>,
366    /// Logical ArkUI router navigation stack backing `PlatformNavigation`.
367    pub(crate) route_stack: Vec<String>,
368    /// Active OS light/dark appearance mode.
369    #[get(type(copy))]
370    pub(crate) theme: ThemeMode,
371    /// Whether the HarmonyOS VSync (`OH_NativeVSync`) frame pump is currently paused for background freeze.
372    #[get(type(copy))]
373    pub(crate) pump_paused: bool,
374    /// Whether `present_framebuffer` retains a cloned RGBA8 snapshot for diagnostic inspection (default `false`).
375    #[get(type(copy))]
376    pub(crate) capture_last_frame: bool,
377    /// Active `OH_NativeVSync*` handle allocated by `libnative_vsync.so` (`0` when running off-device).
378    #[get(type(copy))]
379    pub(crate) vsync_handle: usize,
380    /// Timestamp in nanoseconds of the previous `OH_NativeVSync` callback for live Hz estimation.
381    #[get(type(copy))]
382    pub(crate) last_vsync_timestamp_ns: i64,
383}