Skip to main content

multiboot2_header/
framebuffer.rs

1use crate::{HeaderTagFlag, HeaderTagHeader, HeaderTagType};
2use multiboot2_common::{MaybeDynSized, Tag};
3
4/// Specifies the preferred graphics mode. If this tag
5/// is present the bootloader assumes that the payload
6/// has framebuffer support. Note: This is only a
7/// recommended mode. Only relevant on legacy BIOS.
8#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[repr(C, align(8))]
10pub struct FramebufferHeaderTag {
11    header: HeaderTagHeader,
12    width: u32,
13    height: u32,
14    depth: u32,
15}
16
17impl FramebufferHeaderTag {
18    /// Constructs a new tag.
19    #[must_use]
20    pub const fn new(flags: HeaderTagFlag, width: u32, height: u32, depth: u32) -> Self {
21        let header =
22            HeaderTagHeader::new(HeaderTagType::Framebuffer, flags, Self::BASE_SIZE as u32);
23        Self {
24            header,
25            width,
26            height,
27            depth,
28        }
29    }
30
31    /// Returns the [`HeaderTagType`].
32    #[must_use]
33    pub const fn typ(&self) -> HeaderTagType {
34        self.header.typ()
35    }
36
37    /// Returns the [`HeaderTagFlag`]s.
38    #[must_use]
39    pub const fn flags(&self) -> HeaderTagFlag {
40        self.header.flags()
41    }
42
43    /// Returns the size.
44    #[must_use]
45    pub const fn size(&self) -> u32 {
46        self.header.size()
47    }
48
49    /// Returns the width.
50    #[must_use]
51    pub const fn width(&self) -> u32 {
52        self.width
53    }
54
55    /// Returns the height.
56    #[must_use]
57    pub const fn height(&self) -> u32 {
58        self.height
59    }
60
61    /// Returns the depth.
62    #[must_use]
63    pub const fn depth(&self) -> u32 {
64        self.depth
65    }
66}
67
68impl MaybeDynSized for FramebufferHeaderTag {
69    type Header = HeaderTagHeader;
70
71    const BASE_SIZE: usize = size_of::<HeaderTagHeader>() + 3 * size_of::<u32>();
72}
73
74impl Tag for FramebufferHeaderTag {
75    type IDType = HeaderTagType;
76    const ID: HeaderTagType = HeaderTagType::Framebuffer;
77}