1 //! # Encoder 2 //! 3 //! An encoder is a bridge between a CRTC and a connector that takes the pixel 4 //! data of the CRTC and encodes it into a format the connector understands. 5 6 use crate::control; 7 use drm_ffi as ffi; 8 9 /// A handle to an encoder 10 #[repr(transparent)] 11 #[derive(Copy, Clone, Hash, PartialEq, Eq)] 12 pub struct Handle(control::RawResourceHandle); 13 14 // Safety: Handle is repr(transparent) over NonZeroU32 15 unsafe impl bytemuck::ZeroableInOption for Handle {} 16 unsafe impl bytemuck::PodInOption for Handle {} 17 18 impl From<Handle> for control::RawResourceHandle { from(handle: Handle) -> Self19 fn from(handle: Handle) -> Self { 20 handle.0 21 } 22 } 23 24 impl From<Handle> for u32 { from(handle: Handle) -> Self25 fn from(handle: Handle) -> Self { 26 handle.0.into() 27 } 28 } 29 30 impl From<control::RawResourceHandle> for Handle { from(handle: control::RawResourceHandle) -> Self31 fn from(handle: control::RawResourceHandle) -> Self { 32 Handle(handle) 33 } 34 } 35 36 impl control::ResourceHandle for Handle { 37 const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_ENCODER; 38 } 39 40 impl std::fmt::Debug for Handle { fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result41 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 42 f.debug_tuple("encoder::Handle").field(&self.0).finish() 43 } 44 } 45 46 /// Information about an encoder 47 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] 48 pub struct Info { 49 pub(crate) handle: Handle, 50 pub(crate) enc_type: Kind, 51 pub(crate) crtc: Option<control::crtc::Handle>, 52 pub(crate) pos_crtcs: u32, 53 pub(crate) pos_clones: u32, 54 } 55 56 impl Info { 57 /// Returns the handle to this encoder. handle(&self) -> Handle58 pub fn handle(&self) -> Handle { 59 self.handle 60 } 61 62 /// Returns the `Kind` of encoder this is. kind(&self) -> Kind63 pub fn kind(&self) -> Kind { 64 self.enc_type 65 } 66 67 /// Returns a handle to the CRTC this encoder is attached to. crtc(&self) -> Option<control::crtc::Handle>68 pub fn crtc(&self) -> Option<control::crtc::Handle> { 69 self.crtc 70 } 71 72 /// Returns a filter for the possible CRTCs that can use this encoder. 73 /// 74 /// Use with [`control::ResourceHandles::filter_crtcs`] 75 /// to receive a list of crtcs. possible_crtcs(&self) -> control::CrtcListFilter76 pub fn possible_crtcs(&self) -> control::CrtcListFilter { 77 control::CrtcListFilter(self.pos_crtcs) 78 } 79 80 /// Returns a filter for the possible encoders that clones this one. possible_clones(&self)81 pub fn possible_clones(&self) { 82 unimplemented!() 83 } 84 } 85 86 /// The type of encoder. 87 #[allow(missing_docs)] 88 #[allow(clippy::upper_case_acronyms)] 89 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] 90 pub enum Kind { 91 None, 92 DAC, 93 TMDS, 94 LVDS, 95 TVDAC, 96 Virtual, 97 DSI, 98 DPMST, 99 DPI, 100 } 101 102 impl From<u32> for Kind { from(n: u32) -> Self103 fn from(n: u32) -> Self { 104 match n { 105 ffi::DRM_MODE_ENCODER_NONE => Kind::None, 106 ffi::DRM_MODE_ENCODER_DAC => Kind::DAC, 107 ffi::DRM_MODE_ENCODER_TMDS => Kind::TMDS, 108 ffi::DRM_MODE_ENCODER_LVDS => Kind::LVDS, 109 ffi::DRM_MODE_ENCODER_TVDAC => Kind::TVDAC, 110 ffi::DRM_MODE_ENCODER_VIRTUAL => Kind::Virtual, 111 ffi::DRM_MODE_ENCODER_DSI => Kind::DSI, 112 ffi::DRM_MODE_ENCODER_DPMST => Kind::DPMST, 113 ffi::DRM_MODE_ENCODER_DPI => Kind::DPI, 114 _ => Kind::None, 115 } 116 } 117 } 118 119 impl From<Kind> for u32 { from(kind: Kind) -> Self120 fn from(kind: Kind) -> Self { 121 match kind { 122 Kind::None => ffi::DRM_MODE_ENCODER_NONE, 123 Kind::DAC => ffi::DRM_MODE_ENCODER_DAC, 124 Kind::TMDS => ffi::DRM_MODE_ENCODER_TMDS, 125 Kind::LVDS => ffi::DRM_MODE_ENCODER_LVDS, 126 Kind::TVDAC => ffi::DRM_MODE_ENCODER_TVDAC, 127 Kind::Virtual => ffi::DRM_MODE_ENCODER_VIRTUAL, 128 Kind::DSI => ffi::DRM_MODE_ENCODER_DSI, 129 Kind::DPMST => ffi::DRM_MODE_ENCODER_DPMST, 130 Kind::DPI => ffi::DRM_MODE_ENCODER_DPI, 131 } 132 } 133 } 134