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. 14 15 use crate::control; 16 use drm_ffi as ffi; 17 18 /// A handle to a specific CRTC 19 #[repr(transparent)] 20 #[derive(Copy, Clone, Hash, PartialEq, Eq)] 21 pub struct Handle(control::RawResourceHandle); 22 23 // Safety: Handle is repr(transparent) over NonZeroU32 24 unsafe impl bytemuck::ZeroableInOption for Handle {} 25 unsafe impl bytemuck::PodInOption for Handle {} 26 27 impl From<Handle> for control::RawResourceHandle { from(handle: Handle) -> Self28 fn from(handle: Handle) -> Self { 29 handle.0 30 } 31 } 32 33 impl From<Handle> for u32 { from(handle: Handle) -> Self34 fn from(handle: Handle) -> Self { 35 handle.0.into() 36 } 37 } 38 39 impl From<control::RawResourceHandle> for Handle { from(handle: control::RawResourceHandle) -> Self40 fn from(handle: control::RawResourceHandle) -> Self { 41 Handle(handle) 42 } 43 } 44 45 impl control::ResourceHandle for Handle { 46 const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_CRTC; 47 } 48 49 impl std::fmt::Debug for Handle { fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result50 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 51 f.debug_tuple("crtc::Handle").field(&self.0).finish() 52 } 53 } 54 55 /// Information about a specific CRTC 56 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] 57 pub struct Info { 58 pub(crate) handle: Handle, 59 pub(crate) position: (u32, u32), 60 pub(crate) mode: Option<control::Mode>, 61 pub(crate) fb: Option<control::framebuffer::Handle>, 62 pub(crate) gamma_length: u32, 63 } 64 65 impl std::fmt::Display for Info { fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result66 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 67 write!(f, "CRTC {}", self.handle.0) 68 } 69 } 70 71 impl Info { 72 /// Returns the handle to this CRTC. handle(&self) -> Handle73 pub fn handle(&self) -> Handle { 74 self.handle 75 } 76 77 /// Returns the position of the CRTC. position(&self) -> (u32, u32)78 pub fn position(&self) -> (u32, u32) { 79 self.position 80 } 81 82 /// Returns the current mode of the CRTC. mode(&self) -> Option<control::Mode>83 pub fn mode(&self) -> Option<control::Mode> { 84 self.mode 85 } 86 87 /// Returns the framebuffer currently attached to this CRTC. framebuffer(&self) -> Option<control::framebuffer::Handle>88 pub fn framebuffer(&self) -> Option<control::framebuffer::Handle> { 89 self.fb 90 } 91 92 /// Returns the size of the gamma LUT. gamma_length(&self) -> u3293 pub fn gamma_length(&self) -> u32 { 94 self.gamma_length 95 } 96 } 97