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