drm: Add functions to query device state
This commit is contained in:
parent
2675cf94dc
commit
de526f4b23
|
@ -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<B, D>;
|
||||
|
||||
fn device_id(&self) -> dev_t {
|
||||
self.dev.borrow().device_id()
|
||||
}
|
||||
|
||||
fn set_handler(&mut self, handler: impl DeviceHandler<Device = Self> + '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<T: ResourceInfo>(&self, handle: T::Handle) -> Result<T> {
|
||||
self.dev
|
||||
.borrow()
|
||||
.resource_info(handle)
|
||||
.chain_err(|| ErrorKind::UnderlyingBackendError)
|
||||
}
|
||||
|
||||
fn resource_handles(&self) -> Result<ResourceHandles> {
|
||||
self.dev
|
||||
.borrow()
|
||||
.resource_handles()
|
||||
.chain_err(|| ErrorKind::UnderlyingBackendError)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend<Surface = <D as Device>::Surface> + 'static, D: Device + NativeDisplay<B> + 'static>
|
||||
|
|
|
@ -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<D: RawDevice + ControlDevice + 'static> DeviceHandler for InternalDeviceHan
|
|||
impl<D: RawDevice + ControlDevice + 'static> Device for GbmDevice<D> {
|
||||
type Surface = GbmSurface<D>;
|
||||
|
||||
fn device_id(&self) -> dev_t {
|
||||
self.dev.borrow().device_id()
|
||||
}
|
||||
|
||||
fn set_handler(&mut self, handler: impl DeviceHandler<Device = Self> + 'static) {
|
||||
self.dev.borrow_mut().set_handler(InternalDeviceHandler {
|
||||
handler: Box::new(handler),
|
||||
|
@ -175,6 +180,20 @@ impl<D: RawDevice + ControlDevice + 'static> Device for GbmDevice<D> {
|
|||
fn process_events(&mut self) {
|
||||
self.dev.borrow_mut().process_events()
|
||||
}
|
||||
|
||||
fn resource_info<T: ResourceInfo>(&self, handle: T::Handle) -> Result<T> {
|
||||
self.dev
|
||||
.borrow()
|
||||
.resource_info(handle)
|
||||
.chain_err(|| ErrorKind::UnderlyingBackendError)
|
||||
}
|
||||
|
||||
fn resource_handles(&self) -> Result<ResourceHandles> {
|
||||
self.dev
|
||||
.borrow()
|
||||
.resource_handles()
|
||||
.chain_err(|| ErrorKind::UnderlyingBackendError)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: RawDevice + ControlDevice + 'static> AsRawFd for GbmDevice<D> {
|
||||
|
|
|
@ -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<A: AsRawFd + 'static> LegacyDrmDevice<A> {
|
|||
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<A: AsRawFd + 'static> LegacyDrmDevice<A> {
|
|||
|
||||
Ok(drm)
|
||||
}
|
||||
|
||||
pub fn dev_id(&self) -> dev_t {
|
||||
self.dev_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> AsRawFd for LegacyDrmDevice<A> {
|
||||
|
@ -122,6 +118,10 @@ impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmDevice<A> {}
|
|||
impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
|
||||
type Surface = LegacyDrmSurface<A>;
|
||||
|
||||
fn device_id(&self) -> dev_t {
|
||||
self.dev_id
|
||||
}
|
||||
|
||||
fn set_handler(&mut self, handler: impl DeviceHandler<Device = Self> + 'static) {
|
||||
self.handler = Some(RefCell::new(Box::new(handler)));
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
|
|||
}).collect::<Result<Vec<encoder::Info>>>()?;
|
||||
|
||||
// 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<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn resource_info<T: ResourceInfo>(&self, handle: T::Handle) -> Result<T> {
|
||||
T::load_from_device(self, handle)
|
||||
.chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path())))
|
||||
}
|
||||
|
||||
fn resource_handles(&self) -> Result<ResourceHandles> {
|
||||
ControlDevice::resource_handles(self)
|
||||
.chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path())))
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> RawDevice for LegacyDrmDevice<A> {
|
||||
|
|
|
@ -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<Device = Self> + 'static);
|
||||
fn clear_handler(&mut self);
|
||||
fn create_surface(
|
||||
|
@ -43,6 +42,11 @@ pub trait Device: AsRawFd + DevPath {
|
|||
connectors: impl IntoIterator<Item = connector::Handle>,
|
||||
) -> Result<Self::Surface, <Self::Surface as Surface>::Error>;
|
||||
fn process_events(&mut self);
|
||||
fn resource_info<T: ResourceInfo>(
|
||||
&self,
|
||||
handle: T::Handle,
|
||||
) -> Result<T, <Self::Surface as Surface>::Error>;
|
||||
fn resource_handles(&self) -> Result<ResourceHandles, <Self::Surface as Surface>::Error>;
|
||||
}
|
||||
|
||||
pub trait RawDevice: Device<Surface = <Self as RawDevice>::Surface> {
|
||||
|
|
Loading…
Reference in New Issue