anyrender/
null_backend.rs1use crate::{Filter, ImageRenderer, PaintScene, RenderContext, WindowHandle, WindowRenderer};
4use std::sync::Arc;
5
6#[derive(Copy, Clone, Default)]
7pub struct NullWindowRenderer {
8 is_active: bool,
9}
10
11impl NullWindowRenderer {
12 pub fn new() -> Self {
13 Self::default()
14 }
15}
16
17impl RenderContext for NullWindowRenderer {}
18impl WindowRenderer for NullWindowRenderer {
19 type ScenePainter<'a>
20 = NullScenePainter
21 where
22 Self: 'a;
23
24 fn resume<F: FnOnce() + 'static>(
25 &mut self,
26 _window: Arc<dyn WindowHandle>,
27 _width: u32,
28 _height: u32,
29 on_ready: F,
30 ) {
31 self.is_active = true;
32 on_ready();
33 }
34
35 fn complete_resume(&mut self) -> bool {
36 true
37 }
38
39 fn suspend(&mut self) {
40 self.is_active = false
41 }
42
43 fn is_active(&self) -> bool {
44 self.is_active
45 }
46
47 fn set_size(&mut self, _width: u32, _height: u32) {}
48
49 fn render<F: FnOnce(&mut Self::ScenePainter<'_>)>(&mut self, _draw_fn: F) {}
50}
51
52#[derive(Copy, Clone, Default)]
53pub struct NullImageRenderer;
54
55impl NullImageRenderer {
56 pub fn new() -> Self {
57 Self
58 }
59}
60
61impl RenderContext for NullImageRenderer {}
62impl ImageRenderer for NullImageRenderer {
63 type ScenePainter<'a>
64 = NullScenePainter
65 where
66 Self: 'a;
67
68 fn new(_width: u32, _height: u32) -> Self {
69 Self
70 }
71
72 fn resize(&mut self, _width: u32, _height: u32) {}
73
74 fn reset(&mut self) {}
75
76 fn render_to_vec<F: FnOnce(&mut Self::ScenePainter<'_>)>(
77 &mut self,
78 _draw_fn: F,
79 _vec: &mut Vec<u8>,
80 ) {
81 }
82
83 fn render<F: FnOnce(&mut Self::ScenePainter<'_>)>(&mut self, _draw_fn: F, _buffer: &mut [u8]) {}
84}
85
86#[derive(Copy, Clone, Default)]
87pub struct NullScenePainter;
88
89impl NullScenePainter {
90 pub fn new() -> Self {
91 Self
92 }
93}
94
95impl RenderContext for NullScenePainter {}
96impl PaintScene for NullScenePainter {
97 fn reset(&mut self) {}
98
99 fn push_layer(
100 &mut self,
101 _blend: impl Into<peniko::BlendMode>,
102 _alpha: f32,
103 _transform: kurbo::Affine,
104 _clip: &impl kurbo::Shape,
105 _filter: Option<Arc<Filter>>,
106 _backdrop_filter: Option<Arc<Filter>>,
107 ) {
108 }
109
110 fn push_clip_layer(&mut self, _transform: kurbo::Affine, _clip: &impl kurbo::Shape) {}
111
112 fn pop_layer(&mut self) {}
113
114 fn stroke<'a>(
115 &mut self,
116 _style: &kurbo::Stroke,
117 _transform: kurbo::Affine,
118 _brush: impl Into<crate::PaintRef<'a>>,
119 _brush_transform: Option<kurbo::Affine>,
120 _shape: &impl kurbo::Shape,
121 ) {
122 }
123
124 fn fill<'a>(
125 &mut self,
126 _style: peniko::Fill,
127 _transform: kurbo::Affine,
128 _brush: impl Into<crate::PaintRef<'a>>,
129 _brush_transform: Option<kurbo::Affine>,
130 _shape: &impl kurbo::Shape,
131 ) {
132 }
133
134 fn draw_glyphs<'a, 's: 'a>(
135 &'s mut self,
136 _font: &'a peniko::FontData,
137 _font_size: f32,
138 _hint: bool,
139 _normalized_coords: &'a [crate::NormalizedCoord],
140 _embolden: kurbo::Vec2,
141 _style: impl Into<peniko::StyleRef<'a>>,
142 _brush: impl Into<crate::PaintRef<'a>>,
143 _brush_alpha: f32,
144 _transform: kurbo::Affine,
145 _glyph_transform: Option<kurbo::Affine>,
146 _glyphs: impl Iterator<Item = crate::Glyph>,
147 ) {
148 }
149
150 fn draw_box_shadow(
151 &mut self,
152 _transform: kurbo::Affine,
153 _rect: kurbo::Rect,
154 _brush: peniko::Color,
155 _radius: f64,
156 _std_dev: f64,
157 ) {
158 }
159}