Struct framebuffer::Framebuffer
source · 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>
impl<P: Pixel> Framebuffer<P>
sourcepub fn new(
width: usize,
height: usize,
physical_address: Option<PhysicalAddress>
) -> Result<Framebuffer<P>, &'static str>
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.
sourcepub fn buffer_mut(&mut self) -> &mut [P]
pub fn buffer_mut(&mut self) -> &mut [P]
Returns a mutable reference to this framebuffer’s memory as a slice of pixels.
sourcepub fn buffer(&self) -> &[P]
pub fn buffer(&self) -> &[P]
Returns a reference to this framebuffer’s memory as a slice of pixels.
sourcepub fn composite_buffer(&mut self, src: &[P], index: usize)
pub fn composite_buffer(&mut self, src: &[P], index: usize)
Composites src
to the buffer starting from index
.
sourcepub fn draw_pixel(&mut self, coordinate: Coord, pixel: P)
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.
sourcepub fn overwrite_pixel(&mut self, coordinate: Coord, pixel: P)
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
.
sourcepub fn get_pixel(&self, coordinate: Coord) -> Option<P>
pub fn get_pixel(&self, coordinate: Coord) -> Option<P>
Returns the pixel value at the given coordinate
in this framebuffer.
sourcepub fn fill(&mut self, pixel: P)
pub fn fill(&mut self, pixel: P)
Fills (overwrites) the entire framebuffer with the given pixel
value.
sourcepub fn index_of(&self, coordinate: Coord) -> Option<usize>
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.
sourcepub fn contains(&self, coordinate: Coord) -> bool
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.
sourcepub fn overlaps_with(
&mut self,
coordinate: Coord,
width: usize,
height: usize
) -> bool
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.