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
use super::{AlphaFormat, IDrawingContextImpl, ILockedFramebuffer, PixelFormat};
use crate::media::imaging::BitmapEncoderOptions;
use crate::{PixelSize, Vector};
use std::any::Any;
use std::io::Write;
use std::rc::Rc;
/// Defines the platform-specific interface for a bitmap.
pub trait IBitmapImpl {
/// The dots per inch (DPI) of the image.
fn dpi(&self) -> Vector;
/// The size of the bitmap, in device pixels.
fn pixel_size(&self) -> PixelSize;
/// Version of the pixel data: incremented whenever the content changes.
fn version(&self) -> i32;
/// Saves the bitmap to a stream, encoded as selected by `options`.
fn save(&self, stream: &mut dyn Write, options: &BitmapEncoderOptions) -> std::io::Result<()>;
/// Releases the bitmap's resources.
fn dispose(&self);
/// Lets the backend recover its concrete type.
fn as_any(&self) -> &dyn Any;
/// The bitmap viewed as [`IReadableBitmapImpl`], when its pixels can be
/// read.
fn as_readable_bitmap(&self) -> Option<&dyn IReadableBitmapImpl> {
None
}
}
/// A bitmap shared between the UI thread and the render thread: what a
/// bitmap object of the UI side holds and what a batch carries. (A layer of
/// a drawing context is a bitmap too, but stays on the render thread.)
pub type SharedBitmapImpl = dyn IBitmapImpl + Send + Sync;
/// A bitmap whose pixels can be read.
pub trait IReadableBitmapImpl: IBitmapImpl {
/// The pixel format, if known.
fn format(&self) -> Option<PixelFormat>;
/// The alpha format, if known.
fn alpha_format(&self) -> Option<AlphaFormat>;
/// Locks the pixels for reading (and writing, for writeable bitmaps).
fn lock(&self) -> Rc<dyn ILockedFramebuffer>;
}
/// Defines the platform-specific interface for a writeable bitmap.
pub trait IWriteableBitmapImpl: IReadableBitmapImpl + Send + Sync {}
/// Defines the platform-specific interface for a bitmap that can be drawn
/// into.
pub trait IRenderTargetBitmapImpl: IReadableBitmapImpl + Send + Sync {
/// Creates a drawing context that draws into the bitmap.
fn create_drawing_context(&self) -> Box<dyn IDrawingContextImpl>;
}