multiboot2_header/
framebuffer.rs

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