1//! # Framebuffer
2//!
3//! Process specific GPU buffers that can be attached to a plane.
4
5use buffer;
6use control;
7use drm_ffi as ffi;
8use drm_fourcc::{DrmFourcc, DrmModifier};
9
10/// A handle to a framebuffer
11#[repr(transparent)]
12#[derive(Copy, Clone, Hash, PartialEq, Eq)]
13pub struct Handle(control::RawResourceHandle);
14
15// Safety: Handle is repr(transparent) over NonZeroU32
16unsafe impl bytemuck::ZeroableInOption for Handle {}
17unsafe impl bytemuck::PodInOption for Handle {}
18
19impl From<Handle> for control::RawResourceHandle {
20 fn from(handle: Handle) -> Self {
21 handle.0
22 }
23}
24
25impl From<Handle> for u32 {
26 fn from(handle: Handle) -> Self {
27 handle.0.into()
28 }
29}
30
31impl From<control::RawResourceHandle> for Handle {
32 fn from(handle: control::RawResourceHandle) -> Self {
33 Handle(handle)
34 }
35}
36
37impl control::ResourceHandle for Handle {
38 const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_FB;
39}
40
41impl std::fmt::Debug for Handle {
42 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
43 f.debug_tuple(name:"framebuffer::Handle").field(&self.0).finish()
44 }
45}
46
47/// Information about a framebuffer
48#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
49pub struct Info {
50 pub(crate) handle: Handle,
51 pub(crate) size: (u32, u32),
52 pub(crate) pitch: u32,
53 pub(crate) bpp: u32,
54 pub(crate) depth: u32,
55 pub(crate) buffer: Option<buffer::Handle>,
56}
57
58impl Info {
59 /// Returns the handle to this framebuffer.
60 pub fn handle(&self) -> Handle {
61 self.handle
62 }
63
64 /// Returns the size of this framebuffer.
65 pub fn size(&self) -> (u32, u32) {
66 self.size
67 }
68
69 /// Returns the pitch of this framebuffer.
70 pub fn pitch(&self) -> u32 {
71 self.pitch
72 }
73
74 /// Returns the bits-per-pixel of this framebuffer.
75 pub fn bpp(&self) -> u32 {
76 self.bpp
77 }
78
79 /// Returns the depth of this framebuffer.
80 pub fn depth(&self) -> u32 {
81 self.depth
82 }
83
84 /// Returns the buffer handle of this framebuffer.
85 pub fn buffer(&self) -> Option<buffer::Handle> {
86 self.buffer
87 }
88}
89
90/// Information about a framebuffer (with modifiers)
91#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
92pub struct PlanarInfo {
93 pub(crate) handle: Handle,
94 pub(crate) size: (u32, u32),
95 pub(crate) pixel_format: DrmFourcc,
96 pub(crate) flags: u32,
97 pub(crate) buffers: [Option<buffer::Handle>; 4],
98 pub(crate) pitches: [u32; 4],
99 pub(crate) offsets: [u32; 4],
100 pub(crate) modifier: [DrmModifier; 4],
101}
102
103impl PlanarInfo {
104 /// Returns the handle to this framebuffer.
105 pub fn handle(&self) -> Handle {
106 self.handle
107 }
108
109 /// Returns the size of this framebuffer.
110 pub fn size(&self) -> (u32, u32) {
111 self.size
112 }
113
114 /// Returns the pixel format of this framebuffer.
115 pub fn pixel_format(&self) -> DrmFourcc {
116 self.pixel_format
117 }
118
119 /// Returns the flags of this framebuffer.
120 pub fn flags(&self) -> u32 {
121 self.flags
122 }
123
124 /// Returns the buffer handles of this framebuffer.
125 pub fn buffers(&self) -> [Option<buffer::Handle>; 4] {
126 self.buffers
127 }
128
129 /// Returns the pitches of this framebuffer.
130 pub fn pitches(&self) -> [u32; 4] {
131 self.pitches
132 }
133
134 /// Returns the offsets of this framebuffer.
135 pub fn offsets(&self) -> [u32; 4] {
136 self.offsets
137 }
138
139 /// Returns the modifier of this framebuffer.
140 pub fn modifier(&self) -> [DrmModifier; 4] {
141 self.modifier
142 }
143}
144