breakwater_parser/framebuffer/
mod.rs1pub mod shared_memory;
2pub mod simple;
3
4pub const FB_BYTES_PER_PIXEL: usize = std::mem::size_of::<u32>();
5
6pub trait FrameBuffer {
7 fn get_width(&self) -> usize;
9
10 fn get_height(&self) -> usize;
12
13 #[inline(always)]
15 fn get_size(&self) -> usize {
16 self.get_width() * self.get_height()
17 }
18
19 #[inline(always)]
22 fn get(&self, x: usize, y: usize) -> Option<u32> {
23 if x < self.get_width() && y < self.get_height() {
24 Some(unsafe { self.get_unchecked(x, y) })
25 } else {
26 None
27 }
28 }
29
30 unsafe fn get_unchecked(&self, x: usize, y: usize) -> u32;
33
34 fn set(&self, x: usize, y: usize, rgba: u32);
35
36 #[inline(always)]
42 fn set_multi(&self, start_x: usize, start_y: usize, pixels: &[u8]) -> (usize, usize) {
43 let starting_index = start_x + start_y * self.get_width();
44 let pixels_copied = self.set_multi_from_start_index(starting_index, pixels);
45
46 let new_x = (start_x + pixels_copied) % self.get_width();
47 let new_y = start_y + (pixels_copied / self.get_width());
48
49 (new_x, new_y)
50 }
51
52 fn set_multi_from_start_index(&self, starting_index: usize, pixels: &[u8]) -> usize;
54
55 fn as_bytes(&self) -> &[u8];
58}