From ed257e8991e9a8f8c562c3354361a4996b5bdd99 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sun, 19 Apr 2020 01:30:05 +0200 Subject: [PATCH] drm: move legacy::Error into common module --- src/backend/drm/common/mod.rs | 68 +++++++++++++++++++++++++++++++ src/backend/drm/legacy/mod.rs | 46 ++------------------- src/backend/drm/legacy/surface.rs | 6 +-- src/backend/drm/mod.rs | 2 + 4 files changed, 76 insertions(+), 46 deletions(-) create mode 100644 src/backend/drm/common/mod.rs diff --git a/src/backend/drm/common/mod.rs b/src/backend/drm/common/mod.rs new file mode 100644 index 0000000..9e89a0b --- /dev/null +++ b/src/backend/drm/common/mod.rs @@ -0,0 +1,68 @@ +//! +//! Module for common/shared types of the various [`Device`](::backend::drm::Device) +//! and [`Surface`](::backend::drm::Surface) implementations of the `backend::drm` module. +//! + +use drm::control::{connector, crtc, Mode, RawResourceHandle}; + +use std::path::PathBuf; + +/// Errors thrown by the [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice), +/// [`AtomicDrmDevice`](::backend::drm::atomic::AtomicDrmDevice) +/// and their surfaces: [`LegacyDrmSurface`](::backend::drm::legacy::LegacyDrmSurface) +/// and [`AtomicDrmSurface`](::backend::drm::atomic::AtomicDrmSurface). +#[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 + #[error("DRM access error: {errmsg} on device `{dev:?}`")] + Access { + /// Error message associated to the access error + errmsg: &'static str, + /// Device on which the error was generated + dev: Option, + /// Underlying device error + source: failure::Compat, + }, + /// 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), + /// 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, + }, + /// No matching primary and cursor plane could be found for the given crtc + #[error("No matching primary and cursor plane could be found for crtc {crtc:?} on {dev:?}")] + NoSuitablePlanes { + /// CRTC + crtc: crtc::Handle, + /// Device on which the error was generated + dev: Option, + }, + /// 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), +} diff --git a/src/backend/drm/legacy/mod.rs b/src/backend/drm/legacy/mod.rs index 9d5d502..9a40e03 100644 --- a/src/backend/drm/legacy/mod.rs +++ b/src/backend/drm/legacy/mod.rs @@ -5,13 +5,13 @@ //! Usually this implementation will be wrapped into a [`GbmDevice`](::backend::drm::gbm::GbmDevice). //! Take a look at `anvil`s source code for an example of this. //! -//! For an example how to use this standalone, take a look at the `raw_drm` example. +//! For an example how to use this standalone, take a look at the `raw_legacy_drm` example. //! -use super::{DevPath, Device, DeviceHandler, RawDevice}; +use super::{common::Error, DevPath, Device, DeviceHandler, RawDevice}; use drm::control::{ - connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Event, Mode, ResourceHandles, + connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Event, ResourceHandles, }; use drm::{Device as BasicDevice, SystemError as DrmError}; use nix::libc::dev_t; @@ -20,7 +20,6 @@ use nix::sys::stat::fstat; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::os::unix::io::{AsRawFd, RawFd}; -use std::path::PathBuf; use std::rc::{Rc, Weak}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; @@ -34,45 +33,6 @@ use self::surface::{LegacyDrmSurfaceInternal, State}; #[cfg(feature = "backend_session")] pub mod session; -/// Errors thrown by the [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice) -/// and [`LegacyDrmSurface`](::backend::drm::legacy::LegacyDrmSurface). -#[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 - #[error("DRM access error: {errmsg} on device `{dev:?}`")] - Access { - /// Error message associated to the access error - errmsg: &'static str, - /// Device on which the error was generated - dev: Option, - /// Underlying device error - source: failure::Compat, - }, - /// 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), - /// 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, - }, -} - /// Open raw drm device utilizing legacy mode-setting pub struct LegacyDrmDevice { dev: Rc>, diff --git a/src/backend/drm/legacy/surface.rs b/src/backend/drm/legacy/surface.rs index 3ac3bb5..c459924 100644 --- a/src/backend/drm/legacy/surface.rs +++ b/src/backend/drm/legacy/surface.rs @@ -10,13 +10,13 @@ use std::os::unix::io::{AsRawFd, RawFd}; use std::rc::Rc; use std::sync::RwLock; -use crate::backend::drm::{DevPath, RawSurface, Surface}; +use crate::backend::drm::{common::Error, DevPath, RawSurface, Surface}; use crate::backend::graphics::CursorBackend; use crate::backend::graphics::SwapBuffersError; -use super::{Dev, Error}; +use super::Dev; -use failure::ResultExt; +use failure::{Fail, ResultExt}; #[derive(Debug, PartialEq, Eq, Clone)] pub struct State { diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index c3204d6..148a5ab 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -53,6 +53,8 @@ use calloop::{LoopHandle, Source}; use super::graphics::SwapBuffersError; +#[cfg(feature = "backend_drm")] +pub mod common; #[cfg(feature = "backend_drm_egl")] pub mod egl; #[cfg(feature = "backend_drm_gbm")]