Skip to main content

ferroui_base/platform/
i_locked_framebuffer.rs

1use super::{AlphaFormat, PixelFormat};
2use crate::{PixelSize, Vector};
3
4/// A locked framebuffer: a block of pixel memory that can be read and
5/// written until it is disposed, at which point its content is presented or
6/// committed.
7pub trait ILockedFramebuffer {
8    /// The address of the first pixel.
9    ///
10    /// The memory is `row_bytes() * size().height` bytes long and stays valid
11    /// until [`dispose`](Self::dispose) is called.
12    fn address(&self) -> *mut u8;
13
14    /// Gives `access` the pixel memory as a slice of
15    /// `row_bytes() * size().height` bytes.
16    ///
17    /// This is the safe counterpart of [`address`](Self::address). The
18    /// framebuffer must not be accessed again from within `access`.
19    fn with_data(&self, access: &mut dyn FnMut(&mut [u8]));
20
21    /// The framebuffer size in device pixels.
22    fn size(&self) -> PixelSize;
23
24    /// The number of bytes per row.
25    fn row_bytes(&self) -> i32;
26
27    /// The DPI of the underlying screen.
28    fn dpi(&self) -> Vector;
29
30    /// The pixel format.
31    fn format(&self) -> PixelFormat;
32
33    /// The alpha format.
34    fn alpha_format(&self) -> AlphaFormat;
35
36    /// Unlocks the framebuffer.
37    fn dispose(&self);
38}