cargo fmt

This commit is contained in:
Victor Berger 2021-06-09 22:12:35 +02:00 committed by Victor Berger
parent 671e2053e9
commit c630bd9086
10 changed files with 158 additions and 128 deletions

View File

@ -3,9 +3,11 @@
use std::cell::RefCell;
use slog::Logger;
#[cfg(feature = "egl")]
use smithay::backend::{egl::display::EGLBufferReader, renderer::ImportEgl};
use smithay::{
backend::{
renderer::{Frame, Renderer, Texture, Transform, ImportShm, ImportDma, BufferType, buffer_type},
renderer::{buffer_type, BufferType, Frame, ImportDma, ImportShm, Renderer, Texture, Transform},
SwapBuffersError,
},
reexports::wayland_server::protocol::{wl_buffer, wl_surface},
@ -16,11 +18,6 @@ use smithay::{
seat::CursorImageRole,
},
};
#[cfg(feature = "egl")]
use smithay::backend::{
egl::display::EGLBufferReader,
renderer::ImportEgl,
};
// hacky...
#[cfg(not(feature = "egl"))]
pub trait ImportEgl {}
@ -46,8 +43,7 @@ pub fn draw_cursor<R, E, F, T>(
renderer: &mut R,
frame: &mut F,
surface: &wl_surface::WlSurface,
#[cfg(feature = "egl")]
egl_buffer_reader: Option<&EGLBufferReader>,
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
(x, y): (i32, i32),
token: MyCompositorToken,
log: &Logger,
@ -84,8 +80,7 @@ fn draw_surface_tree<R, E, F, T>(
renderer: &mut R,
frame: &mut F,
root: &wl_surface::WlSurface,
#[cfg(feature = "egl")]
egl_buffer_reader: Option<&EGLBufferReader>,
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
location: (i32, i32),
compositor_token: MyCompositorToken,
log: &Logger,
@ -110,7 +105,7 @@ where
let texture = match buffer_type(
&buffer,
#[cfg(feature = "egl")]
egl_buffer_reader
egl_buffer_reader,
) {
Some(BufferType::Shm) => {
let damage = attributes
@ -126,10 +121,15 @@ where
buffer.release();
// don't return the buffer as it is already released
Some((result, None))
},
}
#[cfg(feature = "egl")]
Some(BufferType::Egl) => Some((renderer.import_egl_buffer(&buffer, egl_buffer_reader.unwrap()), Some(buffer))),
Some(BufferType::Dma) => Some((renderer.import_dma_buffer(&buffer), Some(buffer))),
Some(BufferType::Egl) => Some((
renderer.import_egl_buffer(&buffer, egl_buffer_reader.unwrap()),
Some(buffer),
)),
Some(BufferType::Dma) => {
Some((renderer.import_dma_buffer(&buffer), Some(buffer)))
}
_ => {
error!(log, "Unknown buffer format for: {:?}", buffer);
buffer.release();
@ -147,8 +147,8 @@ where
if let Some(buffer) = buffer {
buffer.release();
}
},
None => {},
}
None => {}
};
}
}
@ -204,8 +204,7 @@ where
pub fn draw_windows<R, E, F, T>(
renderer: &mut R,
frame: &mut F,
#[cfg(feature = "egl")]
egl_buffer_reader: Option<&EGLBufferReader>,
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
window_map: &MyWindowMap,
output_rect: Option<Rectangle>,
compositor_token: MyCompositorToken,
@ -252,8 +251,7 @@ pub fn draw_dnd_icon<R, E, F, T>(
renderer: &mut R,
frame: &mut F,
surface: &wl_surface::WlSurface,
#[cfg(feature = "egl")]
egl_buffer_reader: Option<&EGLBufferReader>,
#[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>,
(x, y): (i32, i32),
token: MyCompositorToken,
log: &::slog::Logger,
@ -278,6 +276,6 @@ where
egl_buffer_reader,
(x, y),
token,
log
log,
)
}

View File

@ -1,10 +1,10 @@
use std::{process::Command, sync::atomic::Ordering};
use crate::AnvilState;
#[cfg(feature = "udev")]
use crate::udev::UdevData;
#[cfg(feature = "winit")]
use crate::winit::WinitData;
use crate::AnvilState;
use smithay::{
backend::input::{

View File

@ -12,6 +12,11 @@ use std::{
use image::{ImageBuffer, Rgba};
use slog::Logger;
#[cfg(feature = "egl")]
use smithay::{
backend::{drm::DevPath, egl::display::EGLBufferReader, renderer::ImportDma, udev::primary_gpu},
wayland::dmabuf::init_dmabuf_global,
};
use smithay::{
backend::{
drm::{DrmDevice, DrmError, DrmEvent, DrmRenderSurface},
@ -19,7 +24,7 @@ use smithay::{
libinput::{LibinputInputBackend, LibinputSessionInterface},
renderer::{
gles2::{Gles2Renderer, Gles2Texture},
Frame, Renderer, Transform
Frame, Renderer, Transform,
},
session::{auto::AutoSession, Session, Signal as SessionSignal},
udev::{UdevBackend, UdevEvent},
@ -55,11 +60,6 @@ use smithay::{
seat::CursorImageStatus,
},
};
#[cfg(feature = "egl")]
use smithay::{
backend::{drm::DevPath, egl::display::EGLBufferReader, udev::primary_gpu, renderer::ImportDma},
wayland::dmabuf::init_dmabuf_global,
};
use crate::drawing::*;
use crate::shell::{MyWindowMap, Roles};
@ -195,7 +195,10 @@ pub fn run_udev(
}
}
init_dmabuf_global(&mut *display.borrow_mut(), formats, |buffer, mut ddata| {
init_dmabuf_global(
&mut *display.borrow_mut(),
formats,
|buffer, mut ddata| {
let anvil_state = ddata.get::<AnvilState<UdevData>>().unwrap();
for backend_data in anvil_state.backend_data.backends.values() {
let surfaces = backend_data.surfaces.borrow_mut();
@ -206,7 +209,9 @@ pub fn run_udev(
}
}
false
}, log.clone());
},
log.clone(),
);
}
let udev_event_source = event_loop

View File

@ -1,5 +1,7 @@
use std::{cell::RefCell, rc::Rc, sync::atomic::Ordering, time::Duration};
#[cfg(feature = "egl")]
use smithay::{backend::renderer::ImportDma, wayland::dmabuf::init_dmabuf_global};
use smithay::{
backend::{input::InputBackend, renderer::Frame, winit, SwapBuffersError},
reexports::{
@ -11,11 +13,6 @@ use smithay::{
seat::CursorImageStatus,
},
};
#[cfg(feature = "egl")]
use smithay::{
backend::renderer::ImportDma,
wayland::dmabuf::init_dmabuf_global,
};
use slog::Logger;
@ -45,11 +42,19 @@ pub fn run_winit(
#[cfg(feature = "egl")]
if reader.is_some() {
info!(log, "EGL hardware-acceleration enabled");
let dmabuf_formats = renderer.borrow_mut().renderer().dmabuf_formats().cloned().collect::<Vec<_>>();
let dmabuf_formats = renderer
.borrow_mut()
.renderer()
.dmabuf_formats()
.cloned()
.collect::<Vec<_>>();
let renderer = renderer.clone();
init_dmabuf_global(&mut *display.borrow_mut(), dmabuf_formats, move |buffer, _| {
renderer.borrow_mut().renderer().import_dmabuf(buffer).is_ok()
}, log.clone());
init_dmabuf_global(
&mut *display.borrow_mut(),
dmabuf_formats,
move |buffer, _| renderer.borrow_mut().renderer().import_dmabuf(buffer).is_ok(),
log.clone(),
);
};
let (w, h): (u32, u32) = renderer.borrow().window_size().physical_size.into();

View File

@ -96,15 +96,15 @@ fn main() {
.supported_formats(surface.plane())
.expect("Unable to readout formats for surface")
.iter()
.filter_map(|format| if format.code == Fourcc::Argb8888 { Some(format.modifier) } else { None })
.filter_map(|format| {
if format.code == Fourcc::Argb8888 {
Some(format.modifier)
} else {
None
}
})
.collect::<Vec<_>>();
let mut swapchain = Swapchain::new(
allocator,
w.into(),
h.into(),
Fourcc::Argb8888,
mods,
);
let mut swapchain = Swapchain::new(allocator, w.into(), h.into(), Fourcc::Argb8888, mods);
let first_buffer: Slot<DumbBuffer<FdWrapper>, _> = swapchain.acquire().unwrap().unwrap();
let framebuffer = surface.add_framebuffer(first_buffer.handle(), 32, 32).unwrap();
*first_buffer.userdata() = Some(framebuffer);

View File

@ -11,9 +11,9 @@
//! the lifetime of the buffer. E.g. when you are only caching associated resources for a dmabuf.
use super::{Buffer, Format, Fourcc, Modifier};
use std::hash::{Hash, Hasher};
use std::os::unix::io::{IntoRawFd, RawFd};
use std::sync::{Arc, Weak};
use std::hash::{Hash, Hasher};
/// Maximum amount of planes this implementation supports
pub const MAX_PLANES: usize = 4;

View File

@ -28,19 +28,16 @@ use crate::backend::egl::{
};
use crate::backend::SwapBuffersError;
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
use super::ImportEgl;
#[cfg(feature = "wayland_frontend")]
use crate::{
utils::Rectangle,
wayland::compositor::SurfaceAttributes,
};
use super::{ImportDma, ImportShm};
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
use crate::backend::egl::{display::EGLBufferReader, Format as EGLFormat};
#[cfg(feature = "wayland_frontend")]
use wayland_server::protocol::{wl_buffer, wl_shm};
use crate::{utils::Rectangle, wayland::compositor::SurfaceAttributes};
#[cfg(feature = "wayland_frontend")]
use super::{ImportShm, ImportDma};
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
use super::ImportEgl;
use wayland_server::protocol::{wl_buffer, wl_shm};
#[allow(clippy::all, missing_docs)]
pub mod ffi {
@ -480,8 +477,7 @@ impl Gles2Renderer {
fn cleanup(&mut self) -> Result<(), Gles2Error> {
self.make_current()?;
#[cfg(feature = "wayland_frontend")]
self.dmabuf_cache
.retain(|entry, _tex| entry.upgrade().is_some());
self.dmabuf_cache.retain(|entry, _tex| entry.upgrade().is_some());
for resource in self.destruction_callback.try_iter() {
match resource {
CleanupResource::Texture(texture) => unsafe {
@ -618,7 +614,11 @@ impl ImportShm for Gles2Renderer {
}
}
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
impl ImportEgl for Gles2Renderer {
fn import_egl_buffer(
&mut self,
@ -664,10 +664,7 @@ impl ImportEgl for Gles2Renderer {
#[cfg(feature = "wayland_frontend")]
impl ImportDma for Gles2Renderer {
fn import_dmabuf(
&mut self,
buffer: &Dmabuf,
) -> Result<Gles2Texture, Gles2Error> {
fn import_dmabuf(&mut self, buffer: &Dmabuf) -> Result<Gles2Texture, Gles2Error> {
if !self.extensions.iter().any(|ext| ext == "GL_OES_EGL_image") {
return Err(Gles2Error::GLExtensionNotSupported(&["GL_OES_EGL_image"]));
}
@ -676,7 +673,10 @@ impl ImportDma for Gles2Renderer {
let is_external = !self.egl.dmabuf_render_formats().contains(&buffer.format());
self.make_current()?;
let image = self.egl.display.create_image_from_dmabuf(&buffer)
let image = self
.egl
.display
.create_image_from_dmabuf(&buffer)
.map_err(Gles2Error::BindBufferEGLError)?;
let tex = self.import_egl_image(image, is_external, None)?;
@ -704,10 +704,7 @@ impl ImportDma for Gles2Renderer {
#[cfg(feature = "wayland_frontend")]
impl Gles2Renderer {
fn existing_dmabuf_texture(
&self,
buffer: &Dmabuf,
) -> Result<Option<Gles2Texture>, Gles2Error> {
fn existing_dmabuf_texture(&self, buffer: &Dmabuf) -> Result<Option<Gles2Texture>, Gles2Error> {
let existing_texture = self
.dmabuf_cache
.iter()

View File

@ -20,7 +20,11 @@ use wayland_server::protocol::{wl_buffer, wl_shm};
pub mod gles2;
#[cfg(feature = "wayland_frontend")]
use crate::backend::allocator::{dmabuf::Dmabuf, Format};
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
use crate::backend::egl::display::EGLBufferReader;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
@ -270,7 +274,11 @@ pub trait ImportShm: Renderer {
}
}
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
/// Trait for Renderers supporting importing wl_drm-based buffers.
pub trait ImportEgl: Renderer {
/// Import a given wl_drm-based buffer into the renderer (see [`buffer_type`]).
@ -343,7 +351,11 @@ pub trait ImportDma: Renderer {
// pub type ImportAll = Renderer + ImportShm + ImportEgl;
/// Common trait for renderers of any wayland buffer type
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
pub trait ImportAll: Renderer + ImportShm + ImportEgl {
/// Import a given buffer into the renderer.
///
@ -377,7 +389,11 @@ pub trait ImportAll: Renderer + ImportShm + ImportEgl {
}
}
}
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
impl<R: Renderer + ImportShm + ImportEgl> ImportAll for R {}
#[cfg(feature = "wayland_frontend")]
@ -397,17 +413,16 @@ pub enum BufferType {
///
/// Returns `None` if the type is not known to smithay
/// or otherwise not supported (e.g. not initialized using one of smithays [`crate::wayland`]-handlers).
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
pub fn buffer_type(
buffer: &wl_buffer::WlBuffer,
egl_buffer_reader: Option<&EGLBufferReader>,
) -> Option<BufferType> {
if buffer
.as_ref()
.user_data()
.get::<Dmabuf>()
.is_some()
{
if buffer.as_ref().user_data().get::<Dmabuf>().is_some() {
Some(BufferType::Dma)
} else if egl_buffer_reader
.as_ref()
@ -415,8 +430,7 @@ pub fn buffer_type(
.is_some()
{
Some(BufferType::Egl)
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok()
{
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok() {
Some(BufferType::Shm)
} else {
None
@ -426,17 +440,14 @@ pub fn buffer_type(
/// Returns the *type* of a wl_buffer
///
/// Returns `None` if the type is not recognized by smithay or otherwise not supported.
#[cfg(all(feature = "wayland_frontend", not(all(feature = "backend_egl", feature = "use_system_lib"))))]
#[cfg(all(
feature = "wayland_frontend",
not(all(feature = "backend_egl", feature = "use_system_lib"))
))]
pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
if buffer
.as_ref()
.user_data()
.get::<Dmabuf>()
.is_some()
{
if buffer.as_ref().user_data().get::<Dmabuf>().is_some() {
Some(BufferType::Dma)
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok()
{
} else if crate::wayland::shm::with_buffer_contents(&buffer, |_, _| ()).is_ok() {
Some(BufferType::Shm)
} else {
None
@ -446,7 +457,11 @@ pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
/// Returns the dimensions of a wl_buffer
///
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
#[cfg(all(feature = "wayland_frontend", feature = "backend_egl", feature = "use_system_lib"))]
#[cfg(all(
feature = "wayland_frontend",
feature = "backend_egl",
feature = "use_system_lib"
))]
pub fn buffer_dimensions(
buffer: &wl_buffer::WlBuffer,
egl_buffer_reader: Option<&EGLBufferReader>,
@ -472,7 +487,10 @@ pub fn buffer_dimensions(
/// Returns the dimensions of a wl_buffer
///
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
#[cfg(all(feature = "wayland_frontend", not(all(feature = "backend_egl", feature = "use_system_lib"))))]
#[cfg(all(
feature = "wayland_frontend",
not(all(feature = "backend_egl", feature = "use_system_lib"))
))]
pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<(i32, i32)> {
use crate::backend::allocator::Buffer;

View File

@ -28,10 +28,10 @@ use winit::{
window::{Window as WinitWindow, WindowBuilder},
};
#[cfg(feature = "use_system_lib")]
use wayland_server::Display;
#[cfg(feature = "use_system_lib")]
use crate::backend::egl::display::EGLBufferReader;
#[cfg(feature = "use_system_lib")]
use wayland_server::Display;
/// Errors thrown by the `winit` backends
#[derive(thiserror::Error, Debug)]

View File

@ -65,7 +65,6 @@ use crate::backend::allocator::{
///
/// You need to provide an implementation of this trait
/// Initialize a dmabuf global.
///
/// You need to provide a vector of the supported formats, as well as a closure,
@ -136,7 +135,9 @@ where
height,
format,
flags,
} => handler.create_immed(&*params, buffer_id, width, height, format, flags, ddata),
} => {
handler.create_immed(&*params, buffer_id, width, height, format, flags, ddata)
}
_ => {}
});
}
@ -169,7 +170,7 @@ struct ParamsHandler<H: for<'a> FnMut(&Dmabuf, DispatchData<'a>) -> bool + 'stat
impl<H> ParamsHandler<H>
where
H: for<'a> FnMut(&Dmabuf, DispatchData<'a>) -> bool + 'static
H: for<'a> FnMut(&Dmabuf, DispatchData<'a>) -> bool + 'static,
{
fn add(
&mut self,
@ -216,7 +217,15 @@ where
});
}
fn create<'a>(&mut self, params: &BufferParams, width: i32, height: i32, format: u32, flags: u32, ddata: DispatchData<'a>) {
fn create<'a>(
&mut self,
params: &BufferParams,
width: i32,
height: i32,
format: u32,
flags: u32,
ddata: DispatchData<'a>,
) {
// Cannot reuse a params:
if self.used {
params.as_ref().post_error(
@ -378,8 +387,6 @@ where
"create_immed resulted in an invalid buffer.".into(),
);
}
}
}