lint: fmt & clippy

This commit is contained in:
Victor Brekenfeld 2020-05-03 20:28:20 +02:00
parent 20b373470f
commit f1c40f7306
11 changed files with 130 additions and 82 deletions

View File

@ -16,7 +16,11 @@ use smithay::backend::egl::display::EGLBufferReader;
use smithay::{ use smithay::{
backend::{ backend::{
egl::{BufferAccessError, EGLImages, Format}, egl::{BufferAccessError, EGLImages, Format},
graphics::{gl::GLGraphicsBackend, glium::{GliumGraphicsBackend, Frame}, SwapBuffersError}, graphics::{
gl::GLGraphicsBackend,
glium::{Frame, GliumGraphicsBackend},
SwapBuffersError,
},
}, },
reexports::{ reexports::{
calloop::LoopHandle, calloop::LoopHandle,
@ -458,21 +462,21 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
} }
} }
pub fn schedule_initial_render<F: GLGraphicsBackend + 'static, Data: 'static>(renderer: Rc<GliumDrawer<F>>, evt_handle: &LoopHandle<Data>) { pub fn schedule_initial_render<F: GLGraphicsBackend + 'static, Data: 'static>(
renderer: Rc<GliumDrawer<F>>,
evt_handle: &LoopHandle<Data>,
) {
let mut frame = renderer.draw(); let mut frame = renderer.draw();
frame.clear_color(0.8, 0.8, 0.9, 1.0); frame.clear_color(0.8, 0.8, 0.9, 1.0);
if let Err(err) = frame.set_finish() { if let Err(err) = frame.set_finish() {
match err { match err {
SwapBuffersError::AlreadySwapped => {}, SwapBuffersError::AlreadySwapped => {}
SwapBuffersError::TemporaryFailure(err) => { SwapBuffersError::TemporaryFailure(err) => {
// TODO dont reschedule after 3(?) retries // TODO dont reschedule after 3(?) retries
error!( error!(renderer.log, "Failed to submit page_flip: {}", err);
renderer.log,
"Failed to submit page_flip: {}", err
);
let handle = evt_handle.clone(); let handle = evt_handle.clone();
evt_handle.insert_idle(move |_| schedule_initial_render(renderer, &handle)); evt_handle.insert_idle(move |_| schedule_initial_render(renderer, &handle));
}, }
SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err), SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err),
} }
} }

View File

@ -39,11 +39,14 @@ use smithay::{
timer::{Timer, TimerHandle}, timer::{Timer, TimerHandle},
EventLoop, LoopHandle, Source, EventLoop, LoopHandle, Source,
}, },
drm::{self, control::{ drm::{
self,
control::{
connector::{Info as ConnectorInfo, State as ConnectorState}, connector::{Info as ConnectorInfo, State as ConnectorState},
crtc, crtc,
encoder::Info as EncoderInfo, encoder::Info as EncoderInfo,
}}, },
},
image::{ImageBuffer, Rgba}, image::{ImageBuffer, Rgba},
input::Libinput, input::Libinput,
nix::{fcntl::OFlag, sys::stat::dev_t}, nix::{fcntl::OFlag, sys::stat::dev_t},
@ -61,7 +64,7 @@ use smithay::{
}; };
use crate::buffer_utils::BufferUtils; use crate::buffer_utils::BufferUtils;
use crate::glium_drawer::{GliumDrawer, schedule_initial_render}; use crate::glium_drawer::{schedule_initial_render, GliumDrawer};
use crate::shell::{MyWindowMap, Roles}; use crate::shell::{MyWindowMap, Roles};
use crate::state::AnvilState; use crate::state::AnvilState;
@ -431,8 +434,14 @@ impl<S: SessionNotifier, Data: 'static> UdevHandlerImpl<S, Data> {
dnd_icon: self.dnd_icon.clone(), dnd_icon: self.dnd_icon.clone(),
logger: self.logger.clone(), logger: self.logger.clone(),
}); });
let restart_id = self.notifier.register(DrmRendererSessionListener { renderer: renderer.clone(), loop_handle: self.loop_handle.clone() }); let restart_id = self.notifier.register(DrmRendererSessionListener {
device.set_handler(DrmHandlerImpl { renderer, loop_handle: self.loop_handle.clone() }); renderer: renderer.clone(),
loop_handle: self.loop_handle.clone(),
});
device.set_handler(DrmHandlerImpl {
renderer,
loop_handle: self.loop_handle.clone(),
});
let device_session_id = self.notifier.register(device.observer()); let device_session_id = self.notifier.register(device.observer());
let dev_id = device.device_id(); let dev_id = device.device_id();
@ -549,11 +558,11 @@ impl<Data: 'static> SessionObserver for DrmRendererSessionListener<Data> {
// we want to be called, after all session handling is done (TODO this is not so nice) // we want to be called, after all session handling is done (TODO this is not so nice)
let renderer = self.renderer.clone(); let renderer = self.renderer.clone();
let handle = self.loop_handle.clone(); let handle = self.loop_handle.clone();
self.loop_handle.insert_idle(move |_| renderer.render_all(Some(&handle))); self.loop_handle
.insert_idle(move |_| renderer.render_all(Some(&handle)));
} }
} }
pub struct DrmRenderer { pub struct DrmRenderer {
compositor_token: CompositorToken<Roles>, compositor_token: CompositorToken<Roles>,
backends: Rc<RefCell<HashMap<crtc::Handle, Rc<GliumDrawer<RenderSurface>>>>>, backends: Rc<RefCell<HashMap<crtc::Handle, Rc<GliumDrawer<RenderSurface>>>>>,
@ -570,7 +579,12 @@ impl DrmRenderer {
self.clone().render(*crtc, None, evt_handle); self.clone().render(*crtc, None, evt_handle);
} }
} }
fn render<Data: 'static>(self: Rc<Self>, crtc: crtc::Handle, timer: Option<TimerHandle<(std::rc::Weak<DrmRenderer>, crtc::Handle)>>, evt_handle: Option<&LoopHandle<Data>>) { fn render<Data: 'static>(
self: Rc<Self>,
crtc: crtc::Handle,
timer: Option<TimerHandle<(std::rc::Weak<DrmRenderer>, crtc::Handle)>>,
evt_handle: Option<&LoopHandle<Data>>,
) {
if let Some(drawer) = self.backends.borrow().get(&crtc) { if let Some(drawer) = self.backends.borrow().get(&crtc) {
{ {
let (x, y) = *self.pointer_location.borrow(); let (x, y) = *self.pointer_location.borrow();
@ -625,32 +639,50 @@ impl DrmRenderer {
error!(self.logger, "Error during rendering: {:?}", err); error!(self.logger, "Error during rendering: {:?}", err);
let reschedule = match err { let reschedule = match err {
SwapBuffersError::AlreadySwapped => false, SwapBuffersError::AlreadySwapped => false,
SwapBuffersError::TemporaryFailure(err) => match err.downcast_ref::<smithay::backend::drm::common::Error>() { SwapBuffersError::TemporaryFailure(err) => {
match err.downcast_ref::<smithay::backend::drm::common::Error>() {
Some(&smithay::backend::drm::common::Error::DeviceInactive) => false, Some(&smithay::backend::drm::common::Error::DeviceInactive) => false,
Some(&smithay::backend::drm::common::Error::Access { ref source, .. }) if match source.get_ref() { Some(&smithay::backend::drm::common::Error::Access { ref source, .. })
if match source.get_ref() {
drm::SystemError::PermissionDenied => true, drm::SystemError::PermissionDenied => true,
_ => false, _ => false,
} => false, } =>
_ => true {
}, false
}
_ => true,
}
}
SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err), SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err),
}; };
if reschedule { if reschedule {
match (timer, evt_handle) { match (timer, evt_handle) {
(Some(handle), _) => { (Some(handle), _) => {
let _ = handle.add_timeout(Duration::from_millis(1000 /*a seconds*/ / 60 /*refresh rate*/), (Rc::downgrade(&self), crtc)); let _ = handle.add_timeout(
}, Duration::from_millis(1000 /*a seconds*/ / 60 /*refresh rate*/),
(Rc::downgrade(&self), crtc),
);
}
(None, Some(evt_handle)) => { (None, Some(evt_handle)) => {
let timer = Timer::new().unwrap(); let timer = Timer::new().unwrap();
let handle = timer.handle(); let handle = timer.handle();
let _ = handle.add_timeout(Duration::from_millis(1000 /*a seconds*/ / 60 /*refresh rate*/), (Rc::downgrade(&self), crtc)); let _ = handle.add_timeout(
evt_handle.insert_source(timer, |(renderer, crtc), handle, _data| { Duration::from_millis(1000 /*a seconds*/ / 60 /*refresh rate*/),
(Rc::downgrade(&self), crtc),
);
evt_handle
.insert_source(timer, |(renderer, crtc), handle, _data| {
if let Some(renderer) = renderer.upgrade() { if let Some(renderer) = renderer.upgrade() {
renderer.render(crtc, Some(handle.clone()), Option::<&LoopHandle<Data>>::None); renderer.render(
crtc,
Some(handle.clone()),
Option::<&LoopHandle<Data>>::None,
);
}
})
.unwrap();
} }
}).unwrap();
},
_ => unreachable!(), _ => unreachable!(),
} }
} }

View File

@ -168,7 +168,7 @@ impl<A: AsRawFd + 'static> AtomicDrmDeviceObserver<A> {
// recreate property blob // recreate property blob
let mode = { let mode = {
let pending = surface.pending.read().unwrap(); let pending = surface.pending.read().unwrap();
pending.mode.clone() pending.mode
}; };
surface.use_mode(mode)?; surface.use_mode(mode)?;

View File

@ -535,7 +535,8 @@ impl<A: AsRawFd + 'static> RawSurface for AtomicDrmSurfaceInternal<A> {
}; };
debug!(self.logger, "Setting screen: {:?}", req); debug!(self.logger, "Setting screen: {:?}", req);
let result = self.atomic_commit( let result = self
.atomic_commit(
&[ &[
AtomicCommitFlags::PageFlipEvent, AtomicCommitFlags::PageFlipEvent,
AtomicCommitFlags::AllowModeset, AtomicCommitFlags::AllowModeset,
@ -617,13 +618,13 @@ impl<A: AsRawFd + 'static> CursorBackend for AtomicDrmSurfaceInternal<A> {
} }
self.cursor.framebuffer.set(Some( self.cursor.framebuffer.set(Some(
self.add_planar_framebuffer(buffer, &[0; 4], 0).compat().map_err( self.add_planar_framebuffer(buffer, &[0; 4], 0)
|source| Error::Access { .compat()
.map_err(|source| Error::Access {
errmsg: "Failed to import cursor", errmsg: "Failed to import cursor",
dev: self.dev_path(), dev: self.dev_path(),
source, source,
}, })?,
)?,
)); ));
self.cursor.hotspot.set(hotspot); self.cursor.hotspot.set(hotspot);
@ -858,7 +859,7 @@ impl<A: AsRawFd + 'static> AtomicDrmSurfaceInternal<A> {
self.plane_prop_handle(planes.cursor, "FB_ID")?, self.plane_prop_handle(planes.cursor, "FB_ID")?,
property::Value::Framebuffer(Some(fb)), property::Value::Framebuffer(Some(fb)),
); );
}, }
Err(err) => { Err(err) => {
warn!(self.logger, "Cursor FB invalid: {}. Skipping.", err); warn!(self.logger, "Cursor FB invalid: {}. Skipping.", err);
self.cursor.framebuffer.set(None); self.cursor.framebuffer.set(None);

View File

@ -76,8 +76,9 @@ impl Into<SwapBuffersError> for Error {
fn into(self) -> SwapBuffersError { fn into(self) -> SwapBuffersError {
match self { match self {
x @ Error::DeviceInactive => SwapBuffersError::TemporaryFailure(Box::new(x)), x @ Error::DeviceInactive => SwapBuffersError::TemporaryFailure(Box::new(x)),
Error::Access { errmsg, dev, source, .. } Error::Access {
if match source.get_ref() { errmsg, dev, source, ..
} if match source.get_ref() {
drm::SystemError::PermissionDenied => true, drm::SystemError::PermissionDenied => true,
drm::SystemError::Unknown { drm::SystemError::Unknown {
errno: nix::errno::Errno::EBUSY, errno: nix::errno::Errno::EBUSY,
@ -89,7 +90,7 @@ impl Into<SwapBuffersError> for Error {
} => } =>
{ {
SwapBuffersError::TemporaryFailure(Box::new(Error::Access { errmsg, dev, source })) SwapBuffersError::TemporaryFailure(Box::new(Error::Access { errmsg, dev, source }))
}, }
x => SwapBuffersError::ContextLost(Box::new(x)), x => SwapBuffersError::ContextLost(Box::new(x)),
} }
} }

View File

@ -47,6 +47,7 @@ pub enum Error<U: std::error::Error + std::fmt::Debug + std::fmt::Display + 'sta
} }
type Arguments = (crtc::Handle, Mode, Vec<connector::Handle>); type Arguments = (crtc::Handle, Mode, Vec<connector::Handle>);
type BackendRef<D> = Weak<EglSurfaceInternal<<D as Device>::Surface>>;
/// Representation of an egl device to create egl rendering surfaces /// Representation of an egl device to create egl rendering surfaces
pub struct EglDevice<B, D> pub struct EglDevice<B, D>
@ -61,7 +62,7 @@ where
logger: ::slog::Logger, logger: ::slog::Logger,
default_attributes: GlAttributes, default_attributes: GlAttributes,
default_requirements: PixelFormatRequirements, default_requirements: PixelFormatRequirements,
backends: Rc<RefCell<HashMap<crtc::Handle, Weak<EglSurfaceInternal<<D as Device>::Surface>>>>>, backends: Rc<RefCell<HashMap<crtc::Handle, BackendRef<D>>>>,
} }
impl<B, D> AsRawFd for EglDevice<B, D> impl<B, D> AsRawFd for EglDevice<B, D>

View File

@ -11,7 +11,10 @@ use std::rc::{Rc, Weak};
use super::{EglDevice, EglSurfaceInternal}; use super::{EglDevice, EglSurfaceInternal};
use crate::backend::drm::{Device, Surface}; use crate::backend::drm::{Device, Surface};
use crate::backend::egl::{ffi, native::{Backend, NativeDisplay, NativeSurface}}; use crate::backend::egl::{
ffi,
native::{Backend, NativeDisplay, NativeSurface},
};
use crate::backend::session::{AsSessionObserver, SessionObserver}; use crate::backend::session::{AsSessionObserver, SessionObserver};
/// [`SessionObserver`](SessionObserver) /// [`SessionObserver`](SessionObserver)
@ -55,7 +58,9 @@ impl<S: SessionObserver + 'static, N: NativeSurface + Surface> SessionObserver f
if let Some(backend) = backend.upgrade() { if let Some(backend) = backend.upgrade() {
let old_surface = backend.surface.surface.replace(std::ptr::null()); let old_surface = backend.surface.surface.replace(std::ptr::null());
if !old_surface.is_null() { if !old_surface.is_null() {
unsafe { ffi::egl::DestroySurface(**backend.surface.display, old_surface as *const _); } unsafe {
ffi::egl::DestroySurface(**backend.surface.display, old_surface as *const _);
}
} }
} }
} }

View File

@ -93,7 +93,7 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
self.recreated.set(false); self.recreated.set(false);
self.current_frame_buffer.set(Some(fb)); self.current_frame_buffer.set(Some(fb));
Ok(()) Ok(())
}, }
Err(err) => { Err(err) => {
self.unlock_buffer(); self.unlock_buffer();
Err(err) Err(err)

View File

@ -485,15 +485,17 @@ impl EGLBufferReader {
buffer: WlBuffer, buffer: WlBuffer,
) -> ::std::result::Result<EGLImages, BufferAccessError> { ) -> ::std::result::Result<EGLImages, BufferAccessError> {
let mut format: i32 = 0; let mut format: i32 = 0;
if wrap_egl_call(|| unsafe { let query = wrap_egl_call(|| unsafe {
ffi::egl::QueryWaylandBufferWL( ffi::egl::QueryWaylandBufferWL(
**self.display, **self.display,
buffer.as_ref().c_ptr() as _, buffer.as_ref().c_ptr() as _,
ffi::egl::EGL_TEXTURE_FORMAT, ffi::egl::EGL_TEXTURE_FORMAT,
&mut format, &mut format,
) )
}).map_err(|source| BufferAccessError::NotManaged(buffer.clone(), source))? == ffi::egl::FALSE { })
return Err(BufferAccessError::NotManaged(buffer.clone(), EGLError::BadParameter)); .map_err(|source| BufferAccessError::NotManaged(buffer.clone(), source))?;
if query == ffi::egl::FALSE {
return Err(BufferAccessError::NotManaged(buffer, EGLError::BadParameter));
} }
let format = match format { let format = match format {

View File

@ -90,7 +90,9 @@ impl<N: native::NativeSurface> EGLSurface<N> {
wrap_egl_call(|| unsafe { ffi::egl::SwapBuffers(**self.display, surface as *const _) }) wrap_egl_call(|| unsafe { ffi::egl::SwapBuffers(**self.display, surface as *const _) })
.map_err(SwapBuffersError::EGLSwapBuffers) .map_err(SwapBuffersError::EGLSwapBuffers)
.and_then(|_| self.native.swap_buffers().map_err(SwapBuffersError::Underlying)) .and_then(|_| self.native.swap_buffers().map_err(SwapBuffersError::Underlying))
} else { Err(SwapBuffersError::EGLSwapBuffers(EGLError::BadSurface)) }; } else {
Err(SwapBuffersError::EGLSwapBuffers(EGLError::BadSurface))
};
// workaround for missing `PartialEq` impl // workaround for missing `PartialEq` impl
let is_bad_surface = if let Err(SwapBuffersError::EGLSwapBuffers(EGLError::BadSurface)) = result { let is_bad_surface = if let Err(SwapBuffersError::EGLSwapBuffers(EGLError::BadSurface)) = result {