-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathbackend_interface.rs
More file actions
58 lines (47 loc) · 1.75 KB
/
backend_interface.rs
File metadata and controls
58 lines (47 loc) · 1.75 KB
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
//! Interface implemented by backends
use crate::{AlphaMode, InitError, PixelFormat, Rect, SoftBufferError};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use std::num::NonZeroU32;
pub(crate) trait ContextInterface<D: HasDisplayHandle + ?Sized> {
fn new(display: D) -> Result<Self, InitError<D>>
where
D: Sized,
Self: Sized;
}
pub(crate) trait SurfaceInterface<D: HasDisplayHandle + ?Sized, W: HasWindowHandle + ?Sized> {
type Context: ContextInterface<D>;
type Buffer<'a>: BufferInterface
where
Self: 'a;
fn new(window: W, context: &Self::Context) -> Result<Self, InitError<W>>
where
W: Sized,
Self: Sized;
/// Get the inner window handle.
fn window(&self) -> &W;
fn alpha_mode(&self) -> AlphaMode;
/// Reconfigure the internal buffer(s).
///
/// Returns `Some(byte_stride)` if the buffer was successfully resized, or `None` if the surface does not support the given pixel format.
fn configure(
&mut self,
width: NonZeroU32,
height: NonZeroU32,
alpha_mode: AlphaMode,
pixel_format: PixelFormat,
) -> Result<Option<u32>, SoftBufferError>;
/// Get a mutable reference to the buffer.
fn buffer_mut(&mut self) -> Result<Self::Buffer<'_>, SoftBufferError>;
/// Fetch the buffer from the window.
fn fetch(&mut self) -> Result<Vec<u32>, SoftBufferError> {
Err(SoftBufferError::Unimplemented)
}
}
pub(crate) trait BufferInterface {
fn width(&self) -> NonZeroU32;
fn height(&self) -> NonZeroU32;
fn pixels_mut(&mut self) -> &mut [u32];
fn age(&self) -> u8;
fn present_with_damage(self, damage: &[Rect]) -> Result<(), SoftBufferError>;
fn present(self) -> Result<(), SoftBufferError>;
}