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#[repr(C)]
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct Framebuffer {
17 fb_addr: u64,
18 width: u32,
19 height: u32,
20 bpp: u8,
21 pitch: u16,
22}
23
24impl Framebuffer {
25 /// Creates a nee framebuffer object.
26 ///
27 /// Note: This method will automatically create by
28 /// bootloader entry, if you are using kernel, this
29 /// method is not needed and not usable.
30 #[cfg(feature = "loader_main")]
31 pub fn new(addr: u64, width: u32, height: u32, bpp: u8, pitch: u16) -> Self {
32 Self {
33 fb_addr: addr,
34 width,
35 height,
36 bpp,
37 pitch,
38 }
39 }
40
41 /// Get the framebuffer address.
42 pub fn address(&self) -> u64 {
43 self.fb_addr
44 }
45
46 /// Get the framebuffer width.
47 pub fn width(&self) -> u32 {
48 self.width
49 }
50
51 /// Get the framebuffer height.
52 pub fn height(&self) -> u32 {
53 self.height
54 }
55
56 /// Get the framebuffer BPP.
57 pub fn bpp(&self) -> u8 {
58 self.bpp
59 }
60
61 /// Get the framebuffer pitch.
62 pub fn pitch(&self) -> u16 {
63 self.pitch
64 }
65}