lint: fmt & clippy
This commit is contained in:
parent
20b373470f
commit
f1c40f7306
|
@ -16,7 +16,11 @@ use smithay::backend::egl::display::EGLBufferReader;
|
|||
use smithay::{
|
||||
backend::{
|
||||
egl::{BufferAccessError, EGLImages, Format},
|
||||
graphics::{gl::GLGraphicsBackend, glium::{GliumGraphicsBackend, Frame}, SwapBuffersError},
|
||||
graphics::{
|
||||
gl::GLGraphicsBackend,
|
||||
glium::{Frame, GliumGraphicsBackend},
|
||||
SwapBuffersError,
|
||||
},
|
||||
},
|
||||
reexports::{
|
||||
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();
|
||||
frame.clear_color(0.8, 0.8, 0.9, 1.0);
|
||||
if let Err(err) = frame.set_finish() {
|
||||
match err {
|
||||
SwapBuffersError::AlreadySwapped => {},
|
||||
SwapBuffersError::AlreadySwapped => {}
|
||||
SwapBuffersError::TemporaryFailure(err) => {
|
||||
// TODO dont reschedule after 3(?) retries
|
||||
error!(
|
||||
renderer.log,
|
||||
"Failed to submit page_flip: {}", err
|
||||
);
|
||||
error!(renderer.log, "Failed to submit page_flip: {}", err);
|
||||
let handle = evt_handle.clone();
|
||||
evt_handle.insert_idle(move |_| schedule_initial_render(renderer, &handle));
|
||||
},
|
||||
}
|
||||
SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,14 @@ use smithay::{
|
|||
timer::{Timer, TimerHandle},
|
||||
EventLoop, LoopHandle, Source,
|
||||
},
|
||||
drm::{self, control::{
|
||||
connector::{Info as ConnectorInfo, State as ConnectorState},
|
||||
crtc,
|
||||
encoder::Info as EncoderInfo,
|
||||
}},
|
||||
drm::{
|
||||
self,
|
||||
control::{
|
||||
connector::{Info as ConnectorInfo, State as ConnectorState},
|
||||
crtc,
|
||||
encoder::Info as EncoderInfo,
|
||||
},
|
||||
},
|
||||
image::{ImageBuffer, Rgba},
|
||||
input::Libinput,
|
||||
nix::{fcntl::OFlag, sys::stat::dev_t},
|
||||
|
@ -61,7 +64,7 @@ use smithay::{
|
|||
};
|
||||
|
||||
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::state::AnvilState;
|
||||
|
||||
|
@ -431,8 +434,14 @@ impl<S: SessionNotifier, Data: 'static> UdevHandlerImpl<S, Data> {
|
|||
dnd_icon: self.dnd_icon.clone(),
|
||||
logger: self.logger.clone(),
|
||||
});
|
||||
let restart_id = self.notifier.register(DrmRendererSessionListener { renderer: renderer.clone(), loop_handle: self.loop_handle.clone() });
|
||||
device.set_handler(DrmHandlerImpl { renderer, loop_handle: self.loop_handle.clone() });
|
||||
let restart_id = self.notifier.register(DrmRendererSessionListener {
|
||||
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 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)
|
||||
let renderer = self.renderer.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 {
|
||||
compositor_token: CompositorToken<Roles>,
|
||||
backends: Rc<RefCell<HashMap<crtc::Handle, Rc<GliumDrawer<RenderSurface>>>>>,
|
||||
|
@ -570,7 +579,12 @@ impl DrmRenderer {
|
|||
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) {
|
||||
{
|
||||
let (x, y) = *self.pointer_location.borrow();
|
||||
|
@ -625,32 +639,50 @@ impl DrmRenderer {
|
|||
error!(self.logger, "Error during rendering: {:?}", err);
|
||||
let reschedule = match err {
|
||||
SwapBuffersError::AlreadySwapped => false,
|
||||
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::Access { ref source, .. }) if match source.get_ref() {
|
||||
drm::SystemError::PermissionDenied => true,
|
||||
_ => false,
|
||||
} => false,
|
||||
_ => true
|
||||
},
|
||||
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::Access { ref source, .. })
|
||||
if match source.get_ref() {
|
||||
drm::SystemError::PermissionDenied => true,
|
||||
_ => false,
|
||||
} =>
|
||||
{
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err),
|
||||
};
|
||||
|
||||
if reschedule {
|
||||
match (timer, evt_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)) => {
|
||||
let timer = Timer::new().unwrap();
|
||||
let handle = timer.handle();
|
||||
let _ = handle.add_timeout(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() {
|
||||
renderer.render(crtc, Some(handle.clone()), Option::<&LoopHandle<Data>>::None);
|
||||
}
|
||||
}).unwrap();
|
||||
},
|
||||
let _ = handle.add_timeout(
|
||||
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() {
|
||||
renderer.render(
|
||||
crtc,
|
||||
Some(handle.clone()),
|
||||
Option::<&LoopHandle<Data>>::None,
|
||||
);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,13 +168,13 @@ impl<A: AsRawFd + 'static> AtomicDrmDeviceObserver<A> {
|
|||
// recreate property blob
|
||||
let mode = {
|
||||
let pending = surface.pending.read().unwrap();
|
||||
pending.mode.clone()
|
||||
pending.mode
|
||||
};
|
||||
surface.use_mode(mode)?;
|
||||
|
||||
// drop cursor state
|
||||
surface.cursor.position.set(None);
|
||||
surface.cursor.hotspot.set((0,0));
|
||||
surface.cursor.hotspot.set((0, 0));
|
||||
surface.cursor.framebuffer.set(None);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -535,20 +535,21 @@ impl<A: AsRawFd + 'static> RawSurface for AtomicDrmSurfaceInternal<A> {
|
|||
};
|
||||
|
||||
debug!(self.logger, "Setting screen: {:?}", req);
|
||||
let result = self.atomic_commit(
|
||||
&[
|
||||
AtomicCommitFlags::PageFlipEvent,
|
||||
AtomicCommitFlags::AllowModeset,
|
||||
AtomicCommitFlags::Nonblock,
|
||||
],
|
||||
req,
|
||||
)
|
||||
.compat()
|
||||
.map_err(|source| Error::Access {
|
||||
errmsg: "Error setting crtc",
|
||||
dev: self.dev_path(),
|
||||
source,
|
||||
});
|
||||
let result = self
|
||||
.atomic_commit(
|
||||
&[
|
||||
AtomicCommitFlags::PageFlipEvent,
|
||||
AtomicCommitFlags::AllowModeset,
|
||||
AtomicCommitFlags::Nonblock,
|
||||
],
|
||||
req,
|
||||
)
|
||||
.compat()
|
||||
.map_err(|source| Error::Access {
|
||||
errmsg: "Error setting crtc",
|
||||
dev: self.dev_path(),
|
||||
source,
|
||||
});
|
||||
|
||||
if result.is_ok() {
|
||||
*current = pending.clone();
|
||||
|
@ -617,13 +618,13 @@ impl<A: AsRawFd + 'static> CursorBackend for AtomicDrmSurfaceInternal<A> {
|
|||
}
|
||||
|
||||
self.cursor.framebuffer.set(Some(
|
||||
self.add_planar_framebuffer(buffer, &[0; 4], 0).compat().map_err(
|
||||
|source| Error::Access {
|
||||
self.add_planar_framebuffer(buffer, &[0; 4], 0)
|
||||
.compat()
|
||||
.map_err(|source| Error::Access {
|
||||
errmsg: "Failed to import cursor",
|
||||
dev: self.dev_path(),
|
||||
source,
|
||||
},
|
||||
)?,
|
||||
})?,
|
||||
));
|
||||
|
||||
self.cursor.hotspot.set(hotspot);
|
||||
|
@ -858,7 +859,7 @@ impl<A: AsRawFd + 'static> AtomicDrmSurfaceInternal<A> {
|
|||
self.plane_prop_handle(planes.cursor, "FB_ID")?,
|
||||
property::Value::Framebuffer(Some(fb)),
|
||||
);
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
warn!(self.logger, "Cursor FB invalid: {}. Skipping.", err);
|
||||
self.cursor.framebuffer.set(None);
|
||||
|
|
|
@ -76,20 +76,21 @@ impl Into<SwapBuffersError> for Error {
|
|||
fn into(self) -> SwapBuffersError {
|
||||
match self {
|
||||
x @ Error::DeviceInactive => SwapBuffersError::TemporaryFailure(Box::new(x)),
|
||||
Error::Access { errmsg, dev, source, .. }
|
||||
if match source.get_ref() {
|
||||
drm::SystemError::PermissionDenied => true,
|
||||
drm::SystemError::Unknown {
|
||||
errno: nix::errno::Errno::EBUSY,
|
||||
} => true,
|
||||
drm::SystemError::Unknown {
|
||||
errno: nix::errno::Errno::EINTR,
|
||||
} => true,
|
||||
_ => false,
|
||||
} =>
|
||||
Error::Access {
|
||||
errmsg, dev, source, ..
|
||||
} if match source.get_ref() {
|
||||
drm::SystemError::PermissionDenied => true,
|
||||
drm::SystemError::Unknown {
|
||||
errno: nix::errno::Errno::EBUSY,
|
||||
} => true,
|
||||
drm::SystemError::Unknown {
|
||||
errno: nix::errno::Errno::EINTR,
|
||||
} => true,
|
||||
_ => false,
|
||||
} =>
|
||||
{
|
||||
SwapBuffersError::TemporaryFailure(Box::new(Error::Access { errmsg, dev, source }))
|
||||
},
|
||||
}
|
||||
x => SwapBuffersError::ContextLost(Box::new(x)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 BackendRef<D> = Weak<EglSurfaceInternal<<D as Device>::Surface>>;
|
||||
|
||||
/// Representation of an egl device to create egl rendering surfaces
|
||||
pub struct EglDevice<B, D>
|
||||
|
@ -61,7 +62,7 @@ where
|
|||
logger: ::slog::Logger,
|
||||
default_attributes: GlAttributes,
|
||||
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>
|
||||
|
|
|
@ -11,7 +11,10 @@ use std::rc::{Rc, Weak};
|
|||
|
||||
use super::{EglDevice, EglSurfaceInternal};
|
||||
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};
|
||||
|
||||
/// [`SessionObserver`](SessionObserver)
|
||||
|
@ -55,7 +58,9 @@ impl<S: SessionObserver + 'static, N: NativeSurface + Surface> SessionObserver f
|
|||
if let Some(backend) = backend.upgrade() {
|
||||
let old_surface = backend.surface.surface.replace(std::ptr::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 _);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
|
|||
self.recreated.set(false);
|
||||
self.current_frame_buffer.set(Some(fb));
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
self.unlock_buffer();
|
||||
Err(err)
|
||||
|
|
|
@ -485,15 +485,17 @@ impl EGLBufferReader {
|
|||
buffer: WlBuffer,
|
||||
) -> ::std::result::Result<EGLImages, BufferAccessError> {
|
||||
let mut format: i32 = 0;
|
||||
if wrap_egl_call(|| unsafe {
|
||||
let query = wrap_egl_call(|| unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
ffi::egl::EGL_TEXTURE_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 {
|
||||
|
|
|
@ -90,7 +90,9 @@ impl<N: native::NativeSurface> EGLSurface<N> {
|
|||
wrap_egl_call(|| unsafe { ffi::egl::SwapBuffers(**self.display, surface as *const _) })
|
||||
.map_err(SwapBuffersError::EGLSwapBuffers)
|
||||
.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
|
||||
let is_bad_surface = if let Err(SwapBuffersError::EGLSwapBuffers(EGLError::BadSurface)) = result {
|
||||
|
|
Loading…
Reference in New Issue