1//! # Plane
2//!
3//! Attachment point for a Framebuffer.
4//!
5//! A Plane is a resource that can have a framebuffer attached to it, either for
6//! hardware compositing or displaying directly to a screen. There are three
7//! types of planes available for use:
8//!
9//! * Primary - A CRTC's built-in plane. When attaching a framebuffer to a CRTC,
10//! it is actually being attached to this kind of plane.
11//!
12//! * Overlay - Can be overlaid on top of a primary plane, utilizing extremely
13//! fast hardware compositing.
14//!
15//! * Cursor - Similar to an overlay plane, these are typically used to display
16//! cursor type objects.
17
18use control;
19use drm_ffi as ffi;
20
21/// A handle to a plane
22#[repr(transparent)]
23#[derive(Copy, Clone, Hash, PartialEq, Eq)]
24pub struct Handle(control::RawResourceHandle);
25
26// Safety: Handle is repr(transparent) over NonZeroU32
27unsafe impl bytemuck::ZeroableInOption for Handle {}
28unsafe impl bytemuck::PodInOption for Handle {}
29
30impl From<Handle> for control::RawResourceHandle {
31 fn from(handle: Handle) -> Self {
32 handle.0
33 }
34}
35
36impl From<Handle> for u32 {
37 fn from(handle: Handle) -> Self {
38 handle.0.into()
39 }
40}
41
42impl From<control::RawResourceHandle> for Handle {
43 fn from(handle: control::RawResourceHandle) -> Self {
44 Handle(handle)
45 }
46}
47
48impl control::ResourceHandle for Handle {
49 const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_PLANE;
50}
51
52impl std::fmt::Debug for Handle {
53 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
54 f.debug_tuple(name:"plane::Handle").field(&self.0).finish()
55 }
56}
57
58/// Information about a plane
59#[derive(Debug, Clone, Hash, PartialEq, Eq)]
60pub struct Info {
61 pub(crate) handle: Handle,
62 pub(crate) crtc: Option<control::crtc::Handle>,
63 pub(crate) fb: Option<control::framebuffer::Handle>,
64 pub(crate) pos_crtcs: u32,
65 pub(crate) formats: Vec<u32>,
66}
67
68impl Info {
69 /// Returns the handle to this plane.
70 pub fn handle(&self) -> Handle {
71 self.handle
72 }
73
74 /// Returns the CRTC this plane is attached to.
75 pub fn crtc(&self) -> Option<control::crtc::Handle> {
76 self.crtc
77 }
78
79 /// Returns a filter for supported crtcs of this plane.
80 ///
81 /// Use with [`control::ResourceHandles::filter_crtcs`]
82 /// to receive a list of crtcs.
83 pub fn possible_crtcs(&self) -> control::CrtcListFilter {
84 control::CrtcListFilter(self.pos_crtcs)
85 }
86
87 /// Returns the framebuffer this plane is attached to.
88 pub fn framebuffer(&self) -> Option<control::framebuffer::Handle> {
89 self.fb
90 }
91
92 /// Returns the formats this plane supports.
93 pub fn formats(&self) -> &[u32] {
94 &self.formats
95 }
96}
97