Skip to main content

nsh_engine/
gpu_off.rs

1//! GPU views' runtime without wgpu (feature `shader` off): the same API, no
2//! render thread and no GPU, so GPU views draw nothing of their own. The
3//! backends' code stays the same either way.
4
5use std::sync::Arc;
6
7use nsh_core::{
8    JsonValue, NodeId,
9    animation::AnimatedPropValue,
10    geometry::{Points, Size},
11    gpu::GpuSource,
12};
13
14#[cfg(windows)]
15use crate::shader_frame::SharedTexture;
16use crate::shader_frame::{Frame, PixelFormat};
17
18/// The GPU views of a surface, in a build without wgpu: they draw nothing.
19pub struct GpuViews {
20    warned: bool,
21}
22
23impl GpuViews {
24    /// No views; this build renders none.
25    pub fn new(format: PixelFormat) -> Self {
26        let _ = format;
27        Self { warned: false }
28    }
29
30    /// Never called: no render thread runs.
31    pub fn on_ready(&self, f: impl Fn() + Send + Sync + 'static) {
32        drop(f);
33    }
34
35    /// Says once that this build draws no GPU views.
36    pub fn set(&mut self, id: NodeId, source: Option<GpuSource>) {
37        if source.is_some() && !std::mem::replace(&mut self.warned, true) {
38            log::warn!(
39                "GPU view {id}: this build has no GPU renderer (feature `shader`); GPU views draw nothing"
40            );
41        }
42    }
43
44    /// Ignored.
45    pub fn set_props(&mut self, id: NodeId, props: &[(Arc<str>, Option<JsonValue>)]) {
46        let _ = (id, props);
47    }
48
49    /// Ignored.
50    pub fn set_animated(&mut self, id: NodeId, name: &str, value: AnimatedPropValue) {
51        let _ = (id, name, value);
52    }
53
54    /// Never: no view is made.
55    pub fn has(&self, id: NodeId) -> bool {
56        let _ = id;
57        false
58    }
59
60    /// Ignored.
61    pub fn set_hidden(&mut self, id: NodeId, hidden: bool) {
62        let _ = (id, hidden);
63    }
64
65    /// Ignored.
66    pub fn set_size(&mut self, id: NodeId, size: Size<Points>, scale: f32) {
67        let _ = (id, size, scale);
68    }
69
70    /// Ignored.
71    #[cfg(any(target_vendor = "apple", windows))]
72    pub fn show_on_surfaces(&mut self, id: NodeId, on: bool) {
73        let _ = (id, on);
74    }
75
76    /// Ignored.
77    pub fn remove(&mut self, id: NodeId) {
78        let _ = id;
79    }
80
81    /// Never: nothing renders.
82    pub fn wants_frame(&self) -> bool {
83        false
84    }
85
86    /// Nothing to do.
87    pub fn tick(&mut self, f: impl FnMut(NodeId)) {
88        drop(f);
89    }
90
91    /// None.
92    pub fn take_events(&mut self) -> Vec<(NodeId, Arc<str>, JsonValue)> {
93        Vec::new()
94    }
95
96    /// None.
97    pub fn with_frame<T>(&self, id: NodeId, f: impl FnOnce(&Frame) -> T) -> Option<T> {
98        let _ = (id, f);
99        None
100    }
101
102    /// None.
103    #[cfg(windows)]
104    pub fn surface(&self, id: NodeId) -> Option<SharedTexture> {
105        let _ = id;
106        None
107    }
108
109    /// None.
110    #[cfg(target_vendor = "apple")]
111    pub fn with_surface<T>(
112        &self,
113        id: NodeId,
114        f: impl FnOnce(&objc2_io_surface::IOSurfaceRef) -> T,
115    ) -> Option<T> {
116        let _ = (id, f);
117        None
118    }
119}