From 9ee44672a01e38ef5c4fe506b08d78db17092185 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Wed, 21 Nov 2018 10:41:55 +0100 Subject: [PATCH] cargo fmt --- src/backend/drm/egl/mod.rs | 101 +++++++++++++++++----------- src/backend/drm/egl/session.rs | 15 +++-- src/backend/drm/egl/surface.rs | 65 +++++++++++------- src/backend/drm/gbm/egl.rs | 29 ++++---- src/backend/drm/gbm/error.rs | 6 +- src/backend/drm/gbm/mod.rs | 68 +++++++++++-------- src/backend/drm/gbm/session.rs | 37 +++++----- src/backend/drm/gbm/surface.rs | 98 ++++++++++++--------------- src/backend/drm/legacy/mod.rs | 46 +++++++------ src/backend/drm/legacy/session.rs | 10 +-- src/backend/drm/legacy/surface.rs | 108 ++++++++++-------------------- src/backend/drm/mod.rs | 32 ++++----- src/backend/egl/context.rs | 40 +++++------ src/backend/egl/mod.rs | 13 ++-- src/backend/egl/native.rs | 5 +- src/backend/egl/surface.rs | 2 +- src/backend/graphics/cursor.rs | 5 +- src/backend/graphics/errors.rs | 3 +- src/backend/graphics/gl.rs | 4 +- src/backend/graphics/glium.rs | 5 +- src/backend/libinput.rs | 14 ++-- src/backend/udev.rs | 17 ++--- src/backend/winit.rs | 17 ++--- 23 files changed, 372 insertions(+), 368 deletions(-) diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index 6f08942..e4570c4 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -1,15 +1,15 @@ use drm::control::{crtc, Mode}; use std::cell::RefCell; use std::collections::HashMap; -use std::rc::{Rc, Weak}; use std::os::unix::io::{AsRawFd, RawFd}; +use std::rc::{Rc, Weak}; use wayland_server::Display; -use backend::egl::{EGLContext, EGLGraphicsBackend, EGLDisplay}; +use super::{Device, DeviceHandler, Surface}; use backend::egl::context::GlAttributes; -use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; use backend::egl::error::Result as EGLResult; -use super::{Device, Surface, DeviceHandler}; +use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; +use backend::egl::{EGLContext, EGLDisplay, EGLGraphicsBackend}; pub mod error; use self::error::*; @@ -21,24 +21,31 @@ pub use self::surface::*; pub mod session; /// Representation of an open gbm device to create rendering backends -pub struct EglDevice::Surface> + 'static, D: Device + NativeDisplay + 'static> - where ::Surface: NativeSurface +pub struct EglDevice< + B: Backend::Surface> + 'static, + D: Device + NativeDisplay + 'static, +> where + ::Surface: NativeSurface, { dev: Rc>>, backends: Rc>>>>, logger: ::slog::Logger, } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> AsRawFd for EglDevice - where ::Surface: NativeSurface +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> AsRawFd + for EglDevice +where + ::Surface: NativeSurface, { fn as_raw_fd(&self) -> RawFd { self.dev.borrow().as_raw_fd() } } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> EglDevice - where ::Surface: NativeSurface +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> + EglDevice +where + ::Surface: NativeSurface, { /// Create a new `EglGbmDrmDevice` from an open drm node /// @@ -75,12 +82,8 @@ impl::Surface> + 'static, D: Device + NativeDis debug!(log, "Creating egl context from device"); Ok(EglDevice { // Open the gbm device from the drm device and create a context based on that - dev: Rc::new(RefCell::new(EGLContext::new( - dev, - attributes, - Default::default(), - log.clone(), - ).map_err(Error::from)? + dev: Rc::new(RefCell::new( + EGLContext::new(dev, attributes, Default::default(), log.clone()).map_err(Error::from)?, )), backends: Rc::new(RefCell::new(HashMap::new())), logger: log, @@ -88,20 +91,28 @@ impl::Surface> + 'static, D: Device + NativeDis } } -struct InternalDeviceHandler::Surface> + 'static, D: Device + NativeDisplay + 'static> - where ::Surface: NativeSurface +struct InternalDeviceHandler< + B: Backend::Surface> + 'static, + D: Device + NativeDisplay + 'static, +> where + ::Surface: NativeSurface, { - handler: Box> + 'static>, + handler: Box> + 'static>, backends: Weak>>>>, logger: ::slog::Logger, } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> DeviceHandler for InternalDeviceHandler - where - >::Arguments: From<(crtc::Handle, Mode, <::Surface as Surface>::Connectors)>, - ::Surface: NativeSurface, +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> + DeviceHandler for InternalDeviceHandler +where + >::Arguments: From<( + crtc::Handle, + Mode, + <::Surface as Surface>::Connectors, + )>, + ::Surface: NativeSurface, { - type Device=D; + type Device = D; fn vblank(&mut self, surface: &::Surface) { if let Some(backends) = self.backends.upgrade() { @@ -110,31 +121,41 @@ impl::Surface> + 'static, D: Device + NativeDis self.handler.vblank(&*surface); } } else { - warn!(self.logger, "Surface ({:?}) not managed by egl, event not handled.", surface.crtc()); + warn!( + self.logger, + "Surface ({:?}) not managed by egl, event not handled.", + surface.crtc() + ); } } } fn error(&mut self, error: <::Surface as Surface>::Error) { - self.handler.error(ResultExt::<()>::chain_err(Err(error), || ErrorKind::UnderlyingBackendError).unwrap_err()) + self.handler + .error(ResultExt::<()>::chain_err(Err(error), || ErrorKind::UnderlyingBackendError).unwrap_err()) } } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> Device for EglDevice - where - >::Arguments: From<(crtc::Handle, Mode, <::Surface as Surface>::Connectors)>, - ::Surface: NativeSurface, +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> Device + for EglDevice +where + >::Arguments: From<( + crtc::Handle, + Mode, + <::Surface as Surface>::Connectors, + )>, + ::Surface: NativeSurface, { type Surface = EglSurface; type Return = Rc>; - fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { + fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { self.dev.borrow_mut().set_handler(InternalDeviceHandler { handler: Box::new(handler), backends: Rc::downgrade(&self.backends), logger: self.logger.clone(), }); } - + fn clear_handler(&mut self) { self.dev.borrow_mut().clear_handler() } @@ -147,7 +168,10 @@ impl::Surface> + 'static, D: Device + NativeDis ) -> Result>> { info!(self.logger, "Initializing EglSurface"); - let surface = self.dev.borrow_mut().create_surface((crtc, mode, connectors.into()).into())?; + let surface = self + .dev + .borrow_mut() + .create_surface((crtc, mode, connectors.into()).into())?; let backend = Rc::new(EglSurface { dev: self.dev.clone(), @@ -157,16 +181,17 @@ impl::Surface> + 'static, D: Device + NativeDis Ok(backend) } - fn process_events(&mut self) { - self.dev.borrow_mut().process_events() + self.dev.borrow_mut().process_events() } } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> EGLGraphicsBackend for EglDevice - where ::Surface: NativeSurface +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> + EGLGraphicsBackend for EglDevice +where + ::Surface: NativeSurface, { fn bind_wl_display(&self, display: &Display) -> EGLResult { self.dev.borrow().bind_wl_display(display) } -} \ No newline at end of file +} diff --git a/src/backend/drm/egl/session.rs b/src/backend/drm/egl/session.rs index f440544..338865d 100644 --- a/src/backend/drm/egl/session.rs +++ b/src/backend/drm/egl/session.rs @@ -1,9 +1,9 @@ use std::os::unix::io::RawFd; +use super::EglDevice; +use backend::drm::Device; use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; use backend::session::{AsSessionObserver, SessionObserver}; -use backend::drm::Device; -use super::{EglDevice}; /// `SessionObserver` linked to the `DrmDevice` it was created from. pub struct EglDeviceObserver { @@ -11,11 +11,12 @@ pub struct EglDeviceObserver { } impl< - S: SessionObserver + 'static, - B: Backend::Surface> + 'static, - D: Device + NativeDisplay + AsSessionObserver + 'static, -> AsSessionObserver> for EglDevice - where ::Surface: NativeSurface + S: SessionObserver + 'static, + B: Backend::Surface> + 'static, + D: Device + NativeDisplay + AsSessionObserver + 'static, + > AsSessionObserver> for EglDevice +where + ::Surface: NativeSurface, { fn observer(&mut self) -> EglDeviceObserver { EglDeviceObserver { diff --git a/src/backend/drm/egl/surface.rs b/src/backend/drm/egl/surface.rs index 3d62af6..9e97168 100644 --- a/src/backend/drm/egl/surface.rs +++ b/src/backend/drm/egl/surface.rs @@ -3,22 +3,27 @@ use nix::libc::c_void; use std::cell::RefCell; use std::rc::Rc; -use backend::drm::{Device, Surface}; -use backend::egl::{EGLContext, EGLSurface}; -use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; -use backend::graphics::{CursorBackend, SwapBuffersError}; -use backend::graphics::gl::{GLGraphicsBackend, PixelFormat}; use super::error::*; +use backend::drm::{Device, Surface}; +use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; +use backend::egl::{EGLContext, EGLSurface}; +use backend::graphics::gl::{GLGraphicsBackend, PixelFormat}; +use backend::graphics::{CursorBackend, SwapBuffersError}; -pub struct EglSurface::Surface> + 'static, D: Device + NativeDisplay + 'static> - where ::Surface: NativeSurface +pub struct EglSurface< + B: Backend::Surface> + 'static, + D: Device + NativeDisplay + 'static, +> where + ::Surface: NativeSurface, { - pub(in super) dev: Rc>>, - pub(in super) surface: EGLSurface, + pub(super) dev: Rc>>, + pub(super) surface: EGLSurface, } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> Surface for EglSurface - where ::Surface: NativeSurface +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> Surface + for EglSurface +where + ::Surface: NativeSurface, { type Error = Error; type Connectors = <::Surface as Surface>::Connectors; @@ -30,36 +35,43 @@ impl::Surface> + 'static, D: Device + NativeDis fn current_connectors(&self) -> Self::Connectors { self.surface.current_connectors() } - + fn pending_connectors(&self) -> Self::Connectors { self.surface.pending_connectors() } fn add_connector(&self, connector: connector::Handle) -> Result<()> { - self.surface.add_connector(connector).chain_err(|| ErrorKind::UnderlyingBackendError) + self.surface + .add_connector(connector) + .chain_err(|| ErrorKind::UnderlyingBackendError) } fn remove_connector(&self, connector: connector::Handle) -> Result<()> { - self.surface.remove_connector(connector).chain_err(|| ErrorKind::UnderlyingBackendError) + self.surface + .remove_connector(connector) + .chain_err(|| ErrorKind::UnderlyingBackendError) } - + fn current_mode(&self) -> Mode { self.surface.current_mode() } - + fn pending_mode(&self) -> Mode { self.surface.pending_mode() } fn use_mode(&self, mode: Mode) -> Result<()> { - self.surface.use_mode(mode).chain_err(|| ErrorKind::UnderlyingBackendError) + self.surface + .use_mode(mode) + .chain_err(|| ErrorKind::UnderlyingBackendError) } } -impl<'a, B: Backend::Surface> + 'static, D: Device + NativeDisplay + 'static> CursorBackend<'a> for EglSurface - where - D: CursorBackend<'a>, - ::Surface: NativeSurface +impl<'a, B: Backend::Surface> + 'static, D: Device + NativeDisplay + 'static> + CursorBackend<'a> for EglSurface +where + D: CursorBackend<'a>, + ::Surface: NativeSurface, { type CursorFormat = >::CursorFormat; type Error = >::Error; @@ -73,15 +85,18 @@ impl<'a, B: Backend::Surface> + 'static, D: Device + Nativ buffer: Self::CursorFormat, hotspot: (u32, u32), ) -> ::std::result::Result<(), Self::Error> - where 'a: 'b + where + 'a: 'b, { let dev = self.dev.borrow(); dev.set_cursor_representation(buffer, hotspot) } } -impl::Surface> + 'static, D: Device + NativeDisplay + 'static> GLGraphicsBackend for EglSurface - where ::Surface: NativeSurface +impl::Surface> + 'static, D: Device + NativeDisplay + 'static> + GLGraphicsBackend for EglSurface +where + ::Surface: NativeSurface, { fn swap_buffers(&self) -> ::std::result::Result<(), SwapBuffersError> { self.surface.swap_buffers() @@ -107,4 +122,4 @@ impl::Surface> + 'static, D: Device + NativeDis fn get_pixel_format(&self) -> PixelFormat { self.dev.borrow().get_pixel_format() } -} \ No newline at end of file +} diff --git a/src/backend/drm/gbm/egl.rs b/src/backend/drm/gbm/egl.rs index 915df9b..edac7ec 100644 --- a/src/backend/drm/gbm/egl.rs +++ b/src/backend/drm/gbm/egl.rs @@ -1,29 +1,29 @@ -use backend::drm::{RawDevice, Device, RawSurface, Surface}; -use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; -use backend::egl::error::{Result as EglResult}; +use backend::drm::{Device, RawDevice, RawSurface, Surface}; +use backend::egl::error::Result as EglResult; use backend::egl::ffi; +use backend::egl::native::{Backend, NativeDisplay, NativeSurface}; use backend::graphics::SwapBuffersError; -use super::{GbmDevice, GbmSurface}; use super::error::{Error, Result}; +use super::{GbmDevice, GbmSurface}; use drm::control::{crtc, Device as ControlDevice, Mode}; use gbm::AsRaw; use std::marker::PhantomData; -use std::rc::Rc; use std::ptr; +use std::rc::Rc; /// Gbm backend type pub struct Gbm where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { _userdata: PhantomData, } impl Backend for Gbm where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { type Surface = Rc>; @@ -54,7 +54,7 @@ where /// Arguments necessary to construct a `GbmSurface` pub struct SurfaceArguments where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { /// Crtc pub crtc: crtc::Handle, @@ -64,9 +64,10 @@ where pub connectors: as Surface>::Connectors, } -impl From<(crtc::Handle, Mode, as Surface>::Connectors)> for SurfaceArguments +impl From<(crtc::Handle, Mode, as Surface>::Connectors)> + for SurfaceArguments where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { fn from((crtc, mode, connectors): (crtc::Handle, Mode, as Surface>::Connectors)) -> Self { SurfaceArguments { @@ -79,7 +80,7 @@ where unsafe impl NativeDisplay> for GbmDevice where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { type Arguments = SurfaceArguments; type Error = Error; @@ -99,7 +100,7 @@ where unsafe impl NativeSurface for Rc> where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { fn ptr(&self) -> ffi::NativeWindowType { self.surface.borrow().as_raw() as *const _ @@ -107,7 +108,7 @@ where fn swap_buffers(&self, flip: F) -> ::std::result::Result<(), SwapBuffersError> where - F: FnOnce() -> ::std::result::Result<(), SwapBuffersError> + F: FnOnce() -> ::std::result::Result<(), SwapBuffersError>, { if ::std::borrow::Borrow::borrow(&self.crtc).commit_pending() { self.recreate(flip).map_err(|_| SwapBuffersError::ContextLost) @@ -115,4 +116,4 @@ where self.page_flip(flip) } } -} \ No newline at end of file +} diff --git a/src/backend/drm/gbm/error.rs b/src/backend/drm/gbm/error.rs index e2fba7e..484e79c 100644 --- a/src/backend/drm/gbm/error.rs +++ b/src/backend/drm/gbm/error.rs @@ -9,19 +9,19 @@ error_chain! { description("Creation of gbm device failed"), display("Creation of gbm device failed"), } - + #[doc = "Creation of gbm surface failed"] SurfaceCreationFailed { description("Creation of gbm surface failed"), display("Creation of gbm surface failed"), } - + #[doc = "Creation of gbm buffer object failed"] BufferCreationFailed { description("Creation of gbm buffer object failed"), display("Creation of gbm buffer object failed"), } - + #[doc = "Writing to gbm buffer failed"] BufferWriteFailed { description("Writing to gbm buffer failed"), diff --git a/src/backend/drm/gbm/mod.rs b/src/backend/drm/gbm/mod.rs index 43f501e..d13f06a 100644 --- a/src/backend/drm/gbm/mod.rs +++ b/src/backend/drm/gbm/mod.rs @@ -1,13 +1,13 @@ -use super::{Device, RawDevice, Surface, DeviceHandler}; +use super::{Device, DeviceHandler, RawDevice, Surface}; use drm::control::{crtc, framebuffer, Device as ControlDevice, Mode}; -use gbm::{self, Format as GbmFormat, BufferObjectFlags}; +use gbm::{self, BufferObjectFlags, Format as GbmFormat}; use std::cell::{Cell, RefCell}; use std::collections::HashMap; +use std::os::unix::io::{AsRawFd, RawFd}; use std::rc::{Rc, Weak}; use std::sync::{Once, ONCE_INIT}; -use std::os::unix::io::{AsRawFd, RawFd}; pub mod error; use self::error::*; @@ -25,16 +25,16 @@ static LOAD: Once = ONCE_INIT; /// Representation of an open gbm device to create rendering backends pub struct GbmDevice where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { - pub(in self) dev: Rc>>, + pub(self) dev: Rc>>, backends: Rc>>>>, logger: ::slog::Logger, } impl GbmDevice where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { /// Create a new `GbmDevice` from an open drm node /// @@ -56,7 +56,7 @@ where nix::libc::RTLD_LAZY | nix::libc::RTLD_GLOBAL, ); }); - + let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_gbm")); dev.clear_handler(); @@ -64,7 +64,9 @@ where debug!(log, "Creating gbm device"); Ok(GbmDevice { // Open the gbm device from the drm device - dev: Rc::new(RefCell::new(gbm::Device::new(dev).chain_err(|| ErrorKind::InitFailed)?)), + dev: Rc::new(RefCell::new( + gbm::Device::new(dev).chain_err(|| ErrorKind::InitFailed)?, + )), backends: Rc::new(RefCell::new(HashMap::new())), logger: log, }) @@ -73,16 +75,16 @@ where struct InternalDeviceHandler where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { - handler: Box> + 'static>, + handler: Box> + 'static>, backends: Weak>>>>, logger: ::slog::Logger, } impl DeviceHandler for InternalDeviceHandler where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { type Device = D; @@ -94,30 +96,35 @@ where self.handler.vblank(&*surface); } } else { - warn!(self.logger, "Surface ({:?}) not managed by gbm, event not handled.", surface.crtc()); + warn!( + self.logger, + "Surface ({:?}) not managed by gbm, event not handled.", + surface.crtc() + ); } } } fn error(&mut self, error: <::Surface as Surface>::Error) { - self.handler.error(ResultExt::<()>::chain_err(Err(error), || ErrorKind::UnderlyingBackendError).unwrap_err()) + self.handler + .error(ResultExt::<()>::chain_err(Err(error), || ErrorKind::UnderlyingBackendError).unwrap_err()) } } impl Device for GbmDevice where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { type Surface = GbmSurface; type Return = Rc>; - fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { + fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { self.dev.borrow_mut().set_handler(InternalDeviceHandler { handler: Box::new(handler), backends: Rc::downgrade(&self.backends), logger: self.logger.clone(), }); } - + fn clear_handler(&mut self) { self.dev.borrow_mut().clear_handler(); } @@ -126,17 +133,20 @@ where &mut self, crtc: crtc::Handle, mode: Mode, - connectors: impl Into<::Connectors> + connectors: impl Into<::Connectors>, ) -> Result>> { info!(self.logger, "Initializing GbmSurface"); let (w, h) = mode.size(); - let surface = self.dev.borrow().create_surface( - w as u32, - h as u32, - GbmFormat::XRGB8888, - BufferObjectFlags::SCANOUT | BufferObjectFlags::RENDERING, - ).chain_err(|| ErrorKind::SurfaceCreationFailed)?; + let surface = self + .dev + .borrow() + .create_surface( + w as u32, + h as u32, + GbmFormat::XRGB8888, + BufferObjectFlags::SCANOUT | BufferObjectFlags::RENDERING, + ).chain_err(|| ErrorKind::SurfaceCreationFailed)?; // init the first screen // (must be done before calling page_flip for the first time) @@ -147,11 +157,13 @@ where debug!(self.logger, "FrontBuffer color format: {:?}", front_bo.format()); // we need a framebuffer for the front buffer - let fb = framebuffer::create(&*self.dev.borrow(), &*front_bo).chain_err(|| ErrorKind::UnderlyingBackendError)?; + let fb = framebuffer::create(&*self.dev.borrow(), &*front_bo) + .chain_err(|| ErrorKind::UnderlyingBackendError)?; front_bo.set_userdata(fb).unwrap(); let cursor = Cell::new(( - self.dev.borrow() + self.dev + .borrow() .create_buffer_object( 1, 1, @@ -177,15 +189,15 @@ where } fn process_events(&mut self) { - self.dev.borrow_mut().process_events() + self.dev.borrow_mut().process_events() } } impl AsRawFd for GbmDevice where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { fn as_raw_fd(&self) -> RawFd { self.dev.borrow().as_raw_fd() } -} \ No newline at end of file +} diff --git a/src/backend/drm/gbm/session.rs b/src/backend/drm/gbm/session.rs index 1a84c41..70b1059 100644 --- a/src/backend/drm/gbm/session.rs +++ b/src/backend/drm/gbm/session.rs @@ -2,32 +2,29 @@ use drm::control::{crtc, Device as ControlDevice, ResourceInfo}; use gbm::BufferObject; use std::cell::RefCell; use std::collections::HashMap; -use std::rc::{Rc, Weak}; use std::os::unix::io::RawFd; +use std::rc::{Rc, Weak}; -use backend::session::{AsSessionObserver, SessionObserver}; -use backend::drm::{Device, RawDevice, RawSurface}; use super::{GbmDevice, GbmSurface}; +use backend::drm::{Device, RawDevice, RawSurface}; +use backend::session::{AsSessionObserver, SessionObserver}; /// `SessionObserver` linked to the `DrmDevice` it was created from. pub struct GbmDeviceObserver< S: SessionObserver + 'static, D: RawDevice + ControlDevice + AsSessionObserver + 'static, -> -where - ::Return: ::std::borrow::Borrow<::Surface> +> where + ::Return: ::std::borrow::Borrow<::Surface>, { observer: S, backends: Weak>>>>, logger: ::slog::Logger, } -impl< - S: SessionObserver + 'static, - D: RawDevice + ControlDevice + AsSessionObserver + 'static, -> AsSessionObserver> for GbmDevice +impl + 'static> + AsSessionObserver> for GbmDevice where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { fn observer(&mut self) -> GbmDeviceObserver { GbmDeviceObserver { @@ -38,12 +35,10 @@ where } } -impl< - S: SessionObserver + 'static, - D: RawDevice + ControlDevice + AsSessionObserver + 'static, -> SessionObserver for GbmDeviceObserver +impl + 'static> + SessionObserver for GbmDeviceObserver where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { fn pause(&mut self, devnum: Option<(u32, u32)>) { self.observer.pause(devnum); @@ -56,15 +51,17 @@ where for (crtc, backend) in backends.borrow().iter() { if let Some(backend) = backend.upgrade() { // restart rendering loop - if let Err(err) = - ::std::borrow::Borrow::borrow(&backend.crtc).page_flip(backend.current_frame_buffer.get().handle()) + if let Err(err) = ::std::borrow::Borrow::borrow(&backend.crtc) + .page_flip(backend.current_frame_buffer.get().handle()) { warn!(self.logger, "Failed to restart rendering loop. Error: {}", err); } // reset cursor { - let &(ref cursor, ref hotspot): &(BufferObject<()>, (u32, u32)) = - unsafe { &*backend.cursor.as_ptr() }; + let &(ref cursor, ref hotspot): &( + BufferObject<()>, + (u32, u32), + ) = unsafe { &*backend.cursor.as_ptr() }; if crtc::set_cursor2( &*backend.dev.borrow(), *crtc, diff --git a/src/backend/drm/gbm/surface.rs b/src/backend/drm/gbm/surface.rs index c279a00..f8ab680 100644 --- a/src/backend/drm/gbm/surface.rs +++ b/src/backend/drm/gbm/surface.rs @@ -1,13 +1,13 @@ +use super::super::{Device, RawDevice, RawSurface, Surface}; use super::error::*; -use super::super::{Device, RawDevice, Surface, RawSurface}; -use drm::control::{crtc, connector, framebuffer, Mode, ResourceInfo}; -use gbm::{self, SurfaceBufferHandle, Format as GbmFormat, BufferObject, BufferObjectFlags}; +use drm::control::{connector, crtc, framebuffer, Mode, ResourceInfo}; +use gbm::{self, BufferObject, BufferObjectFlags, Format as GbmFormat, SurfaceBufferHandle}; use image::{ImageBuffer, Rgba}; use std::cell::{Cell, RefCell}; -use std::rc::Rc; use std::os::unix::io::AsRawFd; +use std::rc::Rc; use backend::drm::legacy::{LegacyDrmDevice, LegacyDrmSurface}; use backend::graphics::CursorBackend; @@ -15,23 +15,23 @@ use backend::graphics::SwapBuffersError; pub struct GbmSurface where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { - pub(in super) dev: Rc>>, - pub(in super) surface: RefCell>, - pub(in super) crtc: ::Return, - pub(in super) cursor: Cell<(BufferObject<()>, (u32, u32))>, - pub(in super) current_frame_buffer: Cell, - pub(in super) front_buffer: Cell>, - pub(in super) next_buffer: Cell>>, - pub(in super) logger: ::slog::Logger, + pub(super) dev: Rc>>, + pub(super) surface: RefCell>, + pub(super) crtc: ::Return, + pub(super) cursor: Cell<(BufferObject<()>, (u32, u32))>, + pub(super) current_frame_buffer: Cell, + pub(super) front_buffer: Cell>, + pub(super) next_buffer: Cell>>, + pub(super) logger: ::slog::Logger, } impl GbmSurface where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { - pub(in super) fn unlock_buffer(&self) { + pub(super) fn unlock_buffer(&self) { // after the page swap is finished we need to release the rendered buffer. // this is called from the PageFlipHandler if let Some(next_buffer) = self.next_buffer.replace(None) { @@ -43,7 +43,7 @@ where pub fn page_flip(&self, flip: F) -> ::std::result::Result<(), SwapBuffersError> where - F: FnOnce() -> ::std::result::Result<(), SwapBuffersError> + F: FnOnce() -> ::std::result::Result<(), SwapBuffersError>, { let res = { let nb = self.next_buffer.take(); @@ -53,10 +53,7 @@ where }; if res { // We cannot call lock_front_buffer anymore without releasing the previous buffer, which will happen when the page flip is done - warn!( - self.logger, - "Tried to swap with an already queued flip" - ); + warn!(self.logger, "Tried to swap with an already queued flip"); return Err(SwapBuffersError::AlreadySwapped); } @@ -99,16 +96,13 @@ where pub fn recreate(&self, flip: F) -> Result<()> where - F: FnOnce() -> ::std::result::Result<(), SwapBuffersError> + F: FnOnce() -> ::std::result::Result<(), SwapBuffersError>, { let (w, h) = self.pending_mode().size(); // Recreate the surface and the related resources to match the new // resolution. - debug!( - self.logger, - "Reinitializing surface for new mode: {}:{}", w, h - ); + debug!(self.logger, "Reinitializing surface for new mode: {}:{}", w, h); let surface = self .dev .borrow_mut() @@ -125,7 +119,9 @@ where { if let Some(mut old_bo) = self.next_buffer.take() { if let Ok(Some(fb)) = old_bo.take_userdata() { - if let Err(err) = framebuffer::destroy(::std::borrow::Borrow::borrow(&self.crtc), fb.handle()) { + if let Err(err) = + framebuffer::destroy(::std::borrow::Borrow::borrow(&self.crtc), fb.handle()) + { warn!( self.logger, "Error releasing old back_buffer framebuffer: {:?}", err @@ -142,17 +138,14 @@ where .lock_front_buffer() .chain_err(|| ErrorKind::FrontBufferLockFailed)?; - debug!( - self.logger, - "FrontBuffer color format: {:?}", - front_bo.format() - ); + debug!(self.logger, "FrontBuffer color format: {:?}", front_bo.format()); // we also need a new framebuffer for the front buffer let fb = framebuffer::create(::std::borrow::Borrow::borrow(&self.crtc), &*front_bo) .chain_err(|| ErrorKind::UnderlyingBackendError)?; - ::std::borrow::Borrow::borrow(&self.crtc).commit(fb.handle()) + ::std::borrow::Borrow::borrow(&self.crtc) + .commit(fb.handle()) .chain_err(|| ErrorKind::UnderlyingBackendError)?; front_bo.set_userdata(fb).unwrap(); @@ -169,31 +162,28 @@ where // Drop the old surface after cleanup *self.surface.borrow_mut() = surface; - + Ok(()) } } impl Surface for GbmSurface where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { type Connectors = <::Surface as Surface>::Connectors; type Error = Error; fn crtc(&self) -> crtc::Handle { - ::std::borrow::Borrow::borrow(&self.crtc) - .crtc() + ::std::borrow::Borrow::borrow(&self.crtc).crtc() } fn current_connectors(&self) -> Self::Connectors { - ::std::borrow::Borrow::borrow(&self.crtc) - .current_connectors() + ::std::borrow::Borrow::borrow(&self.crtc).current_connectors() } - + fn pending_connectors(&self) -> Self::Connectors { - ::std::borrow::Borrow::borrow(&self.crtc) - .pending_connectors() + ::std::borrow::Borrow::borrow(&self.crtc).pending_connectors() } fn add_connector(&self, connector: connector::Handle) -> Result<()> { @@ -207,15 +197,13 @@ where .remove_connector(connector) .chain_err(|| ErrorKind::UnderlyingBackendError) } - + fn current_mode(&self) -> Mode { - ::std::borrow::Borrow::borrow(&self.crtc) - .current_mode() + ::std::borrow::Borrow::borrow(&self.crtc).current_mode() } - + fn pending_mode(&self) -> Mode { - ::std::borrow::Borrow::borrow(&self.crtc) - .pending_mode() + ::std::borrow::Borrow::borrow(&self.crtc).pending_mode() } fn use_mode(&self, mode: Mode) -> Result<()> { @@ -257,9 +245,9 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface Result<()> { ResultExt::chain_err( - ::std::borrow::Borrow::>>::borrow(&self.crtc) - .set_cursor_position(x, y), - || ErrorKind::UnderlyingBackendError) + ::std::borrow::Borrow::>>::borrow(&self.crtc).set_cursor_position(x, y), + || ErrorKind::UnderlyingBackendError, + ) } fn set_cursor_representation<'b>( @@ -267,7 +255,8 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface, Vec>, hotspot: (u32, u32), ) -> Result<()> - where 'a: 'b + where + 'a: 'b, { let (w, h) = buffer.dimensions(); debug!(self.logger, "Importing cursor"); @@ -293,7 +282,8 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface>>::borrow(&self.crtc) .set_cursor_representation(&cursor, hotspot), - || ErrorKind::UnderlyingBackendError)?; + || ErrorKind::UnderlyingBackendError, + )?; // and store it self.cursor.set((cursor, hotspot)); @@ -303,7 +293,7 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface Drop for GbmSurface where - ::Return: ::std::borrow::Borrow<::Surface> + ::Return: ::std::borrow::Borrow<::Surface>, { fn drop(&mut self) { // Drop framebuffers attached to the userdata of the gbm surface buffers. @@ -326,4 +316,4 @@ where let _ = framebuffer::destroy(::std::borrow::Borrow::borrow(&self.crtc), fb.handle()); } } -} \ No newline at end of file +} diff --git a/src/backend/drm/legacy/mod.rs b/src/backend/drm/legacy/mod.rs index 166e664..1bea1ad 100644 --- a/src/backend/drm/legacy/mod.rs +++ b/src/backend/drm/legacy/mod.rs @@ -1,16 +1,16 @@ -use super::{Device, RawDevice, Surface, DeviceHandler, DevPath}; +use super::{DevPath, Device, DeviceHandler, RawDevice, Surface}; +use drm::control::{connector, crtc, encoder, Device as ControlDevice, Mode, ResourceInfo}; use drm::Device as BasicDevice; -use drm::control::{crtc, connector, encoder, Device as ControlDevice, Mode, ResourceInfo}; use nix::libc::dev_t; use nix::sys::stat::fstat; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; -use std::rc::{Rc, Weak}; use std::os::unix::io::{AsRawFd, RawFd}; -use std::sync::{Arc, RwLock}; +use std::rc::{Rc, Weak}; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, RwLock}; mod surface; pub use self::surface::LegacyDrmSurface; @@ -29,7 +29,7 @@ pub struct LegacyDrmDevice { active: Arc, old_state: HashMap)>, backends: Rc>>>>, - handler: Option>>>>, + handler: Option>>>>, logger: ::slog::Logger, } @@ -122,10 +122,10 @@ impl Device for LegacyDrmDevice { type Surface = LegacyDrmSurface; type Return = Rc>; - fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { + fn set_handler(&mut self, handler: impl DeviceHandler + 'static) { self.handler = Some(RefCell::new(Box::new(handler))); } - + fn clear_handler(&mut self) { let _ = self.handler.take(); } @@ -134,7 +134,7 @@ impl Device for LegacyDrmDevice { &mut self, crtc: crtc::Handle, mode: Mode, - connectors: impl Into<::Connectors> + connectors: impl Into<::Connectors>, ) -> Result>> { if self.backends.borrow().contains_key(&crtc) { bail!(ErrorKind::CrtcAlreadyInUse(crtc)); @@ -181,11 +181,8 @@ impl Device for LegacyDrmDevice { // configuration is valid, the kernel will figure out the rest let logger = self.logger.new(o!("crtc" => format!("{:?}", crtc))); - - let state = State { - mode, - connectors, - }; + + let state = State { mode, connectors }; let backend = Rc::new(LegacyDrmSurface { dev: self.dev.clone(), @@ -194,17 +191,24 @@ impl Device for LegacyDrmDevice { pending: RwLock::new(state), logger, }); - + self.backends.borrow_mut().insert(crtc, Rc::downgrade(&backend)); Ok(backend) } - + fn process_events(&mut self) { match crtc::receive_events(self) { Ok(events) => for event in events { if let crtc::Event::PageFlip(event) = event { if self.active.load(Ordering::SeqCst) { - if let Some(backend) = self.backends.borrow().get(&event.crtc).iter().flat_map(|x| x.upgrade()).next() { + if let Some(backend) = self + .backends + .borrow() + .get(&event.crtc) + .iter() + .flat_map(|x| x.upgrade()) + .next() + { trace!(self.logger, "Handling event for backend {:?}", event.crtc); if let Some(handler) = self.handler.as_ref() { handler.borrow_mut().vblank(&backend); @@ -216,10 +220,12 @@ impl Device for LegacyDrmDevice { } }, Err(err) => if let Some(handler) = self.handler.as_ref() { - handler.borrow_mut().error(ResultExt::<()>::chain_err(Err(err), || - ErrorKind::DrmDev(format!("Error processing drm events on {:?}", self.dev_path())) - ).unwrap_err()); - } + handler.borrow_mut().error( + ResultExt::<()>::chain_err(Err(err), || { + ErrorKind::DrmDev(format!("Error processing drm events on {:?}", self.dev_path())) + }).unwrap_err(), + ); + }, } } } diff --git a/src/backend/drm/legacy/session.rs b/src/backend/drm/legacy/session.rs index bc80c09..dc319c0 100644 --- a/src/backend/drm/legacy/session.rs +++ b/src/backend/drm/legacy/session.rs @@ -1,16 +1,16 @@ +use drm::control::{connector, crtc, Device as ControlDevice}; use drm::Device as BasicDevice; -use drm::control::{crtc, connector, Device as ControlDevice}; use nix::libc::dev_t; use nix::sys::stat; use std::cell::RefCell; use std::collections::HashMap; -use std::rc::{Rc, Weak}; -use std::sync::Arc; -use std::sync::atomic::{AtomicBool, Ordering}; use std::os::unix::io::{AsRawFd, RawFd}; +use std::rc::{Rc, Weak}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; +use super::{Dev, LegacyDrmDevice, LegacyDrmSurface}; use backend::session::{AsSessionObserver, SessionObserver}; -use super::{LegacyDrmDevice, LegacyDrmSurface, Dev}; /// `SessionObserver` linked to the `DrmDevice` it was created from. pub struct LegacyDrmDeviceObserver { diff --git a/src/backend/drm/legacy/surface.rs b/src/backend/drm/legacy/surface.rs index 6f4b057..6b6d021 100644 --- a/src/backend/drm/legacy/surface.rs +++ b/src/backend/drm/legacy/surface.rs @@ -1,17 +1,17 @@ -use drm::Device as BasicDevice; -use drm::control::{connector, crtc, encoder, framebuffer, Device as ControlDevice, Mode, ResourceInfo}; pub use drm::buffer::Buffer; +use drm::control::{connector, crtc, encoder, framebuffer, Device as ControlDevice, Mode, ResourceInfo}; +use drm::Device as BasicDevice; use std::collections::HashSet; -use std::rc::Rc; use std::os::unix::io::{AsRawFd, RawFd}; +use std::rc::Rc; use std::sync::RwLock; -use backend::drm::{RawSurface, Surface, DevPath}; +use backend::drm::{DevPath, RawSurface, Surface}; use backend::graphics::CursorBackend; use backend::graphics::SwapBuffersError; -use super::{Dev, error::*}; +use super::{error::*, Dev}; #[derive(Debug, PartialEq, Eq, Clone)] pub struct State { @@ -20,11 +20,11 @@ pub struct State { } pub struct LegacyDrmSurface { - pub(in super) dev: Rc>, - pub(in super) crtc: crtc::Handle, - pub(in super) state: RwLock, - pub(in super) pending: RwLock, - pub(in super) logger: ::slog::Logger, + pub(super) dev: Rc>, + pub(super) crtc: crtc::Handle, + pub(super) state: RwLock, + pub(super) pending: RwLock, + pub(super) logger: ::slog::Logger, } impl AsRawFd for LegacyDrmSurface { @@ -42,36 +42,19 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurface { fn set_cursor_position(&self, x: u32, y: u32) -> Result<()> { trace!(self.logger, "Move the cursor to {},{}", x, y); - crtc::move_cursor(self, self.crtc, (x as i32, y as i32)).chain_err(|| { - ErrorKind::DrmDev(format!( - "Error moving cursor on {:?}", - self.dev_path() - )) - }) + crtc::move_cursor(self, self.crtc, (x as i32, y as i32)) + .chain_err(|| ErrorKind::DrmDev(format!("Error moving cursor on {:?}", self.dev_path()))) } - fn set_cursor_representation<'b>( - &'b self, - buffer: Self::CursorFormat, - hotspot: (u32, u32), - ) -> Result<()> - where 'a: 'b + fn set_cursor_representation<'b>(&'b self, buffer: Self::CursorFormat, hotspot: (u32, u32)) -> Result<()> + where + 'a: 'b, { trace!(self.logger, "Setting the new imported cursor"); - if crtc::set_cursor2( - self, - self.crtc, - buffer, - (hotspot.0 as i32, hotspot.1 as i32), - ).is_err() - { - crtc::set_cursor(self, self.crtc, buffer).chain_err(|| { - ErrorKind::DrmDev(format!( - "Failed to set cursor on {:?}", - self.dev_path() - )) - })?; + if crtc::set_cursor2(self, self.crtc, buffer, (hotspot.0 as i32, hotspot.1 as i32)).is_err() { + crtc::set_cursor(self, self.crtc, buffer) + .chain_err(|| ErrorKind::DrmDev(format!("Failed to set cursor on {:?}", self.dev_path())))?; } Ok(()) @@ -85,11 +68,11 @@ impl Surface for LegacyDrmSurface { fn crtc(&self) -> crtc::Handle { self.crtc } - + fn current_connectors(&self) -> Self::Connectors { self.state.read().unwrap().connectors.clone() } - + fn pending_connectors(&self) -> Self::Connectors { self.pending.read().unwrap().connectors.clone() } @@ -104,10 +87,7 @@ impl Surface for LegacyDrmSurface { fn add_connector(&self, connector: connector::Handle) -> Result<()> { let info = connector::Info::load_from_device(self, connector).chain_err(|| { - ErrorKind::DrmDev(format!( - "Error loading connector info on {:?}", - self.dev_path() - )) + ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) })?; let mut pending = self.pending.write().unwrap(); @@ -120,28 +100,19 @@ impl Surface for LegacyDrmSurface { .iter() .map(|encoder| { encoder::Info::load_from_device(self, *encoder).chain_err(|| { - ErrorKind::DrmDev(format!( - "Error loading encoder info on {:?}", - self.dev_path() - )) + ErrorKind::DrmDev(format!("Error loading encoder info on {:?}", self.dev_path())) }) }).collect::>>()?; // and if any encoder supports the selected crtc let resource_handles = self.resource_handles().chain_err(|| { - ErrorKind::DrmDev(format!( - "Error loading resources on {:?}", - self.dev_path() - )) + ErrorKind::DrmDev(format!("Error loading resources on {:?}", self.dev_path())) })?; if !encoders .iter() .map(|encoder| encoder.possible_crtcs()) - .all(|crtc_list| { - resource_handles - .filter_crtcs(crtc_list) - .contains(&self.crtc) - }) { + .all(|crtc_list| resource_handles.filter_crtcs(crtc_list).contains(&self.crtc)) + { bail!(ErrorKind::NoSuitableEncoder(info, self.crtc)); } @@ -159,15 +130,12 @@ impl Surface for LegacyDrmSurface { fn use_mode(&self, mode: Mode) -> Result<()> { let mut pending = self.pending.write().unwrap(); - + // check the connectors for connector in &pending.connectors { if !connector::Info::load_from_device(self, *connector) .chain_err(|| { - ErrorKind::DrmDev(format!( - "Error loading connector info on {:?}", - self.dev_path() - )) + ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) })?.modes() .contains(&mode) { @@ -185,7 +153,7 @@ impl RawSurface for LegacyDrmSurface { fn commit_pending(&self) -> bool { *self.pending.read().unwrap() != *self.state.read().unwrap() } - + fn commit(&self, framebuffer: framebuffer::Handle) -> Result<()> { let mut current = self.state.write().unwrap(); let pending = self.pending.read().unwrap(); @@ -196,11 +164,7 @@ impl RawSurface for LegacyDrmSurface { for conn in removed { if let Ok(info) = connector::Info::load_from_device(self, *conn) { - info!( - self.logger, - "Removing connector: {:?}", - info.connector_type() - ); + info!(self.logger, "Removing connector: {:?}", info.connector_type()); } else { info!(self.logger, "Removing unknown connector"); } @@ -208,11 +172,7 @@ impl RawSurface for LegacyDrmSurface { for conn in added { if let Ok(info) = connector::Info::load_from_device(self, *conn) { - info!( - self.logger, - "Adding connector: {:?}", - info.connector_type() - ); + info!(self.logger, "Adding connector: {:?}", info.connector_type()); } else { info!(self.logger, "Adding unknown connector"); } @@ -228,7 +188,11 @@ impl RawSurface for LegacyDrmSurface { self, self.crtc, framebuffer, - &pending.connectors.iter().map(|x| *x).collect::>(), + &pending + .connectors + .iter() + .map(|x| *x) + .collect::>(), (0, 0), Some(pending.mode), ).chain_err(|| { @@ -243,7 +207,7 @@ impl RawSurface for LegacyDrmSurface { Ok(()) } - + fn page_flip(&self, framebuffer: framebuffer::Handle) -> ::std::result::Result<(), SwapBuffersError> { trace!(self.logger, "Queueing Page flip"); diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index 05f5e21..1a2d05c 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -1,28 +1,28 @@ -use drm::Device as BasicDevice; -use drm::control::Device as ControlDevice; -pub use drm::control::crtc; 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; use std::borrow::Borrow; use std::error::Error; -use std::path::PathBuf; use std::os::unix::io::AsRawFd; +use std::path::PathBuf; use wayland_server::calloop::generic::{EventedFd, Generic}; -use wayland_server::calloop::{LoopHandle, Source}; use wayland_server::calloop::mio::Ready; pub use wayland_server::calloop::InsertError; +use wayland_server::calloop::{LoopHandle, Source}; use super::graphics::SwapBuffersError; -#[cfg(feature = "backend_drm_legacy")] -pub mod legacy; -#[cfg(feature = "backend_drm_gbm")] -pub mod gbm; #[cfg(feature = "backend_drm_egl")] pub mod egl; +#[cfg(feature = "backend_drm_gbm")] +pub mod gbm; +#[cfg(feature = "backend_drm_legacy")] +pub mod legacy; pub trait DeviceHandler { type Device: Device + ?Sized; @@ -34,26 +34,26 @@ pub trait Device: AsRawFd + DevPath { type Surface: Surface; type Return: Borrow; - fn set_handler(&mut self, handler: impl DeviceHandler + 'static); + fn set_handler(&mut self, handler: impl DeviceHandler + 'static); fn clear_handler(&mut self); fn create_surface( &mut self, ctrc: crtc::Handle, mode: Mode, - connectors: impl Into<::Connectors> + connectors: impl Into<::Connectors>, ) -> Result::Error>; fn process_events(&mut self); } -pub trait RawDevice: Device::Surface> +pub trait RawDevice: Device::Surface> where - ::Return: Borrow<::Surface> + ::Return: Borrow<::Surface>, { type Surface: RawSurface; } pub trait Surface { - type Connectors: IntoIterator; + type Connectors: IntoIterator; type Error: Error + Send; fn crtc(&self) -> crtc::Handle; @@ -70,7 +70,7 @@ pub trait RawSurface: Surface + ControlDevice + BasicDevice { fn commit_pending(&self) -> bool; fn commit(&self, framebuffer: framebuffer::Handle) -> Result<(), ::Error>; fn page_flip(&self, framebuffer: framebuffer::Handle) -> Result<(), SwapBuffersError>; -} +} /// Trait for types representing open devices pub trait DevPath { @@ -82,7 +82,7 @@ impl DevPath for A { fn dev_path(&self) -> Option { use std::fs; - fs::read_link(format!("/proc/self/fd/{:?}", self.as_raw_fd())).ok() + fs::read_link(format!("/proc/self/fd/{:?}", self.as_raw_fd())).ok() } } diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index 4c64afc..070c07a 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -52,14 +52,8 @@ impl> EGLContext { { let log = ::slog_or_stdlog(logger.into()).new(o!("smithay_module" => "renderer_egl")); let ptr = native.ptr()?; - let ( - context, - display, - config_id, - surface_attributes, - pixel_format, - wl_drm_support, - ) = unsafe { EGLContext::::new_internal(ptr, attributes, reqs, log.clone()) }?; + let (context, display, config_id, surface_attributes, pixel_format, wl_drm_support) = + unsafe { EGLContext::::new_internal(ptr, attributes, reqs, log.clone()) }?; Ok(EGLContext { native, @@ -117,15 +111,15 @@ impl> EGLContext { bail!(ErrorKind::OpenGlVersionNotSupported(version)); } }; - - fn constrain(f: F) -> F - where - F: for<'a> Fn(&'a str) -> *const ::std::os::raw::c_void, - { - f - }; - + ffi::egl::LOAD.call_once(|| { + fn constrain(f: F) -> F + where + F: for<'a> Fn(&'a str) -> *const ::std::os::raw::c_void, + { + f + }; + ffi::egl::load_with(|sym| { let name = CString::new(sym).unwrap(); let symbol = ffi::egl::LIB.get::<*mut c_void>(name.as_bytes()); @@ -144,7 +138,7 @@ impl> EGLContext { ffi::egl::UnbindWaylandDisplayWL::load_with(&proc_address); ffi::egl::QueryWaylandBufferWL::load_with(&proc_address); }); - + // the first step is to query the list of extensions without any display, if supported let dp_extensions = { let p = ffi::egl::QueryString(ffi::egl::NO_DISPLAY, ffi::egl::EXTENSIONS as i32); @@ -437,13 +431,11 @@ impl> EGLContext { /// Creates a surface for rendering pub fn create_surface(&mut self, args: N::Arguments) -> Result> { trace!(self.logger, "Creating EGL window surface."); - let surface = self.native - .create_surface(args) - .chain_err(|| ErrorKind::SurfaceCreationFailed)?; - EGLSurface::new( - self, - surface, - ).map(|x| { + let surface = self + .native + .create_surface(args) + .chain_err(|| ErrorKind::SurfaceCreationFailed)?; + EGLSurface::new(self, surface).map(|x| { debug!(self.logger, "EGL surface successfully created"); x }) diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index 9335b7c..3516c15 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -181,7 +181,9 @@ impl ::std::error::Error for TextureCreationError { match *self { TextureCreationError::ContextLost => "The context has been lost, it needs to be recreated", TextureCreationError::PlaneIndexOutOfBounds => "This buffer is not managed by EGL", - TextureCreationError::GLExtensionNotSupported(_) => "Required OpenGL Extension for texture creation is missing", + TextureCreationError::GLExtensionNotSupported(_) => { + "Required OpenGL Extension for texture creation is missing" + } TextureCreationError::TextureBindingFailed(_) => "Failed to create EGLImages from the buffer", } } @@ -263,7 +265,7 @@ impl EGLImages { if !self.egl_to_texture_support { return Err(TextureCreationError::GLExtensionNotSupported("GL_OES_EGL_image")); } - + let mut old_tex_id: i32 = 0; self.gl.GetIntegerv(gl_ffi::TEXTURE_BINDING_2D, &mut old_tex_id); self.gl.BindTexture(gl_ffi::TEXTURE_2D, tex_id); @@ -343,11 +345,12 @@ impl EGLDisplay { #[cfg(feature = "renderer_gl")] egl_to_texture_support: { // the list of gl extensions supported by the context - let data = unsafe { CStr::from_ptr(gl.GetString(gl_ffi::EXTENSIONS) as *const _ )} + let data = unsafe { CStr::from_ptr(gl.GetString(gl_ffi::EXTENSIONS) as *const _) } .to_bytes() .to_vec(); let list = String::from_utf8(data).unwrap(); - list.split(' ').any(|s| s == "GL_OES_EGL_image" || s == "GL_OES_EGL_image_base") + list.split(' ') + .any(|s| s == "GL_OES_EGL_image" || s == "GL_OES_EGL_image_base") }, #[cfg(feature = "renderer_gl")] gl, @@ -496,4 +499,4 @@ impl> EGLGraphicsBackend for EGL } Ok(EGLDisplay::new(self, display.c_ptr())) } -} \ No newline at end of file +} diff --git a/src/backend/egl/native.rs b/src/backend/egl/native.rs index 6e4e79e..2cfb9f7 100644 --- a/src/backend/egl/native.rs +++ b/src/backend/egl/native.rs @@ -169,9 +169,10 @@ pub unsafe trait NativeSurface { fn ptr(&self) -> ffi::NativeWindowType; /// Adds additional semantics when calling EGLSurface::swap_buffers /// - /// Only implement if required by the backend, flip must be called during this call. + /// Only implement if required by the backend, flip must be called during this call. fn swap_buffers(&self, flip: F) -> ::std::result::Result<(), SwapBuffersError> - where F: FnOnce() -> ::std::result::Result<(), SwapBuffersError> + where + F: FnOnce() -> ::std::result::Result<(), SwapBuffersError>, { flip() } diff --git a/src/backend/egl/surface.rs b/src/backend/egl/surface.rs index 71970cb..3e11ce5 100644 --- a/src/backend/egl/surface.rs +++ b/src/backend/egl/surface.rs @@ -66,7 +66,7 @@ impl EGLSurface { err => Err(SwapBuffersError::Unknown(err)), } } else { - Ok(()) + Ok(()) } } else { Err(SwapBuffersError::ContextLost) diff --git a/src/backend/graphics/cursor.rs b/src/backend/graphics/cursor.rs index fe2ab8c..e08c5cc 100644 --- a/src/backend/graphics/cursor.rs +++ b/src/backend/graphics/cursor.rs @@ -29,5 +29,6 @@ pub trait CursorBackend<'a> { cursor: Self::CursorFormat, hotspot: (u32, u32), ) -> Result<(), Self::Error> - where 'a: 'b; -} \ No newline at end of file + where + 'a: 'b; +} diff --git a/src/backend/graphics/errors.rs b/src/backend/graphics/errors.rs index 4b0b56a..fa9e9a7 100644 --- a/src/backend/graphics/errors.rs +++ b/src/backend/graphics/errors.rs @@ -1,5 +1,5 @@ -use std::fmt; use std::error::Error; +use std::fmt; /// Error that can happen when swapping buffers. #[derive(Debug, Clone, PartialEq)] @@ -43,4 +43,3 @@ impl Error for SwapBuffersError { None } } - diff --git a/src/backend/graphics/gl.rs b/src/backend/graphics/gl.rs index 5f120b5..78c3c9f 100644 --- a/src/backend/graphics/gl.rs +++ b/src/backend/graphics/gl.rs @@ -67,10 +67,10 @@ pub trait GLGraphicsBackend { } /// Loads a Raw GLES Interface for a given `GLGraphicsBackend` -/// +/// /// This remains valid as long as the underlying `GLGraphicsBackend` is alive /// and may only be used in combination with the backend. Using this with any /// other gl context may cause undefined behavior. pub fn load_raw_gl(backend: &B) -> Gles2 { Gles2::load_with(|s| unsafe { backend.get_proc_address(s) as *const _ }) -} \ No newline at end of file +} diff --git a/src/backend/graphics/glium.rs b/src/backend/graphics/glium.rs index caf1b1f..ab83d86 100644 --- a/src/backend/graphics/glium.rs +++ b/src/backend/graphics/glium.rs @@ -1,9 +1,6 @@ //! Glium compatibility module -use backend::graphics::{ - gl::GLGraphicsBackend, - SwapBuffersError, -}; +use backend::graphics::{gl::GLGraphicsBackend, SwapBuffersError}; use glium::{ backend::{Backend, Context, Facade}, debug::DebugCallbackBehavior, diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index 4e62ca7..8ffc7e1 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -16,13 +16,16 @@ use std::{ use wayland_server::calloop::{ generic::{EventedFd, Generic}, mio::Ready, - LoopHandle, Source, InsertError, + InsertError, LoopHandle, Source, }; // No idea if this is the same across unix platforms // Lets make this linux exclusive for now, once someone tries to build it for // any BSD-like system, they can verify if this is right and make a PR to change this. -#[cfg(all(any(target_os = "linux", target_os = "android"), feature = "backend_session"))] +#[cfg(all( + any(target_os = "linux", target_os = "android"), + feature = "backend_session" +))] const INPUT_MAJOR: u32 = 13; /// Libinput based `InputBackend`. @@ -600,13 +603,16 @@ impl AsRawFd for LibinputInputBackend { pub fn libinput_bind( backend: LibinputInputBackend, handle: LoopHandle, -) -> ::std::result::Result>>, InsertError>>> { +) -> ::std::result::Result< + Source>>, + InsertError>>, +> { let mut source = Generic::from_fd_source(backend); source.set_interest(Ready::readable()); handle.insert_source(source, move |evt, _| { use backend::input::InputBackend; - + let mut backend = evt.source.borrow_mut(); if let Err(error) = backend.0.dispatch_new_events() { warn!(backend.0.logger, "Libinput errored: {}", error); diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 3f94d95..4ae69a8 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -21,7 +21,7 @@ use udev::{Context, Enumerator, EventType, MonitorBuilder, MonitorSocket, Result use wayland_server::calloop::{ generic::{EventedFd, Generic}, mio::Ready, - LoopHandle, Source, InsertError, + InsertError, LoopHandle, Source, }; /// Backend to monitor available drm devices. @@ -48,7 +48,7 @@ impl UdevBackend { /// ## Arguments /// `context` - An initialized udev context /// `handler` - User-provided handler to respond to any detected changes - /// `seat` - + /// `seat` - /// `logger` - slog Logger to be used by the backend and its `DrmDevices`. pub fn new>( context: &Context, @@ -66,15 +66,14 @@ impl UdevBackend { // Create devices .flat_map(|path| match stat(&path) { Ok(stat) => { - handler.device_added(stat.st_rdev, path); + handler.device_added(stat.st_rdev, path); Some(stat.st_rdev) - }, + } Err(err) => { warn!(log, "Unable to get id of {:?}, Error: {:?}. Skipping", path, err); None } - }) - .collect(); + }).collect(); let mut builder = MonitorBuilder::new(context)?; builder.match_subsystem("drm")?; @@ -89,8 +88,7 @@ impl UdevBackend { } } -impl Drop for UdevBackend -{ +impl Drop for UdevBackend { fn drop(&mut self) { for device in &self.devices { self.handler.device_removed(*device); @@ -105,8 +103,7 @@ impl Drop for UdevBackend pub fn udev_backend_bind( handle: &LoopHandle, udev: UdevBackend, -) -> Result>>>, InsertError>>>> -{ +) -> Result>>>, InsertError>>>> { let mut source = Generic::from_fd_source(udev); source.set_interest(Ready::readable()); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index f7d3a41..fef1f74 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -1,17 +1,13 @@ //! Implementation of backend traits for types provided by `winit` use backend::{ + egl::{ + context::GlAttributes, error as egl_error, error::Result as EGLResult, native, EGLContext, + EGLDisplay, EGLGraphicsBackend, EGLSurface, + }, graphics::{ gl::{GLGraphicsBackend, PixelFormat}, - CursorBackend, - SwapBuffersError, - }, - egl::{ - context::GlAttributes, - error as egl_error, - error::Result as EGLResult, - native, - EGLDisplay, EGLContext, EGLGraphicsBackend, EGLSurface, + CursorBackend, SwapBuffersError, }, input::{ Axis, AxisSource, Event as BackendEvent, InputBackend, InputHandler, KeyState, KeyboardKeyEvent, @@ -246,7 +242,8 @@ impl<'a> CursorBackend<'a> for WinitGraphicsBackend { cursor: Self::CursorFormat, _hotspot: (u32, u32), ) -> ::std::result::Result<(), ()> - where 'a: 'b + where + 'a: 'b, { // Cannot log this one, as `CursorFormat` is not `Debug` and should not be debug!(self.logger, "Changing cursor representation");