From de526f4b2316867daad87e12f61ce8251e9844c9 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Thu, 22 Nov 2018 10:07:17 +0100 Subject: [PATCH] drm: Add functions to query device state --- src/backend/drm/egl/mod.rs | 21 ++++++++++++++++++++- src/backend/drm/gbm/mod.rs | 21 ++++++++++++++++++++- src/backend/drm/legacy/mod.rs | 24 +++++++++++++++++------- src/backend/drm/mod.rs | 18 +++++++++++------- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index ccd7fd2..802cf30 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -1,4 +1,5 @@ -use drm::control::{crtc, Mode}; +use drm::control::{connector, crtc, Mode, ResourceHandles, ResourceInfo}; +use nix::libc::dev_t; use std::cell::RefCell; use std::iter::FromIterator; use std::os::unix::io::{AsRawFd, RawFd}; @@ -123,6 +124,10 @@ where { type Surface = EglSurface; + fn device_id(&self) -> dev_t { + self.dev.borrow().device_id() + } + fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { self.dev.borrow_mut().set_handler(InternalDeviceHandler { handler: Box::new(handler), @@ -155,6 +160,20 @@ where fn process_events(&mut self) { self.dev.borrow_mut().process_events() } + + fn resource_info(&self, handle: T::Handle) -> Result { + self.dev + .borrow() + .resource_info(handle) + .chain_err(|| ErrorKind::UnderlyingBackendError) + } + + fn resource_handles(&self) -> Result { + self.dev + .borrow() + .resource_handles() + .chain_err(|| ErrorKind::UnderlyingBackendError) + } } impl::Surface> + 'static, D: Device + NativeDisplay + 'static> diff --git a/src/backend/drm/gbm/mod.rs b/src/backend/drm/gbm/mod.rs index 212d8e1..34d0fe0 100644 --- a/src/backend/drm/gbm/mod.rs +++ b/src/backend/drm/gbm/mod.rs @@ -1,7 +1,8 @@ -use super::{Device, DeviceHandler, RawDevice, Surface}; +use super::{Device, DeviceHandler, RawDevice, ResourceHandles, ResourceInfo, Surface}; use drm::control::{connector, crtc, framebuffer, Device as ControlDevice, Mode}; use gbm::{self, BufferObjectFlags, Format as GbmFormat}; +use nix::libc::dev_t; use std::cell::{Cell, RefCell}; use std::collections::HashMap; @@ -101,6 +102,10 @@ impl DeviceHandler for InternalDeviceHan impl Device for GbmDevice { type Surface = GbmSurface; + fn device_id(&self) -> dev_t { + self.dev.borrow().device_id() + } + fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { self.dev.borrow_mut().set_handler(InternalDeviceHandler { handler: Box::new(handler), @@ -175,6 +180,20 @@ impl Device for GbmDevice { fn process_events(&mut self) { self.dev.borrow_mut().process_events() } + + fn resource_info(&self, handle: T::Handle) -> Result { + self.dev + .borrow() + .resource_info(handle) + .chain_err(|| ErrorKind::UnderlyingBackendError) + } + + fn resource_handles(&self) -> Result { + self.dev + .borrow() + .resource_handles() + .chain_err(|| ErrorKind::UnderlyingBackendError) + } } impl AsRawFd for GbmDevice { diff --git a/src/backend/drm/legacy/mod.rs b/src/backend/drm/legacy/mod.rs index bb2e50a..4459c15 100644 --- a/src/backend/drm/legacy/mod.rs +++ b/src/backend/drm/legacy/mod.rs @@ -1,6 +1,6 @@ use super::{DevPath, Device, DeviceHandler, RawDevice, Surface}; -use drm::control::{connector, crtc, encoder, Device as ControlDevice, Mode, ResourceInfo}; +use drm::control::{connector, crtc, encoder, Device as ControlDevice, Mode, ResourceHandles, ResourceInfo}; use drm::Device as BasicDevice; use nix::libc::dev_t; use nix::sys::stat::fstat; @@ -78,7 +78,7 @@ impl LegacyDrmDevice { drm.priviledged = false; }; - let res_handles = drm.resource_handles().chain_err(|| { + let res_handles = ControlDevice::resource_handles(&drm).chain_err(|| { ErrorKind::DrmDev(format!("Error loading drm resources on {:?}", drm.dev_path())) })?; for &con in res_handles.connectors() { @@ -104,10 +104,6 @@ impl LegacyDrmDevice { Ok(drm) } - - pub fn dev_id(&self) -> dev_t { - self.dev_id - } } impl AsRawFd for LegacyDrmDevice { @@ -122,6 +118,10 @@ impl ControlDevice for LegacyDrmDevice {} impl Device for LegacyDrmDevice { type Surface = LegacyDrmSurface; + fn device_id(&self) -> dev_t { + self.dev_id + } + fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { self.handler = Some(RefCell::new(Box::new(handler))); } @@ -167,7 +167,7 @@ impl Device for LegacyDrmDevice { }).collect::>>()?; // and if any encoder supports the selected crtc - let resource_handles = self.resource_handles().chain_err(|| { + let resource_handles = ControlDevice::resource_handles(self).chain_err(|| { ErrorKind::DrmDev(format!("Error loading drm resources on {:?}", self.dev_path())) })?; if !encoders @@ -229,6 +229,16 @@ impl Device for LegacyDrmDevice { }, } } + + fn resource_info(&self, handle: T::Handle) -> Result { + T::load_from_device(self, handle) + .chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path()))) + } + + fn resource_handles(&self) -> Result { + ControlDevice::resource_handles(self) + .chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path()))) + } } impl RawDevice for LegacyDrmDevice { diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index 0912051..2b60f5d 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -1,11 +1,9 @@ -pub use drm::control::connector; -pub use drm::control::crtc; -pub use drm::control::framebuffer; -use drm::control::Device as ControlDevice; -pub use drm::control::Mode; -use drm::Device as BasicDevice; +pub use drm::{ + control::{connector, crtc, framebuffer, Device as ControlDevice, Mode, ResourceHandles, ResourceInfo}, + Device as BasicDevice, +}; +pub use nix::libc::dev_t; -use std::borrow::Borrow; use std::error::Error; use std::iter::IntoIterator; use std::os::unix::io::AsRawFd; @@ -34,6 +32,7 @@ pub trait DeviceHandler { pub trait Device: AsRawFd + DevPath { type Surface: Surface; + fn device_id(&self) -> dev_t; fn set_handler(&mut self, handler: impl DeviceHandler + 'static); fn clear_handler(&mut self); fn create_surface( @@ -43,6 +42,11 @@ pub trait Device: AsRawFd + DevPath { connectors: impl IntoIterator, ) -> Result::Error>; fn process_events(&mut self); + fn resource_info( + &self, + handle: T::Handle, + ) -> Result::Error>; + fn resource_handles(&self) -> Result::Error>; } pub trait RawDevice: Device::Surface> {