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] ;
    fn as_pixels(&self) -> &[u32];

    // 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

Source

fn get_height(&self) -> usize

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]

Source

fn as_pixels(&self) -> &[u32]

Provided Methods§

Source

fn get_size(&self) -> usize

Source

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

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§