/
null.rs
144 lines (123 loc) · 3.8 KB
/
null.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use std::borrow::Cow;
use std::sync::Arc;
use crate::backend::{
BitmapCacheEntry, RenderBackend, ShapeHandle, ShapeHandleImpl, ViewportDimensions,
};
use crate::bitmap::{
Bitmap, BitmapHandle, BitmapHandleImpl, BitmapSize, BitmapSource, PixelRegion, RgbaBufRead,
SyncHandle,
};
use crate::commands::CommandList;
use crate::error::Error;
use crate::pixel_bender::{PixelBenderShader, PixelBenderShaderArgument, PixelBenderShaderHandle};
use crate::quality::StageQuality;
use crate::shape_utils::DistilledShape;
use swf::Color;
use super::{Context3D, Context3DProfile, PixelBenderOutput, PixelBenderTarget};
pub struct NullBitmapSource;
impl BitmapSource for NullBitmapSource {
fn bitmap_size(&self, _id: u16) -> Option<BitmapSize> {
None
}
fn bitmap_handle(&self, _id: u16, _renderer: &mut dyn RenderBackend) -> Option<BitmapHandle> {
None
}
}
pub struct NullRenderer {
dimensions: ViewportDimensions,
}
impl NullRenderer {
pub fn new(dimensions: ViewportDimensions) -> Self {
Self { dimensions }
}
}
#[derive(Clone, Debug)]
struct NullBitmapHandle;
impl BitmapHandleImpl for NullBitmapHandle {}
#[derive(Clone, Debug)]
struct NullShapeHandle;
impl ShapeHandleImpl for NullShapeHandle {}
impl RenderBackend for NullRenderer {
fn viewport_dimensions(&self) -> ViewportDimensions {
self.dimensions
}
fn set_viewport_dimensions(&mut self, dimensions: ViewportDimensions) {
self.dimensions = dimensions;
}
fn register_shape(
&mut self,
_shape: DistilledShape,
_bitmap_source: &dyn BitmapSource,
) -> ShapeHandle {
ShapeHandle(Arc::new(NullShapeHandle))
}
fn render_offscreen(
&mut self,
_handle: BitmapHandle,
_commands: CommandList,
_quality: StageQuality,
_bounds: PixelRegion,
) -> Option<Box<dyn SyncHandle>> {
None
}
fn submit_frame(
&mut self,
_clear: Color,
_commands: CommandList,
_cache_entries: Vec<BitmapCacheEntry>,
) {
}
fn register_bitmap(&mut self, _bitmap: Bitmap) -> Result<BitmapHandle, Error> {
Ok(BitmapHandle(Arc::new(NullBitmapHandle)))
}
fn update_texture(
&mut self,
_handle: &BitmapHandle,
_bitmap: Bitmap,
_region: PixelRegion,
) -> Result<(), Error> {
Ok(())
}
fn create_context3d(
&mut self,
_profile: Context3DProfile,
) -> Result<Box<dyn super::Context3D>, Error> {
Err(Error::Unimplemented("createContext3D".into()))
}
fn context3d_present(&mut self, _context: &mut dyn Context3D) -> Result<(), Error> {
Err(Error::Unimplemented("Context3D.present".into()))
}
fn debug_info(&self) -> Cow<'static, str> {
Cow::Borrowed("Renderer: Null")
}
fn name(&self) -> &'static str {
""
}
fn set_quality(&mut self, _quality: StageQuality) {}
fn run_pixelbender_shader(
&mut self,
_shader: PixelBenderShaderHandle,
_arguments: &[PixelBenderShaderArgument],
_target: &PixelBenderTarget,
) -> Result<PixelBenderOutput, Error> {
Err(Error::Unimplemented("Pixel bender shader".into()))
}
fn resolve_sync_handle(
&mut self,
_handle: Box<dyn SyncHandle>,
_with_rgba: RgbaBufRead,
) -> Result<(), Error> {
Err(Error::Unimplemented("Sync handle resolution".into()))
}
fn compile_pixelbender_shader(
&mut self,
_shader: PixelBenderShader,
) -> Result<PixelBenderShaderHandle, Error> {
Err(Error::Unimplemented(
"Pixel bender shader compilation".into(),
))
}
fn create_empty_texture(&mut self, _width: u32, _height: u32) -> Result<BitmapHandle, Error> {
Ok(BitmapHandle(Arc::new(NullBitmapHandle)))
}
}