diff options
| author | Valentin Popov <valentin@popov.link> | 2026-06-23 22:42:20 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-06-23 22:42:20 +0300 |
| commit | c71e706d6969f516152142bbeebf5f836d38db9b (patch) | |
| tree | 0ba128f72c476959205666fc3ab9c8a4e263ec10 /adapters | |
| parent | aa2133d82b2a9d92fdbdce2b60eec103536fe484 (diff) | |
| download | fparkan-c71e706d6969f516152142bbeebf5f836d38db9b.tar.xz fparkan-c71e706d6969f516152142bbeebf5f836d38db9b.zip | |
feat: add native smoke window preflight
Diffstat (limited to 'adapters')
| -rw-r--r-- | adapters/fparkan-platform-winit/src/lib.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/adapters/fparkan-platform-winit/src/lib.rs b/adapters/fparkan-platform-winit/src/lib.rs index 9a9941c..d8efa3e 100644 --- a/adapters/fparkan-platform-winit/src/lib.rs +++ b/adapters/fparkan-platform-winit/src/lib.rs @@ -33,6 +33,8 @@ use winit::platform::scancode::PhysicalKeyExtScancode; use winit::window::Window; static NEXT_WINDOW_HANDLE_ID: AtomicU64 = AtomicU64::new(1); +const DEFAULT_SMOKE_WIDTH: u32 = 1280; +const DEFAULT_SMOKE_HEIGHT: u32 = 720; fn next_window_id() -> u64 { NEXT_WINDOW_HANDLE_ID.fetch_add(1, Ordering::Relaxed) @@ -144,6 +146,44 @@ impl EventSource for WinitEventSource { } } +/// Window creation plan for native smoke entrypoints. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct WinitWindowPlan { + /// Requested drawable width in physical pixels. + pub width: u32, + /// Requested drawable height in physical pixels. + pub height: u32, + /// Whether native window/display handles are required by the caller. + pub requires_native_handles: bool, +} + +impl WinitWindowPlan { + /// Returns the Stage 0 native smoke window plan. + #[must_use] + pub const fn smoke() -> Self { + Self { + width: DEFAULT_SMOKE_WIDTH, + height: DEFAULT_SMOKE_HEIGHT, + requires_native_handles: true, + } + } + + /// Validates the window plan before a native event loop is entered. + /// + /// # Errors + /// + /// Returns [`PlatformError`] when the drawable extent is zero. + pub fn validate(self) -> Result<Self, PlatformError> { + if self.width == 0 || self.height == 0 { + return Err(PlatformError::Backend { + context: "winit window plan", + message: "drawable extent must be non-zero".to_string(), + }); + } + Ok(self) + } +} + /// Minimal window view over a `winit` window. #[derive(Clone, Debug)] pub struct WinitWindow { @@ -277,6 +317,33 @@ mod tests { } #[test] + fn smoke_window_plan_requires_native_handles_and_nonzero_extent() -> Result<(), PlatformError> { + let plan = WinitWindowPlan::smoke().validate()?; + + assert_eq!(plan.width, DEFAULT_SMOKE_WIDTH); + assert_eq!(plan.height, DEFAULT_SMOKE_HEIGHT); + assert!(plan.requires_native_handles); + Ok(()) + } + + #[test] + fn smoke_window_plan_rejects_zero_extent() { + let plan = WinitWindowPlan { + width: 0, + height: DEFAULT_SMOKE_HEIGHT, + requires_native_handles: true, + }; + + assert!(matches!( + plan.validate(), + Err(PlatformError::Backend { + context: "winit window plan", + .. + }) + )); + } + + #[test] fn window_events_push_expected_platform_events() { let mut source = WinitEventSource::new(); let size = winit::dpi::PhysicalSize::new(1024u32, 768u32); |
