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::*;

/// Win32 `RECT` ABI struct for `AdjustWindowRectEx` and `GetClientRect`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct Win32Rect {
    /// Left X coordinate.
    pub(crate) left: i32,
    /// Top Y coordinate.
    pub(crate) top: i32,
    /// Right X coordinate.
    pub(crate) right: i32,
    /// Bottom Y coordinate.
    pub(crate) bottom: i32,
}

/// Queued Win32 window event tagging its source `HWND`.
#[derive(Clone, Copy, Debug)]
pub(crate) struct Win32QueuedEvent {
    /// Originating Win32 `HWND`.
    pub(crate) hwnd: usize,
    /// Translated event payload.
    pub(crate) payload: Win32EventPayload,
}

/// Win32 `WNDCLASSEXW` ABI struct.
#[repr(C)]
pub(crate) struct WndClassExW {
    /// Structure byte size.
    pub(crate) cb_size: u32,
    /// Class style flags.
    pub(crate) style: u32,
    /// Window procedure function pointer.
    pub(crate) lpfn_wnd_proc: unsafe extern "system" fn(isize, u32, usize, isize) -> isize,
    /// Extra class bytes.
    pub(crate) cb_cls_extra: i32,
    /// Extra window bytes.
    pub(crate) cb_wnd_extra: i32,
    /// Module instance handle.
    pub(crate) h_instance: isize,
    /// Class icon handle.
    pub(crate) h_icon: isize,
    /// Class cursor handle.
    pub(crate) h_cursor: isize,
    /// Background brush handle.
    pub(crate) hbr_background: isize,
    /// Optional menu name.
    pub(crate) lpsz_menu_name: *const u16,
    /// Wide class name pointer.
    pub(crate) lpsz_class_name: *const u16,
    /// Small icon handle.
    pub(crate) h_icon_sm: isize,
}

/// Win32 `BITMAPINFOHEADER` ABI struct for `StretchDIBits`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct BitmapInfoHeader {
    /// Header size in bytes (`40`).
    pub(crate) bi_size: u32,
    /// Image width in pixels.
    pub(crate) bi_width: i32,
    /// Negative height indicates top-down scanline order.
    pub(crate) bi_height: i32,
    /// Color planes (`1`).
    pub(crate) bi_planes: u16,
    /// Bits per pixel (`32`).
    pub(crate) bi_bit_count: u16,
    /// Compression format (`BI_RGB`).
    pub(crate) bi_compression: u32,
    /// Image size in bytes.
    pub(crate) bi_size_image: u32,
    /// Horizontal pixels per meter.
    pub(crate) bi_x_pels_per_meter: i32,
    /// Vertical pixels per meter.
    pub(crate) bi_y_pels_per_meter: i32,
    /// Used palette colors.
    pub(crate) bi_clr_used: u32,
    /// Important palette colors.
    pub(crate) bi_clr_important: u32,
}

/// Win32 `BITMAPINFO` wrapper struct.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct BitmapInfo {
    /// Header specification.
    pub(crate) header: BitmapInfoHeader,
    /// Single color entry placeholder.
    pub(crate) colors: [u32; 1],
}

/// Win32 `SYSTEM_POWER_STATUS` ABI struct for `GetSystemPowerStatus`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct Win32SystemPowerStatus {
    /// AC power status (`0` = offline, `1` = online, `255` = unknown).
    pub(crate) ac_line_status: u8,
    /// Battery charge flag bitmask.
    pub(crate) battery_flag: u8,
    /// Percentage of full battery charge remaining (`0..=100`, `255` = unknown).
    pub(crate) battery_life_percent: u8,
    /// Battery saver status (`1` = Battery Saver active on Windows 10+).
    pub(crate) system_status_flag: u8,
    /// Remaining battery lifetime in seconds (`u32::MAX` = unknown).
    pub(crate) battery_life_time: u32,
    /// Full battery lifetime in seconds (`u32::MAX` = unknown).
    pub(crate) battery_full_life_time: u32,
}

/// Win32 `MSG` ABI struct.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct Win32Msg {
    /// Target window handle.
    pub(crate) hwnd: isize,
    /// Message identifier.
    pub(crate) message: u32,
    /// Word parameter.
    pub(crate) w_param: usize,
    /// Long parameter.
    pub(crate) l_param: isize,
    /// Timestamp.
    pub(crate) time: u32,
    /// Cursor X.
    pub(crate) pt_x: i32,
    /// Cursor Y.
    pub(crate) pt_y: i32,
}

/// Win32 `MONITORINFOEXW` ABI struct for per-monitor bounds and device name lookup.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub(crate) struct Win32MonitorInfoExW {
    /// Structure size in bytes (`size_of::<Win32MonitorInfoExW>()`).
    pub(crate) cb_size: u32,
    /// Full physical monitor rectangle in virtual-screen coordinates.
    pub(crate) rc_monitor: Win32Rect,
    /// Monitor work-area rectangle excluding taskbar.
    pub(crate) rc_work: Win32Rect,
    /// Monitor flags (`MONITORINFOF_PRIMARY = 1`).
    pub(crate) dw_flags: u32,
    /// Null-terminated UTF-16 GDI display device name (e.g. `\\.\DISPLAY1`).
    pub(crate) sz_device: [u16; 32],
}

/// Win32 `DEVMODEW` ABI struct (`220` bytes) for per-monitor `EnumDisplaySettingsW(ENUM_CURRENT_SETTINGS)`.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub(crate) struct Win32DevModeW {
    /// UTF-16 device name.
    pub(crate) dm_device_name: [u16; 32],
    /// Specification version.
    pub(crate) dm_spec_version: u16,
    /// Driver version.
    pub(crate) dm_driver_version: u16,
    /// Structure byte size (`220`).
    pub(crate) dm_size: u16,
    /// Extra private driver bytes.
    pub(crate) dm_driver_extra: u16,
    /// Active field bitmask.
    pub(crate) dm_fields: u32,
    /// Display position/orientation union words (`16` bytes).
    pub(crate) dm_position_and_orientation: [u32; 4],
    /// Printer color mode.
    pub(crate) dm_color: i16,
    /// Printer duplex mode.
    pub(crate) dm_duplex: i16,
    /// Printer Y resolution.
    pub(crate) dm_y_resolution: i16,
    /// TrueType option.
    pub(crate) dm_tt_option: i16,
    /// Collate setting.
    pub(crate) dm_collate: i16,
    /// UTF-16 form name.
    pub(crate) dm_form_name: [u16; 32],
    /// Logical pixels per inch.
    pub(crate) dm_log_pixels: u16,
    /// Color depth in bits per pixel.
    pub(crate) dm_bits_per_pel: u32,
    /// Active horizontal resolution in pixels.
    pub(crate) dm_pels_width: u32,
    /// Active vertical resolution in pixels.
    pub(crate) dm_pels_height: u32,
    /// Display flags (`DM_GRAYSCALE` / `DM_INTERLACED`).
    pub(crate) dm_display_flags: u32,
    /// Active vertical refresh rate in Hertz (`60`, `144`, `240`, `360`, `480`, ...).
    pub(crate) dm_display_frequency: u32,
    /// ICM method.
    pub(crate) dm_icm_method: u32,
    /// ICM intent.
    pub(crate) dm_icm_intent: u32,
    /// Media type.
    pub(crate) dm_media_type: u32,
    /// Dither type.
    pub(crate) dm_dither_type: u32,
    /// Reserved word 1.
    pub(crate) dm_reserved1: u32,
    /// Reserved word 2.
    pub(crate) dm_reserved2: u32,
    /// Panning width.
    pub(crate) dm_panning_width: u32,
    /// Panning height.
    pub(crate) dm_panning_height: u32,
}

/// Win32 `WINDOWPLACEMENT` ABI struct used to save and restore windowed bounds across borderless fullscreen.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct Win32WindowPlacement {
    /// Structure size in bytes (`44`).
    pub(crate) length: u32,
    /// Placement flags.
    pub(crate) flags: u32,
    /// Show state (`SW_SHOWNORMAL`, `SW_SHOWMAXIMIZED`, etc.).
    pub(crate) show_cmd: u32,
    /// Minimized upper-left corner coordinates.
    pub(crate) pt_min_position: [i32; 2],
    /// Maximized upper-left corner coordinates.
    pub(crate) pt_max_position: [i32; 2],
    /// Restored windowed bounding rectangle.
    pub(crate) rc_normal_position: Win32Rect,
}

/// D3D12 / DXGI waitable swapchain configuration descriptor probed for low-latency high-Hz presentation.
#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
pub struct Win32DxgiSwapChainConfig {
    /// Whether `dxgi.dll` DXGI 1.6 waitable swapchain creation is available.
    #[get(type(copy))]
    pub(crate) dxgi_available: bool,
    /// Whether `DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING` / VRR tearing present is enabled.
    #[get(type(copy))]
    pub(crate) allow_tearing: bool,
    /// Swapchain creation flags (`FRAME_LATENCY_WAITABLE_OBJECT | ALLOW_TEARING`).
    #[get(type(copy))]
    pub(crate) swap_chain_flags: u32,
    /// `IDXGISwapChain::Present` flags (`DXGI_PRESENT_ALLOW_TEARING` when tearing unlocked).
    #[get(type(copy))]
    pub(crate) present_flags: u32,
}

/// Explicit per-frame Windows presentation telemetry separating DXGI/D3D direct GPU swapchain present from GDI software fallback.
#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
pub struct WindowsPresentTelemetry {
    /// Active presentation path (`GpuDirect` vs `SoftwareGdi`).
    #[get(type(copy))]
    pub(crate) path: WindowsPresentationPath,
    /// Explicit CPU-mirror telemetry flag (`false` for `GpuDirect`; `true` for `SoftwareGdi`).
    #[get(type(copy))]
    pub(crate) cpu_mirror_active: bool,
    /// Truthful timing source (`DxgiFrameStatistics` vs `SubmissionProxy` vs `Unobservable`).
    #[get(type(copy))]
    pub(crate) timing_source: WindowsPresentTimingSource,
    /// Last `DXGI_FRAME_STATISTICS.SyncQPCTime` tick observed (`0` on GDI fallback or unobservable).
    #[get(type(copy))]
    pub(crate) dxgi_sync_qpc_time: u64,
    /// Last `DXGI_FRAME_STATISTICS.PresentCount` observed (`0` on GDI fallback).
    #[get(type(copy))]
    pub(crate) dxgi_present_count: u32,
    /// Exact BGRA8 bytes uploaded via GDI `StretchDIBits` (`0` for `GpuDirect` or unchanged skip).
    #[get(type(copy))]
    pub(crate) upload_bytes: u64,
    /// Number of dirty rectangles blitted on this frame.
    #[get(type(copy))]
    pub(crate) dirty_rect_count: u32,
    /// Cumulative frames presented directly through native DXGI GPU swapchain.
    #[get(type(copy))]
    pub(crate) direct_gpu_frames: u64,
    /// Cumulative frames presented through GDI software fallback.
    #[get(type(copy))]
    pub(crate) software_fallback_frames: u64,
    /// Cumulative failed presentation attempts.
    #[get(type(copy))]
    pub(crate) failed_frames: u64,
}

/// Native Win32 window record storing `HWND`, `HINSTANCE`, reveal state, fullscreen geometry, and GPU/GDI telemetry.
#[derive(Clone, Data, Debug)]
pub struct WindowsWindowRecord {
    /// Window configuration.
    pub(crate) config: WindowConfig,
    /// Live window state and DPI metrics.
    #[get(type(copy))]
    pub(crate) state: WindowState,
    /// Win32 `HWND`.
    #[get(type(copy))]
    pub(crate) hwnd: usize,
    /// Win32 `HINSTANCE`.
    #[get(type(copy))]
    pub(crate) hinstance: usize,
    /// Whether `ShowWindow(hwnd, SW_SHOW)` has been called after Frame 1 presentation.
    #[get(type(copy))]
    pub(crate) revealed: bool,
    /// Saved pre-fullscreen Win32 style bitmask (`GWL_STYLE`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) saved_window_style: i32,
    /// Saved pre-fullscreen `WINDOWPLACEMENT` for exact windowed restoration.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) saved_placement: Win32WindowPlacement,
    /// Probed D3D12/DXGI waitable swapchain configuration for this window.
    #[get(type(copy))]
    pub(crate) dxgi_config: Win32DxgiSwapChainConfig,
    /// Active presentation path (`GpuDirect` on DXGI swapchain or `SoftwareGdi` fallback).
    #[get(type(copy))]
    pub(crate) presentation_path: WindowsPresentationPath,
    /// Explicit CPU-mirror telemetry flag (`false` on `GpuDirect`; `true` on `SoftwareGdi`).
    #[get(type(copy))]
    pub(crate) cpu_mirror_active: bool,
    /// Most recent Windows presentation telemetry snapshot.
    #[get(type(copy))]
    pub(crate) last_telemetry: WindowsPresentTelemetry,
}

/// Direct Windows Win32 / GDI32 / Direct3D platform backend.
#[derive(Clone, Data, Debug)]
pub struct WindowsPlatform {
    /// Monotonic window handle generator.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) next_id: u64,
    /// Whether the Win32 window class has been registered.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) class_registered: bool,
    /// Active Win32 windows.
    pub(crate) windows: HashMap<WindowId, WindowsWindowRecord>,
    /// Queued window and input events.
    pub(crate) pending_events: Vec<WindowEvent>,
    /// Clipboard cache.
    #[get(skip)]
    pub(crate) clipboard_cache: Option<String>,
    /// Whether the Win32 frame pump is paused for background freeze.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) pump_paused: bool,
}