emerald_kernel_user_link/
graphics.rs1#[repr(u64)]
2#[derive(Debug, Clone, Copy)]
3#[non_exhaustive]
4pub enum GraphicsCommand {
5 TakeOwnership,
8 ReleaseOwnership,
11 GetFrameBufferInfo,
14 Blit,
18}
19
20impl GraphicsCommand {
21 pub fn from_u64(value: u64) -> Option<Self> {
22 match value {
23 0 => Some(Self::TakeOwnership),
24 1 => Some(Self::ReleaseOwnership),
25 2 => Some(Self::GetFrameBufferInfo),
26 3 => Some(Self::Blit),
27 _ => None,
28 }
29 }
30
31 pub fn to_u64(self) -> u64 {
32 self as u64
33 }
34}
35
36#[repr(C)]
37#[derive(Debug, Clone, Copy)]
38pub struct FrameBufferInfo {
39 pub pitch: usize,
40 pub height: usize,
41 pub width: usize,
42 pub field_pos: (u8, u8, u8),
43 pub mask: (u8, u8, u8),
44 pub byte_per_pixel: u8,
45}
46
47impl FrameBufferInfo {
48 pub fn memory_size(&self) -> usize {
50 self.pitch * self.height
51 }
52
53 pub fn get_arr_pos(&self, pos: (usize, usize)) -> Option<usize> {
56 if pos.0 >= self.width || pos.1 >= self.height {
57 return None;
58 }
59 Some(pos.0 * self.byte_per_pixel as usize + pos.1 * self.pitch)
60 }
61
62 pub fn pixel_mem<'a>(&self, memory: &'a [u8], pos: (usize, usize)) -> Option<&'a [u8]> {
64 let i = self.get_arr_pos(pos)?;
65 Some(&memory[i..i + self.byte_per_pixel as usize])
66 }
67
68 pub fn pixel_mem_mut<'a>(
70 &self,
71 memory: &'a mut [u8],
72 pos: (usize, usize),
73 ) -> Option<&'a mut [u8]> {
74 let i = self.get_arr_pos(pos)?;
75 Some(&mut memory[i..i + self.byte_per_pixel as usize])
76 }
77}
78
79#[repr(C)]
80#[derive(Debug, Clone, Copy)]
81pub struct BlitCommand {
82 pub memory: *const u8,
85 pub src_framebuffer_info: FrameBufferInfo,
88 pub src: (usize, usize),
90 pub dst: (usize, usize),
93 pub size: (usize, usize),
95}