use crate::control;
use drm_ffi as ffi;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub struct Handle(control::RawResourceHandle);
unsafe impl bytemuck::ZeroableInOption for Handle {}
unsafe impl bytemuck::PodInOption for Handle {}
impl From<Handle> for control::RawResourceHandle {
fn from(handle: Handle) -> Self {
handle.0
}
}
impl From<Handle> for u32 {
fn from(handle: Handle) -> Self {
handle.0.into()
}
}
impl From<control::RawResourceHandle> for Handle {
fn from(handle: control::RawResourceHandle) -> Self {
Handle(handle)
}
}
impl control::ResourceHandle for Handle {
const FFI_TYPE: u32 = ffi::DRM_MODE_OBJECT_CRTC;
}
impl std::fmt::Debug for Handle {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_tuple("crtc::Handle").field(&self.0).finish()
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Info {
pub(crate) handle: Handle,
pub(crate) position: (u32, u32),
pub(crate) mode: Option<control::Mode>,
pub(crate) fb: Option<control::framebuffer::Handle>,
pub(crate) gamma_length: u32,
}
impl std::fmt::Display for Info {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CRTC {}", self.handle.0)
}
}
impl Info {
pub fn handle(&self) -> Handle {
self.handle
}
pub fn position(&self) -> (u32, u32) {
self.position
}
pub fn mode(&self) -> Option<control::Mode> {
self.mode
}
pub fn framebuffer(&self) -> Option<control::framebuffer::Handle> {
self.fb
}
pub fn gamma_length(&self) -> u32 {
self.gamma_length
}
}