pub struct Framebuffer<P: Pixel> { /* private fields */ }
Expand description

A framebuffer is a region of memory interpreted as a 2-D array of pixels. The memory buffer is a rectangular region with a width and height.

Implementations§

source§

impl<P: Pixel> Framebuffer<P>

source

pub fn new( width: usize, height: usize, physical_address: Option<PhysicalAddress> ) -> Result<Framebuffer<P>, &'static str>

Creates a new framebuffer with rectangular dimensions of width * height, specified in number of pixels.

If physical_address is Some, the returned framebuffer will be a real physical one, i.e., mapped to the physical memory at that address, which is typically hardware graphics memory. In this case, we attempt to map the memory as “write-combining”, which only works on x86 if the Page Attribute Table feature is enabled. Otherwise, we map the real physical framebuffer memory with all caching disabled.

If physical_address is None, the returned framebuffer is a “virtual” one that renders to a randomly-allocated chunk of memory.

source

pub fn buffer_mut(&mut self) -> &mut [P]

Returns a mutable reference to this framebuffer’s memory as a slice of pixels.

source

pub fn buffer(&self) -> &[P]

Returns a reference to this framebuffer’s memory as a slice of pixels.

source

pub fn get_size(&self) -> (usize, usize)

Returns the (width, height) of this framebuffer.

source

pub fn composite_buffer(&mut self, src: &[P], index: usize)

Composites src to the buffer starting from index.

source

pub fn draw_pixel(&mut self, coordinate: Coord, pixel: P)

Draw a pixel at the given coordinate. The pixel will be blended with the existing pixel value at that coordinate in this framebuffer.

source

pub fn overwrite_pixel(&mut self, coordinate: Coord, pixel: P)

Overwites a pixel at the given coordinate in this framebuffer instead of blending it like draw_pixel.

source

pub fn get_pixel(&self, coordinate: Coord) -> Option<P>

Returns the pixel value at the given coordinate in this framebuffer.

source

pub fn fill(&mut self, pixel: P)

Fills (overwrites) the entire framebuffer with the given pixel value.

source

pub fn index_of(&self, coordinate: Coord) -> Option<usize>

Returns the index of the given coordinate in this framebuffer, if this framebuffer contains the coordinate within its bounds.

source

pub fn contains(&self, coordinate: Coord) -> bool

Checks if the given coordinate is within the framebuffer’s bounds. The coordinate is relative to the origin coordinate of (0, 0) being the top-left point of the framebuffer.

source

pub fn overlaps_with( &mut self, coordinate: Coord, width: usize, height: usize ) -> bool

Checks if a framebuffer overlaps with an area.

Arguments
  • coordinate: the top-left corner of the area relative to the origin(top-left point) of the framebuffer.
  • width: the width of the area in number of pixels.
  • height: the height of the area in number of pixels.

Trait Implementations§

source§

impl<P: Pixel> Hash for Framebuffer<P>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for Framebuffer<P>where P: RefUnwindSafe,

§

impl<P> Send for Framebuffer<P>where P: Send,

§

impl<P> Sync for Framebuffer<P>where P: Sync,

§

impl<P> Unpin for Framebuffer<P>where P: Unpin,

§

impl<P> UnwindSafe for Framebuffer<P>where P: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.