use std::io;
use std::path::PathBuf;
use denise::SurfaceError;
use crate::mode::SelectionError;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DrmError {
#[error("no DRM device found under /dev/dri")]
NoDevice,
#[error("opening {path}")]
Open {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("no DRM device has a display output")]
NoDisplayCapableDevice,
#[error(
"cannot become DRM master — another process (a compositor, or another \
instance of this program) already holds it, or this process lacks the rights"
)]
NotMaster(#[source] io::Error),
#[error("reading DRM resources")]
Resources(#[source] io::Error),
#[error(transparent)]
Selection(#[from] SelectionError),
#[error("no CRTC can drive connector {connector}")]
NoCrtc {
connector: u32,
},
#[error("allocating a {width}x{height} dumb buffer")]
Allocate {
width: u32,
height: u32,
#[source]
source: io::Error,
},
#[error("mapping a dumb buffer")]
Map(#[source] io::Error),
#[error("dumb buffer pitch {pitch} is not a whole number of 32-bit pixels")]
UnalignedPitch {
pitch: u32,
},
#[error("registering a framebuffer")]
AddFramebuffer(#[source] io::Error),
#[error("setting mode {mode} on CRTC {crtc}")]
SetMode {
mode: String,
crtc: u32,
#[source]
source: io::Error,
},
#[error("queueing a page flip")]
PageFlip(#[source] io::Error),
#[error("waiting for vblank")]
WaitVblank(#[source] io::Error),
}
impl From<DrmError> for SurfaceError {
fn from(err: DrmError) -> Self {
SurfaceError::backend(err)
}
}