apply cargo fmt and clippy

This commit is contained in:
i509VCB 2021-11-23 10:55:49 -06:00 committed by Victor Brekenfeld
parent 86716f9c9f
commit 5506c7e1c5
2 changed files with 20 additions and 20 deletions

View File

@ -44,7 +44,8 @@ impl EGLDevice {
// Passing 0 for max devices and a null-pointer for devices is safe because we indicate we only // Passing 0 for max devices and a null-pointer for devices is safe because we indicate we only
// want the number of devices. // want the number of devices.
if unsafe { ffi::egl::QueryDevicesEXT(0, ptr::null_mut(), amount.as_mut_ptr()) } == ffi::egl::FALSE if unsafe { ffi::egl::QueryDevicesEXT(0, ptr::null_mut(), amount.as_mut_ptr()) }
== ffi::egl::FALSE
{ {
0 0
} else { } else {
@ -63,7 +64,8 @@ impl EGLDevice {
// - Vector used as pointer is correct size. // - Vector used as pointer is correct size.
// - Device amount will accommodate all available devices because we have checked the size earlier. // - Device amount will accommodate all available devices because we have checked the size earlier.
ffi::egl::QueryDevicesEXT(device_amount, devices.as_mut_ptr(), &mut device_amount) ffi::egl::QueryDevicesEXT(device_amount, devices.as_mut_ptr(), &mut device_amount)
}).map_err(Error::QueryDevices)?; })
.map_err(Error::QueryDevices)?;
// Set the length of the vec so that rust does not think it is still empty. // Set the length of the vec so that rust does not think it is still empty.

View File

@ -37,8 +37,8 @@
//! // Initialize EGL to retrieve the support modifier list //! // Initialize EGL to retrieve the support modifier list
//! let egl = EGLDisplay::new(&device, logger.clone()).expect("Failed to create EGLDisplay"); //! let egl = EGLDisplay::new(&device, logger.clone()).expect("Failed to create EGLDisplay");
//! let context = EGLContext::new(&egl, logger).expect("Failed to create EGLContext"); //! let context = EGLContext::new(&egl, logger).expect("Failed to create EGLContext");
//! let modifiers = context.dmabuf_render_formats().iter().map(|format| format.modifier).collect::<HashSet<_>>(); //! let modifiers = context.dmabuf_render_formats().iter().map(|format| format.modifier).collect::<HashSet<_>>();
//! //!
//! // Finally create the X11 surface, you will use this to obtain buffers that will be presented to the //! // Finally create the X11 surface, you will use this to obtain buffers that will be presented to the
//! // window. //! // window.
//! let surface = X11Surface::new(&mut backend, device, modifiers.into_iter()); //! let surface = X11Surface::new(&mut backend, device, modifiers.into_iter());
@ -325,13 +325,13 @@ impl X11Backend {
// We cannot fallback on the egl_init method, because there is no way for us to authenticate a primary node. // We cannot fallback on the egl_init method, because there is no way for us to authenticate a primary node.
// dri3 does not work for closed-source drivers, but *may* give us a authenticated fd as a fallback. // dri3 does not work for closed-source drivers, but *may* give us a authenticated fd as a fallback.
// As a result we try to use egl for a cleaner, better supported approach at first and only if that fails use dri3. // As a result we try to use egl for a cleaner, better supported approach at first and only if that fails use dri3.
egl_init(&self).or_else(|err| { egl_init(self).or_else(|err| {
slog::warn!( slog::warn!(
&self.log, &self.log,
"Failed to init X11 surface via egl, falling back to dri3: {}", "Failed to init X11 surface via egl, falling back to dri3: {}",
err err
); );
dri3_init(&self) dri3_init(self)
}) })
} }
} }
@ -412,19 +412,17 @@ fn dri3_init(backend: &X11Backend) -> Result<DrmNode, X11Error> {
.map_err(AllocateBuffersError::from)?; .map_err(AllocateBuffersError::from)?;
let drm_node = DrmNode::from_fd(drm_device_fd).map_err(Into::<AllocateBuffersError>::into)?; let drm_node = DrmNode::from_fd(drm_device_fd).map_err(Into::<AllocateBuffersError>::into)?;
if drm_node.ty() != NodeType::Render { if drm_node.ty() != NodeType::Render && drm_node.has_render() {
if drm_node.has_render() { // Try to get the render node.
// Try to get the render node. if let Some(path) = drm_node.dev_path_with_type(NodeType::Render) {
if let Some(path) = drm_node.dev_path_with_type(NodeType::Render) { return Ok(fcntl::open(&path, OFlag::O_RDWR | OFlag::O_CLOEXEC, Mode::empty())
return Ok(fcntl::open(&path, OFlag::O_RDWR | OFlag::O_CLOEXEC, Mode::empty()) .map_err(Into::<std::io::Error>::into)
.map_err(Into::<std::io::Error>::into) .map_err(CreateDrmNodeError::Io)
.map_err(CreateDrmNodeError::Io) .and_then(DrmNode::from_fd)
.and_then(DrmNode::from_fd) .unwrap_or_else(|err| {
.unwrap_or_else(|err| { slog::warn!(&backend.log, "Could not create render node from existing DRM node ({}), falling back to primary node", err);
slog::warn!(&backend.log, "Could not create render node from existing DRM node ({}), falling back to primary node", err); drm_node
drm_node }));
}));
}
} }
} }
@ -598,7 +596,7 @@ impl Drop for Present<'_> {
match surface.current.userdata().map(Option::unwrap) { match surface.current.userdata().map(Option::unwrap) {
Ok(dmabuf) => { Ok(dmabuf) => {
if let Ok(pixmap) = PixmapWrapper::with_dmabuf(&*connection, &surface.window, &dmabuf) { if let Ok(pixmap) = PixmapWrapper::with_dmabuf(&*connection, &surface.window, dmabuf) {
// Now present the current buffer // Now present the current buffer
let _ = pixmap.present(&*connection, &surface.window); let _ = pixmap.present(&*connection, &surface.window);
} }