Update to stable drm-rs version

This commit is contained in:
Drakulix 2017-09-27 22:44:08 +02:00 committed by Victor Berger
parent b6a2fe7748
commit 51886fbf00
4 changed files with 62 additions and 72 deletions

View File

@ -14,8 +14,8 @@ slog-stdlog = "2.0.0-0.2"
libloading = "0.4.0" libloading = "0.4.0"
wayland-client = { version = "0.9.9", optional = true } wayland-client = { version = "0.9.9", optional = true }
winit = { version = "0.8.2", optional = true } winit = { version = "0.8.2", optional = true }
drm = { version = "=0.2.1", optional = true } drm = { version = "^0.3.0", optional = true }
gbm = { version = "=0.2.1", optional = true } gbm = { version = "^0.2.2", optional = true }
glium = { version = "0.17.1", optional = true, default-features = false } glium = { version = "0.17.1", optional = true, default-features = false }
input = { version = "0.2.0", optional = true } input = { version = "0.2.0", optional = true }
rental = "0.4.11" rental = "0.4.11"
@ -37,6 +37,3 @@ backend_winit = ["winit", "wayland-server/dlopen", "wayland-client/dlopen"]
backend_drm = ["drm", "gbm"] backend_drm = ["drm", "gbm"]
backend_libinput = ["input"] backend_libinput = ["input"]
renderer_glium = ["glium"] renderer_glium = ["glium"]
[replace]
"drm:0.2.1" = { git = "https://github.com/Drakulix/drm-rs", branch = "future" }

View File

@ -16,6 +16,7 @@ mod helpers;
use drm::control::{Device as ControlDevice, ResourceInfo}; use drm::control::{Device as ControlDevice, ResourceInfo};
use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState};
use drm::control::encoder::Info as EncoderInfo; use drm::control::encoder::Info as EncoderInfo;
use drm::result::Error as DrmError;
use glium::Surface; use glium::Surface;
use helpers::{init_shell, GliumDrawer, MyWindowMap, Roles, SurfaceData}; use helpers::{init_shell, GliumDrawer, MyWindowMap, Roles, SurfaceData};
use slog::{Drain, Logger}; use slog::{Drain, Logger};
@ -27,7 +28,6 @@ use smithay::wayland::shell::ShellState;
use smithay::wayland::shm::init_shm_global; use smithay::wayland::shm::init_shm_global;
use std::cell::RefCell; use std::cell::RefCell;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Error as IoError;
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
use wayland_server::{EventLoopHandle, StateToken}; use wayland_server::{EventLoopHandle, StateToken};
@ -72,9 +72,9 @@ fn main() {
let crtc = encoder_info.current_crtc() let crtc = encoder_info.current_crtc()
// or use the first one that is compatible with the encoder // or use the first one that is compatible with the encoder
.unwrap_or_else(|| .unwrap_or_else(||
*res_handles.crtcs() *res_handles.filter_crtcs(encoder_info.possible_crtcs())
.iter() .iter()
.find(|crtc| encoder_info.supports_crtc(**crtc)) .next()
.unwrap()); .unwrap());
// Assuming we found a good connector and loaded the info into `connector_info` // Assuming we found a good connector and loaded the info into `connector_info`
@ -186,7 +186,7 @@ impl DrmHandler<GliumDrawer<DrmBackend>> for DrmHandlerImpl {
} }
fn error(&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<GliumDrawer<DrmBackend>>, fn error(&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<GliumDrawer<DrmBackend>>,
error: IoError) { error: DrmError) {
panic!("{:?}", error); panic!("{:?}", error);
} }
} }

View File

@ -2,9 +2,8 @@ use super::devices;
use super::error::*; use super::error::*;
use backend::graphics::GraphicsBackend; use backend::graphics::GraphicsBackend;
use backend::graphics::egl::{EGLGraphicsBackend, EGLSurface, PixelFormat, SwapBuffersError}; use backend::graphics::egl::{EGLGraphicsBackend, EGLSurface, PixelFormat, SwapBuffersError};
use drm::buffer::Buffer; use drm::control::{Device, ResourceInfo};
use drm::control::{connector, crtc, encoder, framebuffer, Mode}; use drm::control::{connector, crtc, encoder, framebuffer, Mode};
use drm::control::ResourceInfo;
use gbm::{BufferObject, BufferObjectFlags, Format as GbmFormat, Surface as GbmSurface, SurfaceBufferHandle}; use gbm::{BufferObject, BufferObjectFlags, Format as GbmFormat, Surface as GbmSurface, SurfaceBufferHandle};
use image::{ImageBuffer, Rgba}; use image::{ImageBuffer, Rgba};
use nix::c_void; use nix::c_void;
@ -211,10 +210,22 @@ impl DrmBackend {
.collect::<Result<Vec<encoder::Info>>>()?; .collect::<Result<Vec<encoder::Info>>>()?;
// and if any encoder supports the selected crtc // and if any encoder supports the selected crtc
let resource_handles = self.graphics
.head()
.head()
.head()
.resource_handles()
.chain_err(|| {
ErrorKind::DrmDev(format!("{:?}", self.graphics.head().head().head()))
})?;
if !encoders if !encoders
.iter() .iter()
.any(|encoder| encoder.supports_crtc(self.crtc)) .map(|encoder| encoder.possible_crtcs())
{ .all(|crtc_list| {
resource_handles
.filter_crtcs(crtc_list)
.contains(&self.crtc)
}) {
bail!(ErrorKind::NoSuitableEncoder(info, self.crtc)); bail!(ErrorKind::NoSuitableEncoder(info, self.crtc));
} }
@ -440,17 +451,11 @@ impl GraphicsBackend for DrmBackend {
if crtc::set_cursor2( if crtc::set_cursor2(
self.graphics.head().head().head(), self.graphics.head().head().head(),
self.crtc, self.crtc,
Buffer::handle(&cursor), &cursor,
(w, h),
(hotspot.0 as i32, hotspot.1 as i32), (hotspot.0 as i32, hotspot.1 as i32),
).is_err() ).is_err()
{ {
crtc::set_cursor( crtc::set_cursor(self.graphics.head().head().head(), self.crtc, &cursor).chain_err(|| {
self.graphics.head().head().head(),
self.crtc,
Buffer::handle(&cursor),
(w, h),
).chain_err(|| {
ErrorKind::DrmDev(format!("{:?}", self.graphics.head().head().head())) ErrorKind::DrmDev(format!("{:?}", self.graphics.head().head().head()))
})?; })?;
} }
@ -502,7 +507,7 @@ impl EGLGraphicsBackend for DrmBackend {
trace!(self.logger, "Queueing Page flip"); trace!(self.logger, "Queueing Page flip");
// and flip // and flip
crtc::page_flip(graphics.context.devices.drm, self.crtc, fb.handle(), &[crtc::PageFlipFlags::PageFlipEvent], self.crtc).map_err(|_| SwapBuffersError::ContextLost) crtc::page_flip(graphics.context.devices.drm, self.crtc, fb.handle(), &[crtc::PageFlipFlags::PageFlipEvent]).map_err(|_| SwapBuffersError::ContextLost)
}) })
}) })
} }

View File

@ -80,10 +80,10 @@
//! let crtc = encoder_info.current_crtc() //! let crtc = encoder_info.current_crtc()
//! // or use the first one that is compatible with the encoder //! // or use the first one that is compatible with the encoder
//! .unwrap_or_else(|| //! .unwrap_or_else(||
//! *res_handles.crtcs() //! *res_handles.filter_crtcs(encoder_info.possible_crtcs())
//! .iter() //! .iter()
//! .find(|crtc| encoder_info.supports_crtc(**crtc)) //! .next()
//! .unwrap()); //! .unwrap());
//! //!
//! // Use first mode (usually the highest resolution) //! // Use first mode (usually the highest resolution)
//! let mode = connector_info.modes()[0]; //! let mode = connector_info.modes()[0];
@ -118,7 +118,7 @@
//! # //! #
//! # use drm::control::{Device as ControlDevice, ResourceInfo}; //! # use drm::control::{Device as ControlDevice, ResourceInfo};
//! # use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; //! # use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState};
//! use std::io::Error as IoError; //! use drm::result::Error as DrmError;
//! # use std::fs::OpenOptions; //! # use std::fs::OpenOptions;
//! # use std::time::Duration; //! # use std::time::Duration;
//! use smithay::backend::drm::{DrmDevice, DrmBackend, DrmHandler, drm_device_bind}; //! use smithay::backend::drm::{DrmDevice, DrmBackend, DrmHandler, drm_device_bind};
@ -167,7 +167,7 @@
//! fn error(&mut self, //! fn error(&mut self,
//! _: &mut EventLoopHandle, //! _: &mut EventLoopHandle,
//! device: &mut DrmDevice<DrmBackend>, //! device: &mut DrmDevice<DrmBackend>,
//! error: IoError) //! error: DrmError)
//! { //! {
//! panic!("DrmDevice errored: {}", error); //! panic!("DrmDevice errored: {}", error);
//! } //! }
@ -186,13 +186,13 @@ use backend::graphics::egl::{EGLContext, GlAttributes, PixelFormatRequirements};
use drm::Device as BasicDevice; use drm::Device as BasicDevice;
use drm::control::{connector, crtc, encoder, Mode, ResourceInfo}; use drm::control::{connector, crtc, encoder, Mode, ResourceInfo};
use drm::control::Device as ControlDevice; use drm::control::Device as ControlDevice;
use drm::result::Error as DrmError;
use gbm::Device as GbmDevice; use gbm::Device as GbmDevice;
use nix; use nix;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io::{Error as IoError, Result as IoResult}; use std::io::Result as IoResult;
use std::marker::PhantomData;
use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::io::{AsRawFd, RawFd};
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
@ -356,7 +356,7 @@ impl<B: From<DrmBackend> + Borrow<DrmBackend> + 'static> DrmDevice<B> {
context: Rc::new(Context::try_new( context: Rc::new(Context::try_new(
Box::new(Devices::try_new(Box::new(drm), |drm| { Box::new(Devices::try_new(Box::new(drm), |drm| {
debug!(log, "Creating gbm device"); debug!(log, "Creating gbm device");
GbmDevice::new_from_drm::<DrmDevice<B>>(drm).chain_err(|| ErrorKind::GbmInitFailed) GbmDevice::new_from_drm(drm).chain_err(|| ErrorKind::GbmInitFailed)
})?), })?),
|devices| { |devices| {
debug!(log, "Creating egl context from gbm device"); debug!(log, "Creating egl context from gbm device");
@ -420,7 +420,15 @@ impl<B: From<DrmBackend> + Borrow<DrmBackend> + 'static> DrmDevice<B> {
.collect::<Result<Vec<encoder::Info>>>()?; .collect::<Result<Vec<encoder::Info>>>()?;
// and if any encoder supports the selected crtc // and if any encoder supports the selected crtc
if !encoders.iter().any(|encoder| encoder.supports_crtc(crtc)) { let resource_handles = self.resource_handles().chain_err(|| {
ErrorKind::DrmDev(format!("{:?}", self.context.head().head()))
})?;
if !encoders
.iter()
.map(|encoder| encoder.possible_crtcs())
.all(|crtc_list| {
resource_handles.filter_crtcs(crtc_list).contains(&crtc)
}) {
bail!(ErrorKind::NoSuitableEncoder(con_info, crtc)) bail!(ErrorKind::NoSuitableEncoder(con_info, crtc))
} }
} }
@ -460,7 +468,7 @@ pub trait DrmHandler<B: Borrow<DrmBackend> + 'static> {
/// ///
/// The related backends are most likely *not* usable anymore and /// The related backends are most likely *not* usable anymore and
/// the whole stack has to be recreated. /// the whole stack has to be recreated.
fn error(&mut self, evlh: &mut EventLoopHandle, device: &mut DrmDevice<B>, error: IoError); fn error(&mut self, evlh: &mut EventLoopHandle, device: &mut DrmDevice<B>, error: DrmError);
} }
/// Bind a `DrmDevice` to an EventLoop, /// Bind a `DrmDevice` to an EventLoop,
@ -487,51 +495,31 @@ where
{ {
FdEventSourceImpl { FdEventSourceImpl {
ready: |evlh, id, _, _| { ready: |evlh, id, _, _| {
use std::any::Any;
let &mut (ref mut dev, ref mut handler) = id; let &mut (ref mut dev, ref mut handler) = id;
struct PageFlipHandler<'a, 'b, B: Borrow<DrmBackend> + 'static, H: DrmHandler<B> + 'static> { let events = crtc::receive_events(dev);
handler: &'a mut H, match events {
evlh: &'b mut EventLoopHandle, Ok(events) => for event in events {
_marker: PhantomData<B>, match event {
}; crtc::Event::PageFlip(event) => {
let token = dev.backends.get(&event.crtc).cloned();
impl<'a, 'b, B, H> crtc::PageFlipHandler<DrmDevice<B>> for PageFlipHandler<'a, 'b, B, H> if let Some(token) = token {
where // we can now unlock the buffer
B: Borrow<DrmBackend> + 'static, evlh.state().get(&token).borrow().unlock_buffer();
H: DrmHandler<B> + 'static, trace!(dev.logger, "Handling event for backend {:?}", event.crtc);
{ // and then call the user to render the next frame
fn handle_event(&mut self, device: &mut DrmDevice<B>, frame: u32, duration: Duration, handler.ready(evlh, dev, &token, event.frame, event.duration);
userdata: Box<Any>) { }
let crtc_id: crtc::Handle = *userdata.downcast().unwrap(); }
let token = device.backends.get(&crtc_id).cloned(); _ => {}
if let Some(token) = token {
// we can now unlock the buffer
self.evlh.state().get(&token).borrow().unlock_buffer();
trace!(device.logger, "Handling event for backend {:?}", crtc_id);
// and then call the user to render the next frame
self.handler
.ready(self.evlh, device, &token, frame, duration);
} }
} },
} Err(err) => return handler.error(evlh, dev, err),
};
crtc::handle_event(
dev,
2,
None::<&mut ()>,
Some(&mut PageFlipHandler {
handler,
evlh,
_marker: PhantomData,
}),
None::<&mut ()>,
).unwrap();
}, },
error: |evlh, id, _, error| { error: |evlh, id, _, error| {
warn!(id.0.logger, "DrmDevice errored: {}", error); warn!(id.0.logger, "DrmDevice errored: {}", error);
id.1.error(evlh, &mut id.0, error); id.1.error(evlh, &mut id.0, error.into());
}, },
} }
} }