Skip to main content

proka_bootloader/
output.rs

1//! The output module, which provides framebuffer info and
2//! its utilities.
3
4/// The framebuffer structure, which provides basic 5
5/// elements.
6///
7/// - Framebuffer base address;
8/// - Framebuffer height;
9/// - Framebuffer width;
10/// - Framebuffer BPB
11/// - Framebuffer pitch
12///
13/// You can use it to do output/graphics operations.
14///
15/// If you want to compute the offset, you can use this:
16///
17/// `offset = x * bpp + y * pitch`
18#[repr(C, packed)]
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20#[cfg_attr(feature = "default", derive(Default))]
21pub struct Framebuffer {
22    fb_addr: u64,
23    width: u64,
24    height: u64,
25    bpp: u64,
26    pitch: u64,
27}
28
29impl Framebuffer {
30    /// Creates a nee framebuffer object.
31    ///
32    /// Note: This method will automatically create by
33    /// bootloader entry, if you are using kernel, this
34    /// method is not needed and not usable.
35    #[cfg(feature = "loader_main")]
36    pub fn new(addr: u64, width: u64, height: u64, bpp: u64, pitch: u64) -> Self {
37        Self {
38            fb_addr: addr,
39            width,
40            height,
41            bpp,
42            pitch,
43        }
44    }
45
46    /// Get the framebuffer address.
47    pub fn address(&self) -> u64 {
48        self.fb_addr
49    }
50
51    /// Get the framebuffer width.
52    pub fn width(&self) -> u64 {
53        self.width
54    }
55
56    /// Get the framebuffer height.
57    pub fn height(&self) -> u64 {
58        self.height
59    }
60
61    /// Get the framebuffer BPP.
62    pub fn bpp(&self) -> u64 {
63        self.bpp
64    }
65
66    /// Get the framebuffer pitch.
67    pub fn pitch(&self) -> u64 {
68        self.pitch
69    }
70}