feat: expose native window handles

This commit is contained in:
2026-06-23 22:50:32 +04:00
parent dc7e72961a
commit a0a4089e4b
7 changed files with 42 additions and 2 deletions
Generated
+4
View File
@@ -642,12 +642,16 @@ version = "0.1.0"
[[package]] [[package]]
name = "fparkan-platform" name = "fparkan-platform"
version = "0.1.0" version = "0.1.0"
dependencies = [
"raw-window-handle",
]
[[package]] [[package]]
name = "fparkan-platform-winit" name = "fparkan-platform-winit"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"fparkan-platform", "fparkan-platform",
"raw-window-handle",
"winit", "winit",
] ]
@@ -7,6 +7,7 @@ repository.workspace = true
[dependencies] [dependencies]
fparkan-platform = { path = "../../crates/fparkan-platform" } fparkan-platform = { path = "../../crates/fparkan-platform" }
raw-window-handle = "0.6"
winit = "0.30" winit = "0.30"
[lints] [lints]
+17 -2
View File
@@ -21,9 +21,10 @@
//! Minimal `winit`-backed platform adapter shim. //! Minimal `winit`-backed platform adapter shim.
use fparkan_platform::{ use fparkan_platform::{
EventSource, MonotonicClock, MonotonicInstant, PhysicalSize, PlatformError, PlatformEvent, EventSource, MonotonicClock, MonotonicInstant, NativeWindowHandles, PhysicalSize,
RenderRequest, WindowHandle, WindowPort, PlatformError, PlatformEvent, RenderRequest, WindowHandle, WindowPort,
}; };
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
@@ -153,6 +154,7 @@ pub struct WinitWindow {
focused: bool, focused: bool,
minimized: bool, minimized: bool,
occluded: bool, occluded: bool,
native_handles: Option<NativeWindowHandles>,
} }
impl WinitWindow { impl WinitWindow {
@@ -171,6 +173,7 @@ impl WinitWindow {
focused: true, focused: true,
minimized: false, minimized: false,
occluded: false, occluded: false,
native_handles: native_handles(window),
} }
} }
@@ -187,6 +190,7 @@ impl WinitWindow {
focused: true, focused: true,
minimized: false, minimized: false,
occluded: false, occluded: false,
native_handles: None,
} }
} }
@@ -224,6 +228,16 @@ impl WindowPort for WinitWindow {
fn handle(&self) -> WindowHandle { fn handle(&self) -> WindowHandle {
self.handle self.handle
} }
fn native_handles(&self) -> Option<NativeWindowHandles> {
self.native_handles
}
}
fn native_handles(window: &Window) -> Option<NativeWindowHandles> {
let display = window.display_handle().ok()?.as_raw();
let window = window.window_handle().ok()?.as_raw();
Some(NativeWindowHandles { display, window })
} }
#[cfg(test)] #[cfg(test)]
@@ -259,6 +273,7 @@ mod tests {
height: 360 height: 360
} }
); );
assert!(window.native_handles().is_none());
} }
#[test] #[test]
+1
View File
@@ -6,6 +6,7 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
raw-window-handle = "0.6"
[lints] [lints]
workspace = true workspace = true
+15
View File
@@ -20,6 +20,8 @@
)] )]
//! Platform ports for clocks, event sources and window descriptors. //! Platform ports for clocks, event sources and window descriptors.
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
/// Monotonic instant measured in milliseconds since process start. /// Monotonic instant measured in milliseconds since process start.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct MonotonicInstant(pub u64); pub struct MonotonicInstant(pub u64);
@@ -143,6 +145,15 @@ pub struct WindowHandle {
pub id: u64, pub id: u64,
} }
/// Native raw window/display handles for render surface creation.
#[derive(Clone, Copy, Debug)]
pub struct NativeWindowHandles {
/// Raw display handle.
pub display: RawDisplayHandle,
/// Raw window handle.
pub window: RawWindowHandle,
}
/// Window presentation and lifecycle port. /// Window presentation and lifecycle port.
/// ///
/// Presentation is not owned by the window abstraction. Render adapters /// Presentation is not owned by the window abstraction. Render adapters
@@ -160,6 +171,10 @@ pub trait WindowPort {
fn is_occluded(&self) -> bool; fn is_occluded(&self) -> bool;
/// Opaque window identity. /// Opaque window identity.
fn handle(&self) -> WindowHandle; fn handle(&self) -> WindowHandle;
/// Raw native handles for render surface creation, when backed by a native window.
fn native_handles(&self) -> Option<NativeWindowHandles> {
None
}
} }
/// Render backend request contract. /// Render backend request contract.
+2
View File
@@ -21,6 +21,8 @@ S0-CORPUS-005 covered cargo test -p fparkan-corpus --offline fingerprint_changes
S0-CORPUS-006 covered cargo test -p fparkan-corpus --offline atomic_report_write S0-CORPUS-006 covered cargo test -p fparkan-corpus --offline atomic_report_write
S0-CLI-001 covered cargo test -p fparkan-cli --offline stable_exit_codes_are_mapped S0-CLI-001 covered cargo test -p fparkan-cli --offline stable_exit_codes_are_mapped
S0-CLI-002 covered cargo test -p fparkan-cli --offline accepts_json_format_option archive_json_has_schema_version S0-CLI-002 covered cargo test -p fparkan-cli --offline accepts_json_format_option archive_json_has_schema_version
S0-PLAT-001 covered cargo test -p fparkan-platform-winit --offline window_port_reports_default_request_profile
S0-PLAT-002 covered cargo clippy -p fparkan-platform -p fparkan-platform-winit --all-targets --all-features --locked -- -D warnings
S0-VK-001 covered cargo test -p fparkan-render-vulkan --offline backend_tracks_render_request_and_presents S0-VK-001 covered cargo test -p fparkan-render-vulkan --offline backend_tracks_render_request_and_presents
S0-VK-002 covered cargo test -p fparkan-render-vulkan --offline device_scoring_is_deterministic_and_prefers_discrete_unified_queue S0-VK-002 covered cargo test -p fparkan-render-vulkan --offline device_scoring_is_deterministic_and_prefers_discrete_unified_queue
S0-VK-003 covered cargo test -p fparkan-render-vulkan --offline portability_subset_is_reported_and_enabled_when_exposed S0-VK-003 covered cargo test -p fparkan-render-vulkan --offline portability_subset_is_reported_and_enabled_when_exposed
1 # Acceptance coverage manifest.
21 S0-CORPUS-006
22 S0-CLI-001
23 S0-CLI-002
24 S0-PLAT-001
25 S0-PLAT-002
26 S0-VK-001
27 S0-VK-002
28 S0-VK-003
+2
View File
@@ -21,6 +21,8 @@
`S0-CORPUS-006` `S0-CORPUS-006`
`S0-CLI-001` `S0-CLI-001`
`S0-CLI-002` `S0-CLI-002`
`S0-PLAT-001`
`S0-PLAT-002`
`S0-VK-001` `S0-VK-001`
`S0-VK-002` `S0-VK-002`
`S0-VK-003` `S0-VK-003`