Merge pull request #38 from Smithay/feature/drm
Fix drm doc test and Deref impl
This commit is contained in:
commit
62be110265
|
@ -25,6 +25,7 @@ use smithay::compositor::{compositor_init, CompositorToken, SubsurfaceRole, Trav
|
||||||
use smithay::compositor::roles::Role;
|
use smithay::compositor::roles::Role;
|
||||||
use smithay::shell::{shell_init, ShellState};
|
use smithay::shell::{shell_init, ShellState};
|
||||||
use smithay::shm::init_shm_global;
|
use smithay::shm::init_shm_global;
|
||||||
|
use std::borrow::Borrow;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -147,7 +148,7 @@ impl DrmHandler<GliumDrawer<DrmBackend>> for DrmHandlerImpl {
|
||||||
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
||||||
// redraw the frame, in a simple but inneficient way
|
// redraw the frame, in a simple but inneficient way
|
||||||
{
|
{
|
||||||
let screen_dimensions = drawer.get_framebuffer_dimensions();
|
let screen_dimensions = (drawer.borrow() as &DrmBackend).get_framebuffer_dimensions();
|
||||||
for toplevel_surface in state.get(&self.shell_state_token).toplevel_surfaces() {
|
for toplevel_surface in state.get(&self.shell_state_token).toplevel_surfaces() {
|
||||||
if let Some(wl_surface) = toplevel_surface.get_surface() {
|
if let Some(wl_surface) = toplevel_surface.get_surface() {
|
||||||
// this surface is a root of a subsurface tree that needs to be drawn
|
// this surface is a root of a subsurface tree that needs to be drawn
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use glium;
|
use glium;
|
||||||
use glium::{Frame, Surface};
|
use glium::Surface;
|
||||||
use glium::index::PrimitiveType;
|
use glium::index::PrimitiveType;
|
||||||
use smithay::backend::graphics::egl::EGLGraphicsBackend;
|
use smithay::backend::graphics::egl::EGLGraphicsBackend;
|
||||||
use smithay::backend::graphics::glium::GliumGraphicsBackend;
|
use smithay::backend::graphics::glium::GliumGraphicsBackend;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
|
@ -21,10 +22,16 @@ pub struct GliumDrawer<F: EGLGraphicsBackend + 'static> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: EGLGraphicsBackend + 'static> Deref for GliumDrawer<F> {
|
impl<F: EGLGraphicsBackend + 'static> Deref for GliumDrawer<F> {
|
||||||
type Target = F;
|
type Target = GliumGraphicsBackend<F>;
|
||||||
|
|
||||||
fn deref(&self) -> &F {
|
fn deref(&self) -> &GliumGraphicsBackend<F> {
|
||||||
&*self.display
|
&self.display
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F: EGLGraphicsBackend + 'static> Borrow<F> for GliumDrawer<F> {
|
||||||
|
fn borrow(&self) -> &F {
|
||||||
|
self.display.borrow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,9 +142,4 @@ impl<F: EGLGraphicsBackend + 'static> GliumDrawer<F> {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn draw(&self) -> Frame {
|
|
||||||
self.display.draw()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,19 +42,19 @@
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
//! extern crate drm;
|
//! extern crate drm;
|
||||||
//! extern crate smithay;
|
//! extern crate smithay;
|
||||||
//! # extern crate wayland_server;
|
//! extern crate wayland_server;
|
||||||
//!
|
//!
|
||||||
//! 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 std::io::Error as IoError;
|
|
||||||
//! use std::fs::OpenOptions;
|
//! use std::fs::OpenOptions;
|
||||||
//! # use std::time::Duration;
|
//! use smithay::backend::drm::{DrmDevice, DrmBackend};
|
||||||
//! use smithay::backend::drm::DrmDevice;
|
//! use wayland_server::StateToken;
|
||||||
//! # use smithay::backend::drm::{DrmHandler, Id};
|
|
||||||
//! # use wayland_server::EventLoopHandle;
|
|
||||||
//!
|
//!
|
||||||
//! # fn main() {
|
//! # fn main() {
|
||||||
|
//!
|
||||||
|
//! let (_display, mut event_loop) = wayland_server::create_display();
|
||||||
|
//!
|
||||||
//! // Open the drm device
|
//! // Open the drm device
|
||||||
//! let mut options = OpenOptions::new();
|
//! let mut options = OpenOptions::new();
|
||||||
//! options.read(true);
|
//! options.read(true);
|
||||||
|
@ -89,19 +89,12 @@
|
||||||
//! let mode = connector_info.modes()[0];
|
//! let mode = connector_info.modes()[0];
|
||||||
//!
|
//!
|
||||||
//! // Create the backend
|
//! // Create the backend
|
||||||
//! let backend = device.create_backend(
|
//! let backend: StateToken<DrmBackend> = device.create_backend(
|
||||||
|
//! &mut event_loop,
|
||||||
//! crtc,
|
//! crtc,
|
||||||
//! mode,
|
//! mode,
|
||||||
//! vec![connector_info.handle()]
|
//! vec![connector_info.handle()]
|
||||||
//! ).unwrap();
|
//! ).unwrap();
|
||||||
//! # struct MyDrmHandler;
|
|
||||||
//! #
|
|
||||||
//! # impl DrmHandler for MyDrmHandler {
|
|
||||||
//! # fn ready(&mut self, _: &mut EventLoopHandle, id: Id, _frame: u32, _duration: Duration) {}
|
|
||||||
//! # fn error(&mut self, _: &mut EventLoopHandle, error: IoError) {}
|
|
||||||
//! # }
|
|
||||||
//! #
|
|
||||||
//! # device.set_handler(MyDrmHandler);
|
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -126,13 +119,11 @@
|
||||||
//! # 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 std::io::Error as IoError;
|
||||||
//! use std::os::unix::io::AsRawFd;
|
|
||||||
//! # use std::fs::OpenOptions;
|
//! # use std::fs::OpenOptions;
|
||||||
//! # use std::time::Duration;
|
//! # use std::time::Duration;
|
||||||
//! use smithay::backend::drm::{DrmDevice, DrmBackend, DrmHandler, Id};
|
//! use smithay::backend::drm::{DrmDevice, DrmBackend, DrmHandler, drm_device_bind};
|
||||||
//! use smithay::backend::graphics::egl::EGLGraphicsBackend;
|
//! use smithay::backend::graphics::egl::EGLGraphicsBackend;
|
||||||
//! use wayland_server::sources::READ;
|
//! use wayland_server::{EventLoopHandle, StateToken};
|
||||||
//! # use wayland_server::EventLoopHandle;
|
|
||||||
//! #
|
//! #
|
||||||
//! # fn main() {
|
//! # fn main() {
|
||||||
//! #
|
//! #
|
||||||
|
@ -153,33 +144,39 @@
|
||||||
//! # .unwrap();
|
//! # .unwrap();
|
||||||
//! # let crtc = res_handles.crtcs()[0];
|
//! # let crtc = res_handles.crtcs()[0];
|
||||||
//! # let mode = connector_info.modes()[0];
|
//! # let mode = connector_info.modes()[0];
|
||||||
//! # let backend = device.create_backend(
|
//! # let backend: StateToken<DrmBackend> = device.create_backend(
|
||||||
|
//! # &mut event_loop,
|
||||||
//! # crtc,
|
//! # crtc,
|
||||||
//! # mode,
|
//! # mode,
|
||||||
//! # vec![connector_info.handle()]
|
//! # vec![connector_info.handle()]
|
||||||
//! # ).unwrap();
|
//! # ).unwrap();
|
||||||
//!
|
//!
|
||||||
//! struct MyDrmHandler(DrmBackend);
|
//! struct MyDrmHandler;
|
||||||
//!
|
//!
|
||||||
//! impl DrmHandler for MyDrmHandler {
|
//! impl DrmHandler<DrmBackend> for MyDrmHandler {
|
||||||
//! fn ready(&mut self, _: &mut EventLoopHandle, id: Id, _frame: u32, _duration: Duration) {
|
//! fn ready(&mut self,
|
||||||
//! if self.0.is(id) { // check id in case you got multiple backends
|
//! evlh: &mut EventLoopHandle,
|
||||||
//! // ... render surfaces ...
|
//! _device: &mut DrmDevice<DrmBackend>,
|
||||||
//! self.0.swap_buffers().unwrap(); // trigger the swap
|
//! backend: &StateToken<DrmBackend>,
|
||||||
|
//! _frame: u32,
|
||||||
|
//! _duration: Duration)
|
||||||
|
//! {
|
||||||
|
//! // render surfaces and swap again
|
||||||
|
//! evlh.state().get(backend).swap_buffers().unwrap();
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! fn error(&mut self,
|
||||||
//! fn error(&mut self, _: &mut EventLoopHandle, error: IoError) {
|
//! _: &mut EventLoopHandle,
|
||||||
|
//! device: &mut DrmDevice<DrmBackend>,
|
||||||
|
//! error: IoError)
|
||||||
|
//! {
|
||||||
//! panic!("DrmDevice errored: {}", error);
|
//! panic!("DrmDevice errored: {}", error);
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! // render something (like clear_color)
|
//! // render something (like clear_color)
|
||||||
//! backend.swap_buffers().unwrap();
|
//! event_loop.state().get(&backend).swap_buffers().unwrap();
|
||||||
//!
|
//!
|
||||||
//! device.set_handler(MyDrmHandler(backend));
|
//! let _source = drm_device_bind(&mut event_loop, device, MyDrmHandler).unwrap();
|
||||||
//! let fd = device.as_raw_fd();
|
|
||||||
//! let drm_device_id = event_loop.add_handler(device);
|
|
||||||
//! let _drm_event_source = event_loop.add_fd_event_source::<DrmDevice<MyDrmHandler>>(fd, drm_device_id, READ);
|
|
||||||
//!
|
//!
|
||||||
//! event_loop.run().unwrap();
|
//! event_loop.run().unwrap();
|
||||||
//! # }
|
//! # }
|
||||||
|
@ -191,11 +188,11 @@ use drm::control::{connector, crtc, encoder, Mode, ResourceInfo};
|
||||||
use drm::control::Device as ControlDevice;
|
use drm::control::Device as ControlDevice;
|
||||||
use gbm::Device as GbmDevice;
|
use gbm::Device as GbmDevice;
|
||||||
use nix;
|
use nix;
|
||||||
|
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::{Error as IoError, Result as IoResult};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
|
||||||
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;
|
||||||
|
@ -256,13 +253,13 @@ rental! {
|
||||||
use self::devices::{Context, Devices};
|
use self::devices::{Context, Devices};
|
||||||
|
|
||||||
/// Representation of an open drm device node to create rendering backends
|
/// Representation of an open drm device node to create rendering backends
|
||||||
pub struct DrmDevice<B: Deref<Target = DrmBackend> + 'static> {
|
pub struct DrmDevice<B: Borrow<DrmBackend> + 'static> {
|
||||||
context: Rc<Context>,
|
context: Rc<Context>,
|
||||||
backends: HashMap<crtc::Handle, StateToken<B>>,
|
backends: HashMap<crtc::Handle, StateToken<B>>,
|
||||||
logger: ::slog::Logger,
|
logger: ::slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: From<DrmBackend> + Deref<Target = DrmBackend> + 'static> DrmDevice<B> {
|
impl<B: From<DrmBackend> + Borrow<DrmBackend> + 'static> DrmDevice<B> {
|
||||||
/// Create a new `DrmDevice` from a raw file descriptor
|
/// Create a new `DrmDevice` from a raw file descriptor
|
||||||
///
|
///
|
||||||
/// Returns an error of opening the device failed or context creation was not
|
/// Returns an error of opening the device failed or context creation was not
|
||||||
|
@ -440,18 +437,18 @@ impl<B: From<DrmBackend> + Deref<Target = DrmBackend> + 'static> DrmDevice<B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for users convinience and FdEventSource registering
|
// for users convinience and FdEventSource registering
|
||||||
impl<B: Deref<Target = DrmBackend> + 'static> AsRawFd for DrmDevice<B> {
|
impl<B: Borrow<DrmBackend> + 'static> AsRawFd for DrmDevice<B> {
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
fn as_raw_fd(&self) -> RawFd {
|
||||||
self.context.head().head().as_raw_fd()
|
self.context.head().head().as_raw_fd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<B: Deref<Target = DrmBackend> + 'static> BasicDevice for DrmDevice<B> {}
|
impl<B: Borrow<DrmBackend> + 'static> BasicDevice for DrmDevice<B> {}
|
||||||
impl<B: Deref<Target = DrmBackend> + 'static> ControlDevice for DrmDevice<B> {}
|
impl<B: Borrow<DrmBackend> + 'static> ControlDevice for DrmDevice<B> {}
|
||||||
|
|
||||||
/// Handler for drm node events
|
/// Handler for drm node events
|
||||||
///
|
///
|
||||||
/// See module-level documentation for its use
|
/// See module-level documentation for its use
|
||||||
pub trait DrmHandler<B: Deref<Target = DrmBackend> + 'static> {
|
pub trait DrmHandler<B: Borrow<DrmBackend> + 'static> {
|
||||||
/// A `DrmBackend` has finished swapping buffers and new frame can now
|
/// A `DrmBackend` has finished swapping buffers and new frame can now
|
||||||
/// (and should be immediately) be rendered.
|
/// (and should be immediately) be rendered.
|
||||||
///
|
///
|
||||||
|
@ -472,7 +469,7 @@ pub trait DrmHandler<B: Deref<Target = DrmBackend> + 'static> {
|
||||||
pub fn drm_device_bind<B, H>(evlh: &mut EventLoopHandle, device: DrmDevice<B>, handler: H)
|
pub fn drm_device_bind<B, H>(evlh: &mut EventLoopHandle, device: DrmDevice<B>, handler: H)
|
||||||
-> IoResult<FdEventSource<(DrmDevice<B>, H)>>
|
-> IoResult<FdEventSource<(DrmDevice<B>, H)>>
|
||||||
where
|
where
|
||||||
B: Deref<Target = DrmBackend> + 'static,
|
B: Borrow<DrmBackend> + 'static,
|
||||||
H: DrmHandler<B> + 'static,
|
H: DrmHandler<B> + 'static,
|
||||||
{
|
{
|
||||||
evlh.add_fd_event_source(
|
evlh.add_fd_event_source(
|
||||||
|
@ -485,7 +482,7 @@ where
|
||||||
|
|
||||||
fn fd_event_source_implementation<B, H>() -> FdEventSourceImpl<(DrmDevice<B>, H)>
|
fn fd_event_source_implementation<B, H>() -> FdEventSourceImpl<(DrmDevice<B>, H)>
|
||||||
where
|
where
|
||||||
B: Deref<Target = DrmBackend> + 'static,
|
B: Borrow<DrmBackend> + 'static,
|
||||||
H: DrmHandler<B> + 'static,
|
H: DrmHandler<B> + 'static,
|
||||||
{
|
{
|
||||||
FdEventSourceImpl {
|
FdEventSourceImpl {
|
||||||
|
@ -497,7 +494,7 @@ where
|
||||||
struct PageFlipHandler<
|
struct PageFlipHandler<
|
||||||
'a,
|
'a,
|
||||||
'b,
|
'b,
|
||||||
B: Deref<Target = DrmBackend> + 'static,
|
B: Borrow<DrmBackend> + 'static,
|
||||||
H: DrmHandler<B> + 'static,
|
H: DrmHandler<B> + 'static,
|
||||||
> {
|
> {
|
||||||
handler: &'a mut H,
|
handler: &'a mut H,
|
||||||
|
@ -507,7 +504,7 @@ where
|
||||||
|
|
||||||
impl<'a, 'b, B, H> crtc::PageFlipHandler<DrmDevice<B>> for PageFlipHandler<'a, 'b, B, H>
|
impl<'a, 'b, B, H> crtc::PageFlipHandler<DrmDevice<B>> for PageFlipHandler<'a, 'b, B, H>
|
||||||
where
|
where
|
||||||
B: Deref<Target = DrmBackend> + 'static,
|
B: Borrow<DrmBackend> + 'static,
|
||||||
H: DrmHandler<B> + 'static,
|
H: DrmHandler<B> + 'static,
|
||||||
{
|
{
|
||||||
fn handle_event(&mut self, device: &mut DrmDevice<B>, frame: u32, duration: Duration,
|
fn handle_event(&mut self, device: &mut DrmDevice<B>, frame: u32, duration: Duration,
|
||||||
|
@ -516,7 +513,7 @@ where
|
||||||
let token = device.backends.get(&crtc_id).cloned();
|
let token = device.backends.get(&crtc_id).cloned();
|
||||||
if let Some(token) = token {
|
if let Some(token) = token {
|
||||||
// we can now unlock the buffer
|
// we can now unlock the buffer
|
||||||
(**self.evlh.state().get(&token)).unlock_buffer();
|
self.evlh.state().get(&token).borrow().unlock_buffer();
|
||||||
trace!(device.logger, "Handling event for backend {:?}", crtc_id);
|
trace!(device.logger, "Handling event for backend {:?}", crtc_id);
|
||||||
// and then call the user to render the next frame
|
// and then call the user to render the next frame
|
||||||
self.handler
|
self.handler
|
||||||
|
|
|
@ -5,7 +5,7 @@ use glium::Frame;
|
||||||
use glium::SwapBuffersError as GliumSwapBuffersError;
|
use glium::SwapBuffersError as GliumSwapBuffersError;
|
||||||
use glium::backend::{Backend, Context, Facade};
|
use glium::backend::{Backend, Context, Facade};
|
||||||
use glium::debug::DebugCallbackBehavior;
|
use glium::debug::DebugCallbackBehavior;
|
||||||
use std::ops::Deref;
|
use std::borrow::Borrow;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -54,10 +54,8 @@ impl<T: EGLGraphicsBackend + 'static> GliumGraphicsBackend<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: EGLGraphicsBackend> Deref for GliumGraphicsBackend<T> {
|
impl<T: EGLGraphicsBackend> Borrow<T> for GliumGraphicsBackend<T> {
|
||||||
type Target = T;
|
fn borrow(&self) -> &T {
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
|
||||||
&self.backend.0
|
&self.backend.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue