euv_core/render/config/impl.rs
1use super::*;
2
3/// Default rendering configuration (`Auto`, `VSync`, `AnalyticalSdf`, dirty rects enabled).
4impl Default for RenderConfig {
5 /// Creates the recommended cross-platform `RenderConfig`.
6 ///
7 /// # Returns
8 ///
9 /// - `Self` - Default `RenderConfig`.
10 fn default() -> Self {
11 Self {
12 mode: RenderMode::Auto,
13 preferred_backend: None,
14 present_mode: PresentMode::VSync,
15 antialiasing: AntialiasingMode::AnalyticalSdf,
16 color_space: ColorSpace::Srgb,
17 dirty_rect_optimization: true,
18 tile_size: DEFAULT_TILE_SIZE,
19 max_fps: DEFAULT_MAX_FPS,
20 hdr: false,
21 direct_gpu_present: false,
22 }
23 }
24}
25
26/// Fluent builder helpers for `RenderConfig`.
27impl RenderConfig {
28 /// Creates a software-rendering configuration.
29 ///
30 /// # Returns
31 ///
32 /// - `Self` - Software-mode `RenderConfig`.
33 #[must_use]
34 pub fn software() -> Self {
35 let mut cfg: Self = Self::default();
36 cfg.set_mode(RenderMode::Software);
37 cfg.set_preferred_backend(Some(GraphicsBackend::SoftwareCpu));
38 cfg
39 }
40
41 /// Creates a hardware GPU rendering configuration.
42 ///
43 /// # Returns
44 ///
45 /// - `Self` - Hardware-mode `RenderConfig`.
46 #[must_use]
47 pub fn hardware() -> Self {
48 let mut cfg: Self = Self::default();
49 cfg.set_mode(RenderMode::Hardware);
50 cfg
51 }
52
53 /// Creates a hardware GPU direct-draw configuration skipping steady-state CPU RGBA mirror generation.
54 ///
55 /// # Returns
56 ///
57 /// - `Self` - Direct-draw hardware-mode `RenderConfig`.
58 #[must_use]
59 pub fn hardware_direct() -> Self {
60 let mut cfg: Self = Self::hardware();
61 cfg.set_direct_gpu_present(true);
62 cfg
63 }
64
65 /// Configures whether `Hardware` mode renders directly to the GPU without steady-state CPU RGBA readback.
66 ///
67 /// # Arguments
68 ///
69 /// - `Self` - Base render configuration.
70 /// - `bool` - `true` to enable direct GPU presentation with zero steady-state CPU RGBA mirroring.
71 ///
72 /// # Returns
73 ///
74 /// - `Self` - Updated render configuration.
75 #[must_use]
76 pub fn with_direct_gpu_present(mut self, enabled: bool) -> Self {
77 self.set_direct_gpu_present(enabled);
78 self
79 }
80
81 /// Creates a hybrid CPU-tile + GPU-compositor rendering configuration.
82 ///
83 /// # Returns
84 ///
85 /// - `Self` - Hybrid-mode `RenderConfig`.
86 #[must_use]
87 pub fn hybrid() -> Self {
88 let mut cfg: Self = Self::default();
89 cfg.set_mode(RenderMode::Hybrid);
90 cfg
91 }
92
93 /// Returns the optional preferred graphics backend.
94 ///
95 /// # Arguments
96 ///
97 /// - `&Self` - Render config.
98 ///
99 /// # Returns
100 ///
101 /// - `Option<GraphicsBackend>` - Explicit backend preference if set.
102 #[must_use]
103 pub fn preferred_backend_value(&self) -> Option<GraphicsBackend> {
104 let Self {
105 preferred_backend, ..
106 } = *self;
107 preferred_backend
108 }
109}