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
17pub use crate::shader_frame::{Frame, MAX_SIDE, PixelFormat};
18
19/// This build has no renderer: a platform reports `Environment::shaders`
20/// `false` from the start.
21pub const LINKED: bool = false;
22
23/// No renderer ever looks for a GPU here.
24pub(crate) fn no_gpu() -> bool {
25    false
26}
27
28/// Never made: this build has no renderer.
29pub struct Renderer {
30    format: PixelFormat,
31}
32
33impl Renderer {
34    /// `None`: this build has no renderer.
35    pub fn new(_format: PixelFormat) -> Option<Renderer> {
36        None
37    }
38
39    /// The format of the frames.
40    pub fn format(&self) -> PixelFormat {
41        self.format
42    }
43
44    /// `false`: there are no frames (`f` is dropped).
45    pub fn when_done(&self, f: impl FnOnce() + Send + 'static) -> bool {
46        drop(f);
47        false
48    }
49}
50
51/// One view's state, which never renders.
52#[derive(Default)]
53pub struct ShaderView {
54    layer: Option<Arc<ShaderLayer>>,
55    frame: Frame,
56}
57
58impl ShaderView {
59    /// Keeps `layer`.
60    pub fn set_layer(&mut self, layer: Option<Arc<ShaderLayer>>) {
61        self.layer = layer;
62    }
63
64    /// Does nothing.
65    pub fn set_input(
66        &mut self,
67        _renderer: &Renderer,
68        _input: ShaderInput,
69        _picture: Option<(&[u8], u32, u32, u32)>,
70    ) {
71    }
72
73    /// `false`: there is no frame.
74    pub fn set_input_from_frame(&mut self, _renderer: &Renderer, _input: ShaderInput) -> bool {
75        false
76    }
77
78    /// `false`: nothing is kept.
79    pub fn has_input(&self, _input: ShaderInput) -> bool {
80        false
81    }
82
83    /// Does nothing: a transition ends at once.
84    pub fn start_transition(&mut self, _duration: Duration, _now: Instant) {}
85
86    /// Does nothing: a transition ends at once.
87    pub fn start_transition_backwards(&mut self, _duration: Duration, _now: Instant) {}
88
89    /// `false`: a transition ends at once.
90    pub fn transitioning(&mut self, _now: Instant) -> bool {
91        false
92    }
93
94    /// `false`: the children stay.
95    pub fn replaces_children(&mut self, _now: Instant) -> bool {
96        false
97    }
98
99    /// Nothing is drawn beyond the box.
100    pub fn overflow(&self) -> Points {
101        Points(0.0)
102    }
103
104    /// The layer it was given.
105    pub fn layer(&self) -> Option<&Arc<ShaderLayer>> {
106        self.layer.as_ref()
107    }
108
109    /// Does nothing.
110    pub fn set_slot(&mut self, _slot: u16, _value: AnimationValue) {}
111
112    /// Does nothing.
113    pub fn set_size(&mut self, _size: Size<Points>, _scale: f32) {}
114
115    /// `false`: there are no frames.
116    pub fn wants_frame(&self) -> bool {
117        false
118    }
119
120    /// `false`: there are no frames.
121    pub fn pending(&self) -> bool {
122        false
123    }
124
125    /// `false`: there are no frames.
126    pub fn due(&self) -> bool {
127        false
128    }
129
130    /// `false`: there are no frames.
131    pub fn animates(&self) -> bool {
132        false
133    }
134
135    /// The empty frame.
136    pub fn frame(&self) -> &Frame {
137        &self.frame
138    }
139
140    /// Does nothing: there are no frames.
141    #[cfg(target_vendor = "apple")]
142    pub fn show_on_surfaces(&mut self) {}
143
144    /// `None`: there are no frames.
145    #[cfg(target_vendor = "apple")]
146    pub fn surface(&self) -> Option<&objc2_io_surface::IOSurfaceRef> {
147        None
148    }
149
150    /// `false`: there are no frames.
151    pub fn collect_frame(&mut self, _renderer: &Renderer) -> bool {
152        false
153    }
154
155    /// `false`: there are no frames.
156    pub fn render(&mut self, _renderer: &Renderer, _now: Instant) -> bool {
157        false
158    }
159}