framebuffer.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. use crate::{HeaderTagFlag, HeaderTagHeader, HeaderTagType};
  2. use core::mem;
  3. use multiboot2_common::{MaybeDynSized, Tag};
  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))]
  10. pub struct FramebufferHeaderTag {
  11. header: HeaderTagHeader,
  12. width: u32,
  13. height: u32,
  14. depth: u32,
  15. }
  16. impl FramebufferHeaderTag {
  17. /// Constructs a new tag.
  18. #[must_use]
  19. pub const fn new(flags: HeaderTagFlag, width: u32, height: u32, depth: u32) -> Self {
  20. let header =
  21. HeaderTagHeader::new(HeaderTagType::Framebuffer, flags, Self::BASE_SIZE as u32);
  22. Self {
  23. header,
  24. width,
  25. height,
  26. depth,
  27. }
  28. }
  29. /// Returns the [`HeaderTagType`].
  30. #[must_use]
  31. pub const fn typ(&self) -> HeaderTagType {
  32. self.header.typ()
  33. }
  34. /// Returns the [`HeaderTagFlag`]s.
  35. #[must_use]
  36. pub const fn flags(&self) -> HeaderTagFlag {
  37. self.header.flags()
  38. }
  39. /// Returns the size.
  40. #[must_use]
  41. pub const fn size(&self) -> u32 {
  42. self.header.size()
  43. }
  44. /// Returns the width.
  45. #[must_use]
  46. pub const fn width(&self) -> u32 {
  47. self.width
  48. }
  49. /// Returns the height.
  50. #[must_use]
  51. pub const fn height(&self) -> u32 {
  52. self.height
  53. }
  54. /// Returns the depth.
  55. #[must_use]
  56. pub const fn depth(&self) -> u32 {
  57. self.depth
  58. }
  59. }
  60. impl MaybeDynSized for FramebufferHeaderTag {
  61. type Header = HeaderTagHeader;
  62. const BASE_SIZE: usize = mem::size_of::<HeaderTagHeader>() + 3 * mem::size_of::<u32>();
  63. fn dst_len(_header: &Self::Header) -> Self::Metadata {}
  64. }
  65. impl Tag for FramebufferHeaderTag {
  66. type IDType = HeaderTagType;
  67. const ID: HeaderTagType = HeaderTagType::Framebuffer;
  68. }