Skip to main content

euv_core/platform/harmony/
struct.rs

1use super::*;
2
3/// Opaque OpenHarmony `OHNativeWindow` FFI handle from `libnative_window.so`.
4#[repr(C)]
5pub struct OhNativeWindow {
6    /// Zero-sized private marker enforcing opaque FFI semantics.
7    pub(crate) _private: [u8; 0],
8}
9
10/// Opaque OpenHarmony `OH_NativeXComponent` FFI handle from `libace_ndk.z.so`.
11#[repr(C)]
12pub struct OhNativeXComponent {
13    /// Zero-sized private marker enforcing opaque FFI semantics.
14    pub(crate) _private: [u8; 0],
15}
16
17/// Opaque OpenHarmony `OHNativeWindowBuffer` FFI handle returned by `OH_NativeWindow_NativeWindowRequestBuffer`.
18#[repr(C)]
19pub struct OhNativeWindowBuffer {
20    /// Zero-sized private marker enforcing opaque FFI semantics.
21    pub(crate) _private: [u8; 0],
22}
23
24/// Opaque OpenHarmony `napi_env` handle from `libace_napi.z.so`.
25#[repr(C)]
26pub struct OhNapiEnv {
27    /// Zero-sized private marker enforcing opaque FFI semantics.
28    pub(crate) _private: [u8; 0],
29}
30
31/// Opaque OpenHarmony `napi_value` handle from `libace_napi.z.so`.
32#[repr(C)]
33pub struct OhNapiValue {
34    /// Zero-sized private marker enforcing opaque FFI semantics.
35    pub(crate) _private: [u8; 0],
36}
37
38/// Opaque OpenHarmony `OH_NativeVSync` handle from `libnative_vsync.so`.
39#[repr(C)]
40pub struct OhNativeVSync {
41    /// Zero-sized private marker enforcing opaque FFI semantics.
42    pub(crate) _private: [u8; 0],
43}
44
45/// POSIX `pollfd` ABI layout used to await OpenHarmony acquire fence FDs before pixel upload.
46#[cfg(target_env = "ohos")]
47#[repr(C)]
48#[derive(Clone, Copy, Debug)]
49pub(crate) struct HarmonyPollFd {
50    /// Acquire sync fence file descriptor.
51    pub(crate) fd: i32,
52    /// Requested poll events (`HARMONY_POLLIN`).
53    pub(crate) events: i16,
54    /// Returned poll events.
55    pub(crate) revents: i16,
56}
57
58/// OpenHarmony `OH_NativeWindow` `BufferHandle` header layout matching `<buffer_handle.h>`.
59#[repr(C)]
60#[derive(Clone, Copy, Debug)]
61pub struct OhBufferHandle {
62    /// Shared memory buffer file descriptor (`-1` if unmapped).
63    pub(crate) fd: i32,
64    /// Physical buffer width in pixels.
65    pub(crate) width: i32,
66    /// Row stride in bytes.
67    pub(crate) stride: i32,
68    /// Physical buffer height in pixels.
69    pub(crate) height: i32,
70    /// Allocated buffer byte size.
71    pub(crate) size: i32,
72    /// Pixel format code (`HARMONY_PIXEL_FMT_RGBA_8888 = 12`).
73    pub(crate) format: i32,
74    /// Buffer usage bitflags.
75    pub(crate) usage: u64,
76    /// Mapped virtual address pointer (`0` when unmapped).
77    pub(crate) vir_addr: usize,
78    /// Physical memory address (`0` when virtual-only).
79    pub(crate) phy_addr: u64,
80}
81
82/// Single damaged rectangle inside OpenHarmony `Region` for `OH_NativeWindow_NativeWindowFlushBuffer`.
83#[repr(C)]
84#[derive(Clone, Copy, Debug, Default)]
85pub struct OhRegionRect {
86    /// Left pixel coordinate.
87    pub(crate) x: i32,
88    /// Top pixel coordinate.
89    pub(crate) y: i32,
90    /// Rectangle width in pixels.
91    pub(crate) w: u32,
92    /// Rectangle height in pixels.
93    pub(crate) h: u32,
94}
95
96/// OpenHarmony `Region` damage descriptor passed to `OH_NativeWindow_NativeWindowFlushBuffer`.
97#[repr(C)]
98#[derive(Clone, Copy, Debug)]
99pub struct OhRegion {
100    /// Pointer to contiguous array of `OhRegionRect` items (null for full-surface damage).
101    pub(crate) rects: *const OhRegionRect,
102    /// Number of rectangles in `rects` (`0` for full-surface flush).
103    pub(crate) rect_number: i32,
104}
105
106/// ABI-compatible OpenHarmony `OH_NativeXComponent_TouchPoint` structure.
107#[repr(C)]
108#[derive(Clone, Copy, Debug, Default)]
109pub struct OhNativeXComponentTouchPoint {
110    /// Hardware touch contact identifier.
111    pub(crate) id: i32,
112    /// Screen-space X coordinate in physical pixels.
113    pub(crate) screen_x: f32,
114    /// Screen-space Y coordinate in physical pixels.
115    pub(crate) screen_y: f32,
116    /// Component-local X coordinate in physical pixels.
117    pub(crate) x: f32,
118    /// Component-local Y coordinate in physical pixels.
119    pub(crate) y: f32,
120    /// Touch action type (`HARMONY_TOUCH_DOWN`..`HARMONY_TOUCH_CANCEL`).
121    pub(crate) touch_type: i32,
122    /// Contact area size.
123    pub(crate) size: f64,
124    /// Normalized touch pressure force.
125    pub(crate) force: f32,
126    /// Monotonic event timestamp in nanoseconds.
127    pub(crate) time_stamp: i64,
128    /// True when this point is the active pressed contact.
129    pub(crate) is_pressed: bool,
130}
131
132/// ABI-compatible OpenHarmony `OH_NativeXComponent_TouchEvent` payload.
133#[repr(C)]
134#[derive(Clone, Copy, Debug)]
135pub struct OhNativeXComponentTouchEvent {
136    /// Active primary contact identifier.
137    pub(crate) id: i32,
138    /// Primary screen-space X coordinate in physical pixels.
139    pub(crate) screen_x: f32,
140    /// Primary screen-space Y coordinate in physical pixels.
141    pub(crate) screen_y: f32,
142    /// Primary component-local X coordinate in physical pixels.
143    pub(crate) x: f32,
144    /// Primary component-local Y coordinate in physical pixels.
145    pub(crate) y: f32,
146    /// Action type (`HARMONY_TOUCH_DOWN`..`HARMONY_TOUCH_CANCEL`).
147    pub(crate) touch_type: i32,
148    /// Contact size.
149    pub(crate) size: f64,
150    /// Contact force.
151    pub(crate) force: f32,
152    /// Input device identifier.
153    pub(crate) device_id: i64,
154    /// Event timestamp in nanoseconds.
155    pub(crate) time_stamp: i64,
156    /// Up to 10 simultaneous multi-touch points matching `OH_MAX_TOUCH_POINTS_NUMBER`.
157    pub(crate) touch_points: [OhNativeXComponentTouchPoint; 10],
158    /// Count of valid entries in `touch_points`.
159    pub(crate) num_points: u32,
160}
161
162/// ABI-compatible OpenHarmony `OH_NativeXComponent_Callback` table registered with `libace_ndk.z.so`.
163#[repr(C)]
164#[derive(Clone, Copy)]
165pub struct OhNativeXComponentCallback {
166    /// Callback fired when ArkUI attaches a live `OHNativeWindow` surface.
167    pub(crate) on_surface_created:
168        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
169    /// Callback fired when the XComponent surface dimensions change.
170    pub(crate) on_surface_changed:
171        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
172    /// Callback fired before ArkUI destroys the `OHNativeWindow` surface.
173    pub(crate) on_surface_destroyed:
174        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
175    /// Callback fired when ArkUI dispatches a touch event to the XComponent.
176    pub(crate) dispatch_touch_event:
177        Option<unsafe extern "C" fn(*mut OhNativeXComponent, *mut OhNativeWindow)>,
178}
179
180/// Normalized HarmonyOS `window.AvoidArea` insets combining system bars, camera cutout, gesture bar, and IME.
181#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
182pub struct HarmonyAvoidArea {
183    /// Top status bar / cutout avoid inset in physical pixels.
184    #[get(type(copy))]
185    pub(crate) top_px: u32,
186    /// Right landscape cutout / gesture avoid inset in physical pixels.
187    #[get(type(copy))]
188    pub(crate) right_px: u32,
189    /// Bottom navigation indicator / keyboard avoid inset in physical pixels.
190    #[get(type(copy))]
191    pub(crate) bottom_px: u32,
192    /// Left landscape cutout avoid inset in physical pixels.
193    #[get(type(copy))]
194    pub(crate) left_px: u32,
195    /// Active soft keyboard height in physical pixels (`0` when hidden).
196    #[get(type(copy))]
197    pub(crate) keyboard_px: u32,
198}
199
200/// Device form-factor hardware profile for HarmonyOS / OpenHarmony targets.
201#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
202pub struct HarmonyDeviceProfile {
203    /// Concrete HarmonyOS device category (Phone, Tablet, PC/2-in-1, Foldable, Watch, TV, Automotive).
204    #[get(type(copy))]
205    pub(crate) device_type: HarmonyDeviceType,
206    /// Initial logical viewport width in HarmonyOS `vp`.
207    #[get(type(copy))]
208    pub(crate) logical_width: u32,
209    /// Initial logical viewport height in HarmonyOS `vp`.
210    #[get(type(copy))]
211    pub(crate) logical_height: u32,
212    /// Display density scaling `vp -> px`.
213    #[get(type(copy))]
214    pub(crate) density: f32,
215    /// Preferred hardware refresh rate in Hertz (`60.0` / `90.0` / `120.0`).
216    #[get(type(copy))]
217    pub(crate) refresh_rate_hz: f32,
218    /// Preferred native graphics API (`Vulkan`, `OpenGlEs3`, or `SoftwareBuffer`).
219    #[get(type(copy))]
220    pub(crate) graphics_api: HarmonyGraphicsApi,
221}
222
223/// Live ArkUI XComponent window record held by `HarmonyPlatform`.
224#[derive(Clone, Data, Debug)]
225pub struct HarmonyWindowRecord {
226    /// Window configuration snapshot.
227    pub(crate) config: WindowConfig,
228    /// Live window state with safe-area and display refresh metadata.
229    #[get(type(copy))]
230    pub(crate) state: WindowState,
231    /// ArkUI `<XComponent>` instance identifier string.
232    pub(crate) xcomponent_id: String,
233    /// Attached `OHNativeWindow*` raw pointer (`0` before `onSurfaceCreated` or after teardown).
234    #[get(type(copy))]
235    pub(crate) native_window: usize,
236    /// Attached `OH_NativeXComponent*` raw pointer (`0` when running offscreen/simulated).
237    #[get(type(copy))]
238    pub(crate) xcomponent: usize,
239    /// Active graphics API driving this XComponent surface.
240    #[get(type(copy))]
241    pub(crate) graphics_api: HarmonyGraphicsApi,
242    /// Cached surface pixel width to avoid redundant `SET_BUFFER_GEOMETRY` calls.
243    #[get(type(copy))]
244    pub(crate) surface_width: u32,
245    /// Cached surface pixel height.
246    #[get(type(copy))]
247    pub(crate) surface_height: u32,
248    /// Last presented RGBA8 framebuffer snapshot.
249    pub(crate) last_frame: Framebuffer,
250    /// Total frames presented to this XComponent surface.
251    #[get(type(copy))]
252    pub(crate) present_count: u64,
253}
254
255/// Unified HarmonyOS / OpenHarmony platform backend bridging ArkUI XComponent, `OHNativeWindow`, EGL/GLES3/Vulkan, and NAPI.
256#[derive(Clone, Data, Debug)]
257pub struct HarmonyPlatform {
258    /// Active HarmonyOS device form-factor profile.
259    #[get(type(copy))]
260    pub(crate) profile: HarmonyDeviceProfile,
261    /// Active foldable hinge posture (relevant when `device_type == HarmonyDeviceType::Foldable`).
262    #[get(type(copy))]
263    pub(crate) fold_state: HarmonyFoldState,
264    /// Active `OHNativeWindow*` pointer attached by ArkUI XComponent.
265    #[get(type(copy))]
266    pub(crate) attached_native_window: usize,
267    /// Active `OH_NativeXComponent*` pointer attached by NAPI `Init`.
268    #[get(type(copy))]
269    pub(crate) attached_xcomponent: usize,
270    /// Latest resolved `SafeAreaInsets` in logical `vp`.
271    #[get(type(copy))]
272    pub(crate) safe_area: SafeAreaInsets,
273    /// Generation-stamped mobile/ability lifecycle coordinator preventing exit/re-entry races.
274    pub(crate) lifecycle: MobileSessionLifecycle,
275    /// Monotonic window identifier allocator.
276    #[get(pub(crate), type(copy))]
277    #[get_mut(pub(crate))]
278    #[set(pub(crate))]
279    pub(crate) next_id: u64,
280    /// Primary XComponent window handle, if created.
281    #[get(skip)]
282    pub(crate) primary_window: Option<WindowId>,
283    /// Active HarmonyOS windows indexed by `WindowId`.
284    pub(crate) windows: HashMap<WindowId, HarmonyWindowRecord>,
285    /// Queued normalized `WindowEvent` and `SystemEvent`s awaiting `poll_events()`.
286    pub(crate) pending_events: Vec<WindowEvent>,
287    /// Cached system pasteboard UTF-8 text.
288    #[get(skip)]
289    pub(crate) clipboard: Option<String>,
290    /// In-memory sandbox `preferences` / `KVStore` storage backing `PlatformStorage`.
291    pub(crate) storage: HashMap<String, String>,
292    /// Logical ArkUI router navigation stack backing `PlatformNavigation`.
293    pub(crate) route_stack: Vec<String>,
294    /// Active OS light/dark appearance mode.
295    #[get(type(copy))]
296    pub(crate) theme: ThemeMode,
297    /// Whether the HarmonyOS VSync (`OH_NativeVSync`) frame pump is currently paused for background freeze.
298    #[get(type(copy))]
299    pub(crate) pump_paused: bool,
300    /// Whether `present_framebuffer` retains a cloned RGBA8 snapshot for diagnostic inspection (default `false`).
301    #[get(type(copy))]
302    pub(crate) capture_last_frame: bool,
303    /// Active `OH_NativeVSync*` handle allocated by `libnative_vsync.so` (`0` when running off-device).
304    #[get(type(copy))]
305    pub(crate) vsync_handle: usize,
306    /// Timestamp in nanoseconds of the previous `OH_NativeVSync` callback for live Hz estimation.
307    #[get(type(copy))]
308    pub(crate) last_vsync_timestamp_ns: i64,
309}