forked from ruffle-rs/ruffle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnull.rs
101 lines (84 loc) · 2.58 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
use std::borrow::Cow;
use std::sync::Arc;
use crate::backend::{RenderBackend, ShapeHandle, ShapeHandleImpl, ViewportDimensions};
use crate::bitmap::{
Bitmap, BitmapHandle, BitmapHandleImpl, BitmapSize, BitmapSource, PixelRegion, SyncHandle,
};
use crate::commands::CommandList;
use crate::error::Error;
use crate::quality::StageQuality;
use crate::shape_utils::DistilledShape;
use swf::Color;
use super::Context3D;
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) {}
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) -> 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) {}
}