euv-core 0.48.3

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
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) x: i32,
    /// Top pixel coordinate.
    pub(crate) y: i32,
    /// Rectangle width in pixels.
    pub(crate) w: u32,
    /// Rectangle height in pixels.
    pub(crate) h: 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_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 `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,
}