pub struct OwnedSurface<O: PixelOps = ScalarOps> {
words: Vec<u32>,
dims: Dims,
format: Format,
ops: O,
dirty: RectSet<DEFAULT_SET_CAPACITY>,
track_dirty: bool,
}Expand description
A heap-backed, 32 bpp surface with damage tracking.
The pitch is always width * 4 (no padding), which is what a compositor
or a console back buffer wants. Use Canvas directly
when the backing store has a driver-provided pitch (scanout, client
buffer).
Fields§
§words: Vec<u32>§dims: Dims§format: Format§ops: O§dirty: RectSet<DEFAULT_SET_CAPACITY>§track_dirty: boolImplementations§
Source§impl<O: PixelOps + Copy> OwnedSurface<O>
impl<O: PixelOps + Copy> OwnedSurface<O>
Sourcepub fn with_ops(dims: Dims, format: Format, ops: O) -> Result<Self, Error>
pub fn with_ops(dims: Dims, format: Format, ops: O) -> Result<Self, Error>
Allocate a zeroed surface.
Only 32 bpp layouts are accepted: a heap surface is a drawing target,
not a 24 bpp scanout, and Vec<u32> gives the alignment the pixel
backends expect.
Sourcepub fn from_words(
words: Vec<u32>,
dims: Dims,
format: Format,
ops: O,
) -> Result<Self, Error>
pub fn from_words( words: Vec<u32>, dims: Dims, format: Format, ops: O, ) -> Result<Self, Error>
Wrap an existing word buffer.
The buffer must hold at least dims.w * dims.h pixels; extra words
are ignored.
pub fn dims(&self) -> Dims
pub fn format(&self) -> Format
pub fn bounds(&self) -> Rect
Sourcepub fn words(&self) -> &[u32]
pub fn words(&self) -> &[u32]
Raw pixels. Bypasses damage tracking; call Self::mark_dirty if
the caller wrote through this slice.
Sourcepub fn words_mut(&mut self) -> &mut [u32]
pub fn words_mut(&mut self) -> &mut [u32]
Mutable raw pixels. See Self::words.
Sourcepub fn mark_dirty(&mut self, rect: Rect)
pub fn mark_dirty(&mut self, rect: Rect)
Record damage from an external write.
pub fn dirty(&self) -> &RectSet<DEFAULT_SET_CAPACITY>
pub fn take_dirty(&mut self) -> RectSet<DEFAULT_SET_CAPACITY>
pub fn clear_dirty(&mut self)
pub fn set_tracking(&mut self, on: bool)
Sourcefn canvas(&mut self) -> Canvas<'_, O>
fn canvas(&mut self) -> Canvas<'_, O>
Build a canvas over the pixels.
Private on purpose: a caller that drops the canvas loses its damage.
Self::draw is the safe way to run a multi-operation frame.
Sourcepub fn draw<T>(&mut self, f: impl FnOnce(&mut Canvas<'_, O>) -> T) -> T
pub fn draw<T>(&mut self, f: impl FnOnce(&mut Canvas<'_, O>) -> T) -> T
Run a drawing closure and merge its damage into this surface.
Use this to draw a whole frame through one canvas without losing damage tracking. The per-operation helpers call it internally.