Skip to main content

Framebuffer

Struct Framebuffer 

Source
pub struct Framebuffer<const W: usize, const H: usize> { /* private fields */ }
Expand description

A W×H RGB565 framebuffer in display wire format.

At 240×135 it is 64 800 bytes, so it should live in a static, never on the stack. Framebuffer::new is const and all-zero, which places the buffer in .bss: it costs RAM but no flash. A non-zero initial value would put 64 KB of initialiser data in the firmware image.

use oxstack_gfx::{Framebuffer, Rgb565};
use embedded_graphics::prelude::*;

static mut FB: Framebuffer<240, 135> = Framebuffer::new();
fb.clear(Rgb565::BLUE).unwrap();
let dirty = fb.take_dirty().unwrap();
assert_eq!((dirty.y, dirty.rows), (0, 135));
assert_eq!(dirty.bytes.len(), 240 * 135 * 2);

Implementations§

Source§

impl<const W: usize, const H: usize> Framebuffer<W, H>

Source

pub const fn new() -> Self

An all-black framebuffer with nothing marked dirty.

Source

pub const fn width(&self) -> usize

Width in pixels.

Source

pub const fn height(&self) -> usize

Height in pixels.

Source

pub fn pixel(&self, x: usize, y: usize) -> Option<Rgb565>

Colour at (x, y), or None outside the buffer.

Source

pub fn mark_all_dirty(&mut self)

Marks every row as changed, e.g. after the panel lost its contents.

Source

pub fn take_dirty(&mut self) -> Option<DirtyRows<'_>>

Hands out the changed rows and marks the buffer clean. The caller must send them to the display before drawing again.

Source

pub fn wire_rows_mut(&mut self, rows: Range<usize>) -> &mut [[u16; W]]

Mutable access to rows rows in wire format, for renderers that write pixels one by one (a 3D rasteriser testing depth per pixel cannot use fill_solid). Those rows are marked dirty, so a flush cannot miss them. Store colours converted with wire_color.

§Panics

If rows is out of bounds or decreasing, like slice indexing.

use oxstack_gfx::{Framebuffer, Rgb565, wire_color};
use embedded_graphics::prelude::*;

let mut fb = Framebuffer::<8, 6>::new();
let red = wire_color(Rgb565::RED);
for row in fb.wire_rows_mut(2..4) {
    row[1..3].fill(red);
}
assert_eq!(fb.pixel(1, 3), Some(Rgb565::RED));
let dirty = fb.take_dirty().unwrap();
assert_eq!((dirty.y, dirty.rows), (2, 2));
Source

pub fn as_bytes(&self) -> &[u8]

The whole buffer in wire format.

Trait Implementations§

Source§

impl<const W: usize, const H: usize> Default for Framebuffer<W, H>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const W: usize, const H: usize> DrawTarget for Framebuffer<W, H>

Source§

type Color = Rgb565

The pixel color type the targetted display supports.
Source§

type Error = Infallible

Error type to return when a drawing operation fails. Read more
Source§

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Infallible>
where I: IntoIterator<Item = Pixel<Rgb565>>,

Draw individual pixels to the display without a defined order. Read more
Source§

fn fill_solid( &mut self, area: &Rectangle, color: Rgb565, ) -> Result<(), Infallible>

Fill a given area with a solid color. Read more
Source§

fn clear(&mut self, color: Rgb565) -> Result<(), Infallible>

Fill the entire display with a solid color. Read more
§

fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I, ) -> Result<(), Self::Error>
where I: IntoIterator<Item = Self::Color>,

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
Source§

impl<const W: usize, const H: usize> OriginDimensions for Framebuffer<W, H>

Source§

fn size(&self) -> Size

Returns the size of the bounding box.

Auto Trait Implementations§

§

impl<const W: usize, const H: usize> Freeze for Framebuffer<W, H>

§

impl<const W: usize, const H: usize> RefUnwindSafe for Framebuffer<W, H>

§

impl<const W: usize, const H: usize> Send for Framebuffer<W, H>

§

impl<const W: usize, const H: usize> Sync for Framebuffer<W, H>

§

impl<const W: usize, const H: usize> Unpin for Framebuffer<W, H>

§

impl<const W: usize, const H: usize> UnsafeUnpin for Framebuffer<W, H>

§

impl<const W: usize, const H: usize> UnwindSafe for Framebuffer<W, H>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> Dimensions for T
where T: OriginDimensions,

§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.