Fix drm example and tests

This commit is contained in:
Drakulix 2017-12-03 22:33:21 +01:00
parent 35b20450c5
commit ae5df5039d
2 changed files with 30 additions and 26 deletions

View File

@ -31,7 +31,7 @@ use std::cell::RefCell;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
use wayland_server::{EventLoopHandle, StateToken}; use wayland_server::{StateToken, StateProxy};
fn main() { fn main() {
// A logger facility, here we use the terminal for this example // A logger facility, here we use the terminal for this example
@ -84,13 +84,13 @@ fn main() {
{ {
// Initialize the hardware backend // Initialize the hardware backend
let renderer = device let renderer = device
.create_backend(crtc, mode, vec![connector_info.handle()]) .create_backend(event_loop.state(), crtc, mode, vec![connector_info.handle()])
.unwrap(); .unwrap();
/* /*
* Initialize glium * Initialize glium
*/ */
let mut frame = renderer.draw(); let mut frame = event_loop.state().get(renderer).draw();
frame.clear_color(0.8, 0.8, 0.9, 1.0); frame.clear_color(0.8, 0.8, 0.9, 1.0);
frame.finish().unwrap(); frame.finish().unwrap();
} }
@ -140,11 +140,10 @@ pub struct DrmHandlerImpl {
} }
impl DrmHandler<GliumDrawer<DrmBackend>> for DrmHandlerImpl { impl DrmHandler<GliumDrawer<DrmBackend>> for DrmHandlerImpl {
fn ready(&mut self, evlh: &mut EventLoopHandle, device: &StateToken<DrmDevice<GliumDrawer<DrmBackend>>>, fn ready<'a, S: Into<StateProxy<'a>>>(&mut self, state: S, _device: &mut DrmDevice<GliumDrawer<DrmBackend>>,
crtc: &crtc::Handle, _frame: u32, _duration: Duration) { backend: &StateToken<GliumDrawer<DrmBackend>>, _crtc: crtc::Handle, _frame: u32, _duration: Duration) {
let state = evlh.state(); let state = state.into();
let dev = state.get(device); let drawer = state.get(backend);
let drawer = dev.backend_for_crtc(crtc).unwrap();
let mut frame = drawer.draw(); let mut frame = drawer.draw();
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
@ -187,7 +186,7 @@ impl DrmHandler<GliumDrawer<DrmBackend>> for DrmHandlerImpl {
frame.finish().unwrap(); frame.finish().unwrap();
} }
fn error(&mut self, _evlh: &mut EventLoopHandle, _device: &StateToken<DrmDevice<GliumDrawer<DrmBackend>>>, fn error<'a, S: Into<StateProxy<'a>>>(&mut self, _state: S, _device: &mut DrmDevice<GliumDrawer<DrmBackend>>,
error: DrmError) { error: DrmError) {
panic!("{:?}", error); panic!("{:?}", error);
} }

View File

@ -90,11 +90,11 @@
//! //!
//! // Create the backend //! // Create the backend
//! let backend: StateToken<DrmBackend> = device.create_backend( //! let backend: StateToken<DrmBackend> = device.create_backend(
//! &mut event_loop, //! event_loop.state(),
//! crtc, //! crtc,
//! mode, //! mode,
//! vec![connector_info.handle()] //! vec![connector_info.handle()]
//! ).unwrap(); //! ).unwrap().clone();
//! # } //! # }
//! ``` //! ```
//! //!
@ -118,12 +118,13 @@
//! # //! #
//! # 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::crtc::{Handle as CrtcHandle};
//! use drm::result::Error as DrmError; //! 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};
//! use smithay::backend::graphics::egl::EGLGraphicsBackend; //! use smithay::backend::graphics::egl::EGLGraphicsBackend;
//! use wayland_server::{EventLoopHandle, StateToken}; //! use wayland_server::{StateToken, StateProxy};
//! # //! #
//! # fn main() { //! # fn main() {
//! # //! #
@ -145,27 +146,30 @@
//! # 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: StateToken<DrmBackend> = device.create_backend( //! # let backend: StateToken<DrmBackend> = device.create_backend(
//! # &mut event_loop, //! # event_loop.state(),
//! # crtc, //! # crtc,
//! # mode, //! # mode,
//! # vec![connector_info.handle()] //! # vec![connector_info.handle()]
//! # ).unwrap(); //! # ).unwrap().clone();
//! //!
//! struct MyDrmHandler; //! struct MyDrmHandler;
//! //!
//! impl DrmHandler<DrmBackend> for MyDrmHandler { //! impl DrmHandler<DrmBackend> for MyDrmHandler {
//! fn ready(&mut self, //! fn ready<'a, S: Into<StateProxy<'a>>>(
//! evlh: &mut EventLoopHandle, //! &mut self,
//! state: S,
//! _device: &mut DrmDevice<DrmBackend>, //! _device: &mut DrmDevice<DrmBackend>,
//! backend: &StateToken<DrmBackend>, //! backend: &StateToken<DrmBackend>,
//! _crtc: CrtcHandle,
//! _frame: u32, //! _frame: u32,
//! _duration: Duration) //! _duration: Duration)
//! { //! {
//! // render surfaces and swap again //! // render surfaces and swap again
//! evlh.state().get(backend).swap_buffers().unwrap(); //! state.into().get(backend).swap_buffers().unwrap();
//! } //! }
//! fn error(&mut self, //! fn error<'a, S: Into<StateProxy<'a>>>(
//! _: &mut EventLoopHandle, //! &mut self,
//! _state: S,
//! device: &mut DrmDevice<DrmBackend>, //! device: &mut DrmDevice<DrmBackend>,
//! error: DrmError) //! error: DrmError)
//! { //! {
@ -176,7 +180,8 @@
//! // render something (like clear_color) //! // render something (like clear_color)
//! event_loop.state().get(&backend).swap_buffers().unwrap(); //! event_loop.state().get(&backend).swap_buffers().unwrap();
//! //!
//! let _source = drm_device_bind(&mut event_loop, device, MyDrmHandler).unwrap(); //! let device_token = event_loop.state().insert(device);
//! let _source = drm_device_bind(&mut event_loop, device_token, MyDrmHandler).unwrap();
//! //!
//! event_loop.run().unwrap(); //! event_loop.run().unwrap();
//! # } //! # }