2021-04-28 22:32:47 +00:00
|
|
|
use crate::backend::SwapBuffersError;
|
2021-04-06 22:16:46 +00:00
|
|
|
use drm::control::{connector, crtc, plane, Mode, RawResourceHandle};
|
2020-04-18 23:30:05 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2021-05-24 17:15:46 +00:00
|
|
|
/// Errors thrown by the [`DrmDevice`](crate::backend::drm::DrmDevice)
|
|
|
|
/// and the [`DrmSurface`](crate::backend::drm::DrmSurface).
|
2020-04-18 23:30:05 +00:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
/// Unable to acquire DRM master
|
|
|
|
#[error("Failed to aquire DRM master")]
|
|
|
|
DrmMasterFailed,
|
|
|
|
/// The `DrmDevice` encountered an access error
|
2020-04-26 22:42:33 +00:00
|
|
|
#[error("DRM access error: {errmsg} on device `{dev:?}` ({source:})")]
|
2020-04-18 23:30:05 +00:00
|
|
|
Access {
|
|
|
|
/// Error message associated to the access error
|
|
|
|
errmsg: &'static str,
|
|
|
|
/// Device on which the error was generated
|
|
|
|
dev: Option<PathBuf>,
|
|
|
|
/// Underlying device error
|
2021-04-06 22:16:46 +00:00
|
|
|
source: drm::SystemError,
|
2020-04-18 23:30:05 +00:00
|
|
|
},
|
|
|
|
/// Unable to determine device id of drm device
|
|
|
|
#[error("Unable to determine device id of drm device")]
|
|
|
|
UnableToGetDeviceId(#[source] nix::Error),
|
|
|
|
/// Device is currently paused
|
|
|
|
#[error("Device is currently paused, operation rejected")]
|
|
|
|
DeviceInactive,
|
|
|
|
/// Mode is not compatible with all given connectors
|
|
|
|
#[error("Mode `{0:?}` is not compatible with all given connectors")]
|
|
|
|
ModeNotSuitable(Mode),
|
|
|
|
/// The given crtc is already in use by another backend
|
|
|
|
#[error("Crtc `{0:?}` is already in use by another backend")]
|
|
|
|
CrtcAlreadyInUse(crtc::Handle),
|
2020-04-26 14:32:44 +00:00
|
|
|
/// This operation would result in a surface without connectors.
|
|
|
|
#[error("Surface of crtc `{0:?}` would have no connectors, which is not accepted")]
|
|
|
|
SurfaceWithoutConnectors(crtc::Handle),
|
2021-04-30 15:21:35 +00:00
|
|
|
/// The given plane cannot be used with the given crtc
|
2021-04-06 22:16:46 +00:00
|
|
|
#[error("Plane `{1:?}` is not compatible for use with crtc `{0:?}`")]
|
|
|
|
PlaneNotCompatible(crtc::Handle, plane::Handle),
|
2021-04-30 15:21:35 +00:00
|
|
|
/// The given plane is not a primary plane and therefor not supported by the underlying implementation
|
2021-04-06 22:16:46 +00:00
|
|
|
#[error("Non-Primary Planes (provided was `{0:?}`) are not available for use with legacy devices")]
|
|
|
|
NonPrimaryPlane(plane::Handle),
|
2020-04-18 23:30:05 +00:00
|
|
|
/// No encoder was found for a given connector on the set crtc
|
|
|
|
#[error("No encoder found for the given connector '{connector:?}' on crtc `{crtc:?}`")]
|
|
|
|
NoSuitableEncoder {
|
|
|
|
/// Connector
|
|
|
|
connector: connector::Handle,
|
|
|
|
/// CRTC
|
|
|
|
crtc: crtc::Handle,
|
|
|
|
},
|
|
|
|
/// The DrmDevice is missing a required property
|
|
|
|
#[error("The DrmDevice is missing a required property '{name}' for handle ({handle:?})")]
|
|
|
|
UnknownProperty {
|
|
|
|
/// Property handle
|
|
|
|
handle: RawResourceHandle,
|
|
|
|
/// Property name
|
|
|
|
name: &'static str,
|
|
|
|
},
|
|
|
|
/// Atomic Test failed for new properties
|
|
|
|
#[error("Atomic Test failed for new properties on crtc ({0:?})")]
|
|
|
|
TestFailed(crtc::Handle),
|
|
|
|
}
|
2020-04-29 22:24:35 +00:00
|
|
|
|
2021-04-28 22:31:49 +00:00
|
|
|
impl From<Error> for SwapBuffersError {
|
|
|
|
fn from(err: Error) -> SwapBuffersError {
|
|
|
|
match err {
|
2020-04-29 22:24:35 +00:00
|
|
|
x @ Error::DeviceInactive => SwapBuffersError::TemporaryFailure(Box::new(x)),
|
2020-05-03 18:28:20 +00:00
|
|
|
Error::Access {
|
|
|
|
errmsg, dev, source, ..
|
2021-04-28 22:32:47 +00:00
|
|
|
} if matches!(
|
|
|
|
source,
|
|
|
|
drm::SystemError::PermissionDenied
|
|
|
|
| drm::SystemError::Unknown {
|
|
|
|
errno: nix::errno::Errno::EBUSY,
|
|
|
|
}
|
|
|
|
| drm::SystemError::Unknown {
|
|
|
|
errno: nix::errno::Errno::EINTR,
|
|
|
|
}
|
2021-04-28 22:31:49 +00:00
|
|
|
) =>
|
2020-04-30 17:03:02 +00:00
|
|
|
{
|
2020-05-03 15:56:43 +00:00
|
|
|
SwapBuffersError::TemporaryFailure(Box::new(Error::Access { errmsg, dev, source }))
|
2020-05-03 18:28:20 +00:00
|
|
|
}
|
2020-04-29 22:24:35 +00:00
|
|
|
x => SwapBuffersError::ContextLost(Box::new(x)),
|
|
|
|
}
|
|
|
|
}
|
2021-04-28 22:32:47 +00:00
|
|
|
}
|