Skip to main content

nsh_engine/
shader_off.rs

1//! The native backends' shader API without the renderer (feature `shader` off):
2//! no GPU is ever found ([`Renderer::new`] is `None`), so shader views draw
3//! nothing of their own, and wgpu is not linked. The backends' code stays the
4//! same either way.
5
6use std::{
7    sync::Arc,
8    time::{Duration, Instant},
9};
10
11use nsh_core::{
12    animation::AnimationValue,
13    geometry::{Points, Size},
14    shader::{ShaderInput, ShaderLayer},
15};
16
17#[cfg(windows)]
18pub use crate::shader_frame::SharedTexture;
19pub use crate::shader_frame::{Frame, MAX_SIDE, PixelFormat};
20
21/// This build has no renderer: a platform reports `Environment::shaders`
22/// `false` from the start.
23pub const LINKED: bool = false;
24
25/// No renderer ever looks for a GPU here.
26pub(crate) fn no_gpu() -> bool {
27    false
28}
29
30/// Never made: this build has no renderer.
31pub struct Renderer {
32    format: PixelFormat,
33}
34
35impl Renderer {
36    /// `None`: this build has no renderer.
37    pub fn new(_format: PixelFormat) -> Option<Renderer> {
38        None
39    }
40
41    /// Calls `done(None)` at once: this build has no renderer.
42    pub fn open(_format: PixelFormat, done: impl FnOnce(Option<Renderer>) + Send + 'static) {
43        done(None);
44    }
45
46    /// Does nothing: no pipeline is ever compiled (`f` is dropped).
47    pub fn on_pipeline_ready(&self, f: impl Fn() + Send + Sync + 'static) {
48        drop(f);
49    }
50
51    /// `false`: no pipeline is ever compiled.
52    pub fn compiling(&self) -> bool {
53        false
54    }
55
56    /// `true` at once: no pipeline is ever compiled.
57    pub fn wait_for_pipelines(&self, _timeout: Duration) -> bool {
58        true
59    }
60
61    /// The format of the frames.
62    pub fn format(&self) -> PixelFormat {
63        self.format
64    }
65
66    /// `false`: there are no frames (`f` is dropped).
67    pub fn when_done(&self, f: impl FnOnce() + Send + 'static) -> bool {
68        drop(f);
69        false
70    }
71}
72
73/// One view's state, which never renders.
74#[derive(Default)]
75pub struct ShaderView {
76    layer: Option<Arc<ShaderLayer>>,
77    frame: Frame,
78}
79
80impl ShaderView {
81    /// Keeps `layer`.
82    pub fn set_layer(&mut self, layer: Option<Arc<ShaderLayer>>) {
83        self.layer = layer;
84    }
85
86    /// Does nothing.
87    pub fn set_input(
88        &mut self,
89        _renderer: &Renderer,
90        _input: ShaderInput,
91        _picture: Option<(&[u8], u32, u32, u32)>,
92    ) {
93    }
94
95    /// `false`: there is no frame.
96    pub fn set_input_from_frame(&mut self, _renderer: &Renderer, _input: ShaderInput) -> bool {
97        false
98    }
99
100    /// `false`: nothing is kept.
101    pub fn has_input(&self, _input: ShaderInput) -> bool {
102        false
103    }
104
105    /// Does nothing: a transition ends at once.
106    pub fn start_transition(&mut self, _duration: Duration, _now: Instant) {}
107
108    /// Does nothing: a transition ends at once.
109    pub fn start_transition_backwards(&mut self, _duration: Duration, _now: Instant) {}
110
111    /// `false`: a transition ends at once.
112    pub fn transitioning(&mut self, _now: Instant) -> bool {
113        false
114    }
115
116    /// `false`: the children stay.
117    pub fn replaces_children(&mut self, _now: Instant) -> bool {
118        false
119    }
120
121    /// Nothing is drawn beyond the box.
122    pub fn overflow(&self) -> Points {
123        Points(0.0)
124    }
125
126    /// The layer it was given.
127    pub fn layer(&self) -> Option<&Arc<ShaderLayer>> {
128        self.layer.as_ref()
129    }
130
131    /// Does nothing.
132    pub fn set_slot(&mut self, _slot: u16, _value: AnimationValue) {}
133
134    /// Does nothing.
135    pub fn set_size(&mut self, _size: Size<Points>, _scale: f32) {}
136
137    /// `false`: there are no frames.
138    pub fn wants_frame(&self) -> bool {
139        false
140    }
141
142    /// `false`: nothing compiles.
143    pub fn compiling(&self) -> bool {
144        false
145    }
146
147    /// `false`: there are no frames.
148    pub fn pending(&self) -> bool {
149        false
150    }
151
152    /// `false`: there are no frames.
153    pub fn due(&self) -> bool {
154        false
155    }
156
157    /// `false`: there are no frames.
158    pub fn animates(&self) -> bool {
159        false
160    }
161
162    /// The empty frame.
163    pub fn frame(&self) -> &Frame {
164        &self.frame
165    }
166
167    /// Does nothing: there are no frames.
168    #[cfg(any(target_vendor = "apple", windows))]
169    pub fn show_on_surfaces(&mut self, _on: bool) {}
170
171    /// `None`: there are no frames.
172    #[cfg(windows)]
173    pub fn surface(&self) -> Option<SharedTexture> {
174        None
175    }
176
177    /// `None`: there are no frames.
178    #[cfg(target_vendor = "apple")]
179    pub fn surface(&self) -> Option<&objc2_io_surface::IOSurfaceRef> {
180        None
181    }
182
183    /// `false`: there are no frames.
184    pub fn collect_frame(&mut self, _renderer: &Renderer) -> bool {
185        false
186    }
187
188    /// `false`: there are no frames.
189    pub fn render(&mut self, _renderer: &Renderer, _now: Instant) -> bool {
190        false
191    }
192}