Skip to main content

euv_core/platform/backend/
trait.rs

1use super::*;
2
3/// Unified system abstraction implemented directly over each OS native API (Web, Android, iOS, iPadOS, macOS, Windows, Linux, Headless).
4pub trait PlatformBackend: WindowController {
5    /// Returns the concrete `PlatformKind` served by this backend.
6    ///
7    /// # Arguments
8    ///
9    /// - `&Self` - Backend reference.
10    ///
11    /// # Returns
12    ///
13    /// - `PlatformKind` - Active platform kind.
14    fn kind(&self) -> PlatformKind;
15
16    /// Returns the normalized capability matrix for this backend.
17    ///
18    /// # Arguments
19    ///
20    /// - `&Self` - Backend reference.
21    ///
22    /// # Returns
23    ///
24    /// - `PlatformCapabilities` - Hardware and OS capability flags.
25    fn capabilities(&self) -> PlatformCapabilities;
26
27    /// Creates a native or web window configured by `config`.
28    ///
29    /// # Arguments
30    ///
31    /// - `&Self` - Mutable platform backend.
32    /// - `&WindowConfig` - Declarative window configuration.
33    ///
34    /// # Returns
35    ///
36    /// - `Result<WindowState, PlatformError>` - Initial live window state on success.
37    fn create_window(&mut self, config: &WindowConfig) -> Result<WindowState, PlatformError>;
38
39    /// Returns the latest `WindowState` for `id`, if alive.
40    ///
41    /// # Arguments
42    ///
43    /// - `&Self` - Backend reference.
44    /// - `WindowId` - Window identifier.
45    ///
46    /// # Returns
47    ///
48    /// - `Option<WindowState>` - Live window state.
49    fn window_state(&self, id: WindowId) -> Option<WindowState>;
50
51    /// Returns the ABI-stable `RawWindowHandle` for hardware GPU surface binding.
52    ///
53    /// # Arguments
54    ///
55    /// - `&Self` - Backend reference.
56    /// - `WindowId` - Window identifier.
57    ///
58    /// # Returns
59    ///
60    /// - `RawWindowHandle` - Native OS surface pointer bundle.
61    fn raw_window_handle(&self, id: WindowId) -> RawWindowHandle;
62
63    /// Drains all pending OS window, input, and lifecycle events since the last poll.
64    ///
65    /// # Arguments
66    ///
67    /// - `&Self` - Mutable platform backend.
68    ///
69    /// # Returns
70    ///
71    /// - `Vec<WindowEvent>` - Ordered pending events.
72    fn poll_events(&mut self) -> Vec<WindowEvent>;
73
74    /// Presents a CPU-rendered RGBA8 `Framebuffer` directly onto the native window surface.
75    ///
76    /// # Arguments
77    ///
78    /// - `&Self` - Mutable platform backend.
79    /// - `WindowId` - Target window handle.
80    /// - `&Framebuffer` - Rendered RGBA8 framebuffer.
81    ///
82    /// # Returns
83    ///
84    /// - `Result<(), PlatformError>` - Presentation status.
85    fn present_framebuffer(
86        &mut self,
87        id: WindowId,
88        framebuffer: &Framebuffer,
89    ) -> Result<(), PlatformError>;
90
91    /// Presents a damaged sub-region of a CPU-rendered RGBA8 `Framebuffer` when supported by the backend.
92    ///
93    /// # Arguments
94    ///
95    /// - `&Self` - Mutable platform backend.
96    /// - `WindowId` - Target window handle.
97    /// - `&Framebuffer` - Rendered RGBA8 framebuffer.
98    /// - `DamageRegion` - Damaged pixel region updated this frame.
99    ///
100    /// # Returns
101    ///
102    /// - `Result<(), PlatformError>` - Presentation status.
103    fn present_framebuffer_region(
104        &mut self,
105        id: WindowId,
106        framebuffer: &Framebuffer,
107        _damage: DamageRegion,
108    ) -> Result<(), PlatformError> {
109        self.present_framebuffer(id, framebuffer)
110    }
111
112    /// Reads the current system clipboard text if available.
113    ///
114    /// # Arguments
115    ///
116    /// - `&Self` - Backend reference.
117    ///
118    /// # Returns
119    ///
120    /// - `Option<String>` - Clipboard UTF-8 contents.
121    fn read_clipboard(&self) -> Option<String>;
122
123    /// Writes `text` into the system clipboard.
124    ///
125    /// # Arguments
126    ///
127    /// - `&Self` - Mutable platform backend.
128    /// - `&str` - UTF-8 text to store.
129    ///
130    /// # Returns
131    ///
132    /// - `Result<(), PlatformError>` - Clipboard write status.
133    fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError>;
134
135    /// Queries the current operating system theme mode (`Light` / `Dark`).
136    ///
137    /// # Arguments
138    ///
139    /// - `&Self` - Backend reference.
140    ///
141    /// # Returns
142    ///
143    /// - `ThemeMode` - Detected OS appearance mode.
144    fn system_theme(&self) -> ThemeMode;
145
146    /// Queries the active display's native hardware refresh rate in Hertz (`60.0` fallback).
147    ///
148    /// # Arguments
149    ///
150    /// - `&Self` - Backend reference.
151    ///
152    /// # Returns
153    ///
154    /// - `f32` - Native display refresh rate in Hertz (e.g. `120.0`, `144.0`, `180.0`).
155    fn display_refresh_rate_hz(&self) -> f32 {
156        60.0
157    }
158}