framebuffer.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. use crate::{HeaderTagFlag, HeaderTagType};
  2. use core::mem::size_of;
  3. /// Specifies the preferred graphics mode. If this tag
  4. /// is present the bootloader assumes that the payload
  5. /// has framebuffer support. Note: This is only a
  6. /// recommended mode. Only relevant on legacy BIOS.
  7. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
  8. #[repr(C)]
  9. pub struct FramebufferHeaderTag {
  10. typ: HeaderTagType,
  11. flags: HeaderTagFlag,
  12. size: u32,
  13. width: u32,
  14. height: u32,
  15. depth: u32,
  16. }
  17. impl FramebufferHeaderTag {
  18. pub const fn new(flags: HeaderTagFlag, width: u32, height: u32, depth: u32) -> Self {
  19. FramebufferHeaderTag {
  20. typ: HeaderTagType::Framebuffer,
  21. flags,
  22. size: size_of::<Self>() as u32,
  23. width,
  24. height,
  25. depth,
  26. }
  27. }
  28. pub const fn typ(&self) -> HeaderTagType {
  29. self.typ
  30. }
  31. pub const fn flags(&self) -> HeaderTagFlag {
  32. self.flags
  33. }
  34. pub const fn size(&self) -> u32 {
  35. self.size
  36. }
  37. pub const fn width(&self) -> u32 {
  38. self.width
  39. }
  40. pub const fn height(&self) -> u32 {
  41. self.height
  42. }
  43. pub const fn depth(&self) -> u32 {
  44. self.depth
  45. }
  46. }
  47. #[cfg(test)]
  48. mod tests {
  49. use crate::FramebufferHeaderTag;
  50. #[test]
  51. fn test_assert_size() {
  52. assert_eq!(
  53. core::mem::size_of::<FramebufferHeaderTag>(),
  54. 2 + 2 + 4 + 4 + 4 + 4
  55. );
  56. }
  57. }