1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/// The framebuffer info passed by the bootloader
/// and based on the configuration in the stivale2 header
#[repr(packed)]
pub struct FramebufferTag {
    _identifier: u64,
    _next: u64,
    address: u64,
    width: u16,
    height: u16,
    pitch: u16,
    bpp: u16,
}

impl FramebufferTag {
    /// Get the start address of the framebuffer
    pub fn start_address(&self) -> usize {
        self.address as usize
    }

    /// Get the end address of the framebuffer
    /// 
    /// Identical to `framebuffer_info.start_address() + framebuffer_info.size()`
    pub fn end_address(&self) -> usize {
        self.address as usize + self.size()
    }

    /// Get the size of the framebuffer
    pub fn size(&self) -> usize {
        self.pitch as usize * self.height as usize * (self.bpp as usize / 8)
    }

    /// Get the width of the framebuffer in pixels
    pub fn width(&self) -> u16 {
        self.width
    }

    /// Get the height of the framebuffer in pixels
    pub fn height(&self) -> u16 {
        self.height
    }

    /// Get the bytes per line of the framebuffer
    pub fn pitch(&self) -> u16 {
        self.pitch
    }

    /// Get the bits per pixel of the framebuffer
    pub fn bpp(&self) -> u16 {
        self.bpp
    }
}