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.
1718use crate::control;
19use drm_ffi as ffi;
2021/// A handle to a plane
22#[repr(transparent)]
23#[derive(Copy, Clone, Hash, PartialEq, Eq)]
24pub struct Handle(control::RawResourceHandle);
2526// Safety: Handle is repr(transparent) over NonZeroU32
27unsafe impl bytemuck::ZeroableInOption for Handle {}
28unsafe impl bytemuck::PodInOption for Handle {}
2930impl From<Handle> for control::RawResourceHandle {
31fn from(handle: Handle) -> Self {
32 handle.0
33}
34}
3536impl From<Handle> for u32 {
37fn from(handle: Handle) -> Self {
38 handle.0.into()
39 }
40}
4142impl From<control::RawResourceHandle> for Handle {
43fn from(handle: control::RawResourceHandle) -> Self {
44 Handle(handle)
45 }
46}
4748impl control::ResourceHandle for Handle {
49const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_PLANE;
50}
5152impl std::fmt::Debug for Handle {
53fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
54 f.debug_tuple("plane::Handle").field(&self.0).finish()
55 }
56}
5758/// Information about a plane
59#[derive(Debug, Clone, Hash, PartialEq, Eq)]
60pub struct Info {
61pub(crate) handle: Handle,
62pub(crate) crtc: Option<control::crtc::Handle>,
63pub(crate) fb: Option<control::framebuffer::Handle>,
64pub(crate) pos_crtcs: u32,
65pub(crate) formats: Vec<u32>,
66}
6768impl std::fmt::Display for Info {
69fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70write!(f, "Plane {}", self.handle.0)
71 }
72}
7374impl Info {
75/// Returns the handle to this plane.
76pub fn handle(&self) -> Handle {
77self.handle
78 }
7980/// Returns the CRTC this plane is attached to.
81pub fn crtc(&self) -> Option<control::crtc::Handle> {
82self.crtc
83 }
8485/// Returns a filter for supported crtcs of this plane.
86 ///
87 /// Use with [`control::ResourceHandles::filter_crtcs`]
88 /// to receive a list of crtcs.
89pub fn possible_crtcs(&self) -> control::CrtcListFilter {
90 control::CrtcListFilter(self.pos_crtcs)
91 }
9293/// Returns the framebuffer this plane is attached to.
94pub fn framebuffer(&self) -> Option<control::framebuffer::Handle> {
95self.fb
96 }
9798/// Returns the formats this plane supports.
99pub fn formats(&self) -> &[u32] {
100&self.formats
101 }
102}