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

View File

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