Skip to main content

OwnedSurface

Struct OwnedSurface 

Source
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: bool

Implementations§

Source§

impl<O: PixelOps + Copy> OwnedSurface<O>

Source

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.

Source

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.

Source

pub fn dims(&self) -> Dims

Source

pub fn format(&self) -> Format

Source

pub fn pitch(&self) -> usize

Bytes per row (always width * 4).

Source

pub fn bounds(&self) -> Rect

Source

pub fn words(&self) -> &[u32]

Raw pixels. Bypasses damage tracking; call Self::mark_dirty if the caller wrote through this slice.

Source

pub fn words_mut(&mut self) -> &mut [u32]

Mutable raw pixels. See Self::words.

Source

pub fn mark_dirty(&mut self, rect: Rect)

Record damage from an external write.

Source

pub fn dirty(&self) -> &RectSet<DEFAULT_SET_CAPACITY>

Source

pub fn take_dirty(&mut self) -> RectSet<DEFAULT_SET_CAPACITY>

Source

pub fn clear_dirty(&mut self)

Source

pub fn set_tracking(&mut self, on: bool)

Source

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.

Source

pub fn view(&self) -> View<'_>

Immutable view over the pixels.

Source

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.

Source

pub fn fill_rect(&mut self, rect: Rect, color: Packed) -> Option<Rect>

Source

pub fn fill(&mut self, color: Packed) -> Rect

Source

pub fn blit<S: Source + ?Sized>( &mut self, dst: Rect, src: &S, src_rect: Rect, ) -> Result<Option<Rect>, Error>

Source

pub fn blend_rect<S: Source + ?Sized>( &mut self, dst: Rect, src: &S, src_rect: Rect, alpha: u8, ) -> Result<Option<Rect>, Error>

Source

pub fn convert_from<S: Source + ?Sized>( &mut self, dst: Rect, src: &S, src_rect: Rect, ) -> Result<Option<Rect>, Error>

Source

pub fn read_pixel(&self, x: u32, y: u32) -> Option<Packed>

Source

pub fn write_pixel(&mut self, x: u32, y: u32, pixel: Packed) -> bool

Source§

impl OwnedSurface<ScalarOps>

Source

pub fn new(dims: Dims, format: Format) -> Result<Self, Error>

Allocate a zeroed XRGB8888 surface with the scalar backend.

Trait Implementations§

Source§

impl<O: PixelOps> Debug for OwnedSurface<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O: PixelOps> Source for OwnedSurface<O>

Source§

fn dims(&self) -> Dims

Source§

fn format(&self) -> Format

Source§

fn pitch(&self) -> usize

Bytes per row. Read more
Source§

unsafe fn row_ptr(&self, y: u32) -> *const u8

Pointer to the first pixel of row y. Read more
Source§

unsafe fn read_raw(&self, x: u32, y: u32) -> u32

Read one pixel with no volatile semantics. Read more

Auto Trait Implementations§

§

impl<O> Forget for OwnedSurface<O>

§

impl<O> Freeze for OwnedSurface<O>
where O: Freeze,

§

impl<O> Move for OwnedSurface<O>

§

impl<O> RefUnwindSafe for OwnedSurface<O>
where O: RefUnwindSafe,

§

impl<O> Send for OwnedSurface<O>
where O: Send,

§

impl<O> Sync for OwnedSurface<O>
where O: Sync,

§

impl<O> Unpin for OwnedSurface<O>
where O: Unpin,

§

impl<O> UnsafeUnpin for OwnedSurface<O>
where O: UnsafeUnpin,

§

impl<O> UnwindSafe for OwnedSurface<O>
where O: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.