Skip to main content

View

Struct View 

Source
pub struct View<'a> {
    base: *const u8,
    pitch: usize,
    dims: Dims,
    format: Format,
    _borrow: PhantomData<&'a [u8]>,
}
Expand description

An immutable rectangle of pixels.

Created from a borrowed slice or from raw memory (MMIO, shared mapping). It records no damage and cannot be drawn into.

Fields§

§base: *const u8§pitch: usize§dims: Dims§format: Format§_borrow: PhantomData<&'a [u8]>

Implementations§

Source§

impl<'a> View<'a>

Source

pub fn new( buf: &'a [u8], dims: Dims, pitch: usize, format: Format, ) -> Result<Self, Error>

Build a view over a borrowed buffer.

pitch is a byte count, not a pixel count.

Source

pub unsafe fn from_raw( base: *const u8, dims: Dims, pitch: usize, format: Format, ) -> Result<Self, Error>

Build a view over raw memory.

§Safety

base must be readable for pitch * height bytes for the whole lifetime 'a, and the memory must stay valid if the view is sent to another CPU (View is Send + Sync).

Source

pub fn dims(&self) -> Dims

Source

pub fn format(&self) -> Format

Source

pub fn pitch(&self) -> usize

Source

pub fn bytes_per_pixel(&self) -> usize

Source

pub fn bounds(&self) -> Rect

Source

pub fn clip(&self, rect: Rect) -> Option<Rect>

Source

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

Read one pixel. Volatile, because the backing memory may be MMIO or a shared mapping that a device updates.

Trait Implementations§

Source§

impl Debug for View<'_>

Source§

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

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

impl Send for View<'_>

Source§

impl Source for View<'_>

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
Source§

impl Sync for View<'_>

Auto Trait Implementations§

§

impl<'a> Forget for View<'a>

§

impl<'a> Freeze for View<'a>

§

impl<'a> Move for View<'a>

§

impl<'a> RefUnwindSafe for View<'a>

§

impl<'a> Unpin for View<'a>

§

impl<'a> UnsafeUnpin for View<'a>

§

impl<'a> UnwindSafe for View<'a>

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.