Trait FrameBuffer

Source
pub trait FrameBuffer {
    // Required methods
    fn get_width(&self) -> usize;
    fn get_height(&self) -> usize;
    unsafe fn get_unchecked(&self, x: usize, y: usize) -> u32;
    fn set(&self, x: usize, y: usize, rgba: u32);
    fn set_multi_from_start_index(
        &self,
        starting_index: usize,
        pixels: &[u8],
    ) -> usize;
    fn as_bytes(&self) -> &[u8] ;

    // Provided methods
    fn get_size(&self) -> usize { ... }
    fn get(&self, x: usize, y: usize) -> Option<u32> { ... }
    fn set_multi(
        &self,
        start_x: usize,
        start_y: usize,
        pixels: &[u8],
    ) -> (usize, usize) { ... }
}

Required Methods§

Source

fn get_width(&self) -> usize

Width in pixels

Source

fn get_height(&self) -> usize

Height in pixels

Source

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

§Safety

make sure x and y are in bounds

Source

fn set(&self, x: usize, y: usize, rgba: u32)

Source

fn set_multi_from_start_index( &self, starting_index: usize, pixels: &[u8], ) -> usize

Returns the number of pixels copied

Source

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

As the pixel memory doesn’t necessarily need to be aligned (think of using shared memory for that), we can only return it as a list of bytes, not a list of pixels.

Provided Methods§

Source

fn get_size(&self) -> usize

Returns the number of pixels (not bytes)

Source

fn get(&self, x: usize, y: usize) -> Option<u32>

In case the coordinates are within the framebuffers area, Some with the current color is returned, None otherwise.

Source

fn set_multi( &self, start_x: usize, start_y: usize, pixels: &[u8], ) -> (usize, usize)

We can not take an &[u32] for the pixel here, as std::slice::from_raw_parts requires the data to be aligned. As the data already is stored in a buffer we can not guarantee it’s correctly aligned, so let’s just treat the pixels as raw bytes.

Returns the coordinates where we landed after filling

Implementors§