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§
Sourcefn get_height(&self) -> usize
fn get_height(&self) -> usize
Height in pixels
Sourceunsafe fn get_unchecked(&self, x: usize, y: usize) -> u32
unsafe fn get_unchecked(&self, x: usize, y: usize) -> u32
§Safety
make sure x and y are in bounds
fn set(&self, x: usize, y: usize, rgba: u32)
Sourcefn set_multi_from_start_index(
&self,
starting_index: usize,
pixels: &[u8],
) -> usize
fn set_multi_from_start_index( &self, starting_index: usize, pixels: &[u8], ) -> usize
Returns the number of pixels copied
Provided Methods§
Sourcefn set_multi(
&self,
start_x: usize,
start_y: usize,
pixels: &[u8],
) -> (usize, usize)
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