1//! # CRTC
2//!
3//! A CRTC is a display controller provided by your device. It's primary job is
4//! to take pixel data and send it to a connector with the proper resolution and
5//! frequencies.
6//!
7//! Specific CRTCs can only be attached to connectors that have an encoder it
8//! supports. For example, you can have a CRTC that can not output to analog
9//! connectors. These are built in hardware limitations.
10//!
11//! Each CRTC has a built in plane, which can have a framebuffer attached to it,
12//! but they can also use pixel data from other planes to perform hardware
13//! compositing.
1415use crate::control;
16use drm_ffi as ffi;
1718/// A handle to a specific CRTC
19#[repr(transparent)]
20#[derive(Copy, Clone, Hash, PartialEq, Eq)]
21pub struct Handle(control::RawResourceHandle);
2223// Safety: Handle is repr(transparent) over NonZeroU32
24unsafe impl bytemuck::ZeroableInOption for Handle {}
25unsafe impl bytemuck::PodInOption for Handle {}
2627impl From<Handle> for control::RawResourceHandle {
28fn from(handle: Handle) -> Self {
29 handle.0
30}
31}
3233impl From<Handle> for u32 {
34fn from(handle: Handle) -> Self {
35 handle.0.into()
36 }
37}
3839impl From<control::RawResourceHandle> for Handle {
40fn from(handle: control::RawResourceHandle) -> Self {
41 Handle(handle)
42 }
43}
4445impl control::ResourceHandle for Handle {
46const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_CRTC;
47}
4849impl std::fmt::Debug for Handle {
50fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
51 f.debug_tuple("crtc::Handle").field(&self.0).finish()
52 }
53}
5455/// Information about a specific CRTC
56#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
57pub struct Info {
58pub(crate) handle: Handle,
59pub(crate) position: (u32, u32),
60pub(crate) mode: Option<control::Mode>,
61pub(crate) fb: Option<control::framebuffer::Handle>,
62pub(crate) gamma_length: u32,
63}
6465impl std::fmt::Display for Info {
66fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67write!(f, "CRTC {}", self.handle.0)
68 }
69}
7071impl Info {
72/// Returns the handle to this CRTC.
73pub fn handle(&self) -> Handle {
74self.handle
75 }
7677/// Returns the position of the CRTC.
78pub fn position(&self) -> (u32, u32) {
79self.position
80 }
8182/// Returns the current mode of the CRTC.
83pub fn mode(&self) -> Option<control::Mode> {
84self.mode
85 }
8687/// Returns the framebuffer currently attached to this CRTC.
88pub fn framebuffer(&self) -> Option<control::framebuffer::Handle> {
89self.fb
90 }
9192/// Returns the size of the gamma LUT.
93pub fn gamma_length(&self) -> u32 {
94self.gamma_length
95 }
96}