cargo fmt & lint
This commit is contained in:
parent
3fd336aba5
commit
9c3c3d939e
|
@ -1,9 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
#[cfg(feature = "egl")]
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
rc::Rc,
|
||||
};
|
||||
use glium::texture::Texture2d;
|
||||
#[cfg(feature = "egl")]
|
||||
use glium::{
|
||||
|
@ -11,9 +5,14 @@ use glium::{
|
|||
GlObject,
|
||||
};
|
||||
use slog::Logger;
|
||||
use std::collections::HashMap;
|
||||
#[cfg(feature = "egl")]
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
#[cfg(feature = "egl")]
|
||||
use smithay::backend::egl::{display::EGLBufferReader, EGLImages, BufferAccessError as EGLBufferAccessError, Format};
|
||||
use smithay::backend::egl::{
|
||||
display::EGLBufferReader, BufferAccessError as EGLBufferAccessError, EGLImages, Format,
|
||||
};
|
||||
use smithay::{
|
||||
backend::graphics::gl::GLGraphicsBackend,
|
||||
reexports::wayland_server::protocol::wl_buffer::WlBuffer,
|
||||
|
@ -65,8 +64,7 @@ impl BufferUtils {
|
|||
|
||||
/// Returns the dimensions of an image stored in the shm buffer.
|
||||
fn shm_buffer_dimensions(&self, buffer: &WlBuffer) -> Result<(i32, i32), BufferAccessError> {
|
||||
shm_buffer_contents(buffer, |_, data| (data.width, data.height))
|
||||
.map_err(|err| {
|
||||
shm_buffer_contents(buffer, |_, data| (data.width, data.height)).map_err(|err| {
|
||||
warn!(self.log, "Unable to load buffer contents"; "err" => format!("{:?}", err));
|
||||
err
|
||||
})
|
||||
|
@ -111,7 +109,8 @@ impl BufferUtils {
|
|||
}
|
||||
|
||||
fn load_shm_buffer(&self, buffer: WlBuffer) -> Result<BufferTextures, WlBuffer> {
|
||||
let (width, height, format) = match shm_buffer_contents(&buffer, |_, data| (data.width, data.height, data.format)) {
|
||||
let (width, height, format) =
|
||||
match shm_buffer_contents(&buffer, |_, data| (data.width, data.height, data.format)) {
|
||||
Ok(x) => x,
|
||||
Err(err) => {
|
||||
warn!(self.log, "Unable to load buffer contents"; "err" => format!("{:?}", err));
|
||||
|
@ -151,12 +150,16 @@ pub struct BufferTextures {
|
|||
|
||||
impl BufferTextures {
|
||||
#[cfg(feature = "egl")]
|
||||
pub fn load_texture<'a, F: GLGraphicsBackend + 'static>(&'a mut self, drawer: &GliumDrawer<F>) -> Result<&'a Texture2d, ()> {
|
||||
pub fn load_texture<'a, F: GLGraphicsBackend + 'static>(
|
||||
&'a mut self,
|
||||
drawer: &GliumDrawer<F>,
|
||||
) -> Result<&'a Texture2d, ()> {
|
||||
if self.textures.contains_key(&drawer.id) {
|
||||
return Ok(&self.textures[&drawer.id]);
|
||||
}
|
||||
|
||||
if let Some(images) = self.images.as_ref() { //EGL buffer
|
||||
if let Some(images) = self.images.as_ref() {
|
||||
//EGL buffer
|
||||
let format = match images.format {
|
||||
Format::RGB => UncompressedFloatFormat::U8U8U8,
|
||||
Format::RGBA => UncompressedFloatFormat::U8U8U8U8,
|
||||
|
@ -189,7 +192,10 @@ impl BufferTextures {
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "egl"))]
|
||||
pub fn load_texture<'a, F: GLGraphicsBackend + 'static>(&'a mut self, drawer: &GliumDrawer<F>) -> Result<&'a Texture2d, ()> {
|
||||
pub fn load_texture<'a, F: GLGraphicsBackend + 'static>(
|
||||
&'a mut self,
|
||||
drawer: &GliumDrawer<F>,
|
||||
) -> Result<&'a Texture2d, ()> {
|
||||
if self.textures.contains_key(&drawer.id) {
|
||||
return Ok(&self.textures[&drawer.id]);
|
||||
}
|
||||
|
@ -197,7 +203,10 @@ impl BufferTextures {
|
|||
self.load_shm_texture(drawer)
|
||||
}
|
||||
|
||||
fn load_shm_texture<'a, F: GLGraphicsBackend + 'static>(&'a mut self, drawer: &GliumDrawer<F>) -> Result<&'a Texture2d, ()> {
|
||||
fn load_shm_texture<'a, F: GLGraphicsBackend + 'static>(
|
||||
&'a mut self,
|
||||
drawer: &GliumDrawer<F>,
|
||||
) -> Result<&'a Texture2d, ()> {
|
||||
match shm_buffer_contents(&self.buffer, |slice, data| {
|
||||
crate::shm_load::load_shm_buffer(data, slice)
|
||||
.map(|(image, _kind)| Texture2d::new(&drawer.display, image).unwrap())
|
||||
|
@ -205,7 +214,7 @@ impl BufferTextures {
|
|||
Ok(Ok(texture)) => {
|
||||
self.textures.insert(drawer.id, texture);
|
||||
Ok(&self.textures[&drawer.id])
|
||||
},
|
||||
}
|
||||
Ok(Err(format)) => {
|
||||
warn!(self.logger, "Unsupported SHM buffer format"; "format" => format!("{:?}", format));
|
||||
Err(())
|
||||
|
|
|
@ -1,28 +1,19 @@
|
|||
use std::{
|
||||
cell::{Ref, RefCell},
|
||||
rc::Rc,
|
||||
sync::atomic::{AtomicUsize, AtomicBool, Ordering},
|
||||
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
use glium::{
|
||||
self,
|
||||
index::PrimitiveType,
|
||||
texture::Texture2d,
|
||||
Surface,
|
||||
};
|
||||
use glium::{self, index::PrimitiveType, texture::Texture2d, Surface};
|
||||
use slog::Logger;
|
||||
|
||||
use smithay::{
|
||||
backend::graphics::{
|
||||
CursorBackend,
|
||||
gl::GLGraphicsBackend,
|
||||
glium::{Frame, GliumGraphicsBackend},
|
||||
SwapBuffersError,
|
||||
},
|
||||
reexports::{
|
||||
calloop::LoopHandle,
|
||||
wayland_server::protocol::wl_surface,
|
||||
CursorBackend, SwapBuffersError,
|
||||
},
|
||||
reexports::{calloop::LoopHandle, wayland_server::protocol::wl_surface},
|
||||
utils::Rectangle,
|
||||
wayland::{
|
||||
compositor::{roles::Role, SubsurfaceRole, TraversalAction},
|
||||
|
@ -68,11 +59,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
|||
}
|
||||
|
||||
impl<T: Into<GliumGraphicsBackend<T>> + GLGraphicsBackend + 'static> GliumDrawer<T> {
|
||||
pub fn init(
|
||||
backend: T,
|
||||
buffer_loader: BufferUtils,
|
||||
log: Logger,
|
||||
) -> GliumDrawer<T> {
|
||||
pub fn init(backend: T, buffer_loader: BufferUtils, log: Logger) -> GliumDrawer<T> {
|
||||
let display = backend.into();
|
||||
|
||||
// building the vertex buffer, which contains all the vertices that we will draw
|
||||
|
@ -127,13 +114,14 @@ impl<F: GLGraphicsBackend + CursorBackend + 'static> GliumDrawer<F> {
|
|||
) {
|
||||
let (x, y) = position;
|
||||
let _ = self.display.borrow().set_cursor_position(x as u32, y as u32);
|
||||
if !self.hardware_cursor.swap(true, Ordering::SeqCst) {
|
||||
if let Err(_) = self.display.borrow().set_cursor_representation(cursor, hotspot) {
|
||||
warn!(
|
||||
self.log,
|
||||
"Failed to upload hardware cursor",
|
||||
);
|
||||
}
|
||||
if !self.hardware_cursor.swap(true, Ordering::SeqCst)
|
||||
&& self
|
||||
.display
|
||||
.borrow()
|
||||
.set_cursor_representation(cursor, hotspot)
|
||||
.is_err()
|
||||
{
|
||||
warn!(self.log, "Failed to upload hardware cursor",);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,15 +148,15 @@ impl<F: GLGraphicsBackend + CursorBackend + 'static> GliumDrawer<F> {
|
|||
}
|
||||
|
||||
pub fn clear_cursor(&self) {
|
||||
if self.hardware_cursor.swap(false, Ordering::SeqCst) {
|
||||
if let Err(_) = self.display.borrow().clear_cursor_representation() {
|
||||
if self.hardware_cursor.swap(false, Ordering::SeqCst)
|
||||
&& self.display.borrow().clear_cursor_representation().is_err()
|
||||
{
|
||||
warn!(self.log, "Failed to clear cursor");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// I would love to do this, but this is essentially specialization...
|
||||
// I would love to do this (check on !CursorBackend), but this is essentially specialization...
|
||||
// And since this is just an example compositor, it seems we require now,
|
||||
// that for the use of software cursors we need the hardware cursor trait (to do automatic cleanup..)
|
||||
/*
|
||||
|
@ -347,7 +335,8 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
|||
// redraw the frame, in a simple but inneficient way
|
||||
{
|
||||
let screen_dimensions = self.borrow().get_framebuffer_dimensions();
|
||||
window_map.with_windows_from_bottom_to_top(|toplevel_surface, mut initial_place, bounding_box| {
|
||||
window_map.with_windows_from_bottom_to_top(
|
||||
|toplevel_surface, mut initial_place, bounding_box| {
|
||||
// skip windows that do not overlap with a given output
|
||||
if let Some(output) = output_rect {
|
||||
if !output.overlaps(bounding_box) {
|
||||
|
@ -365,7 +354,8 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
|||
screen_dimensions,
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,18 +81,20 @@ impl AnvilState {
|
|||
"err" => format!("{:?}", e)
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
#[cfg(feature = "udev")]
|
||||
KeyAction::Screen(num) => {
|
||||
let output_map = self.output_map
|
||||
.as_ref().unwrap();
|
||||
let output_map = self.output_map.as_ref().unwrap();
|
||||
let outputs = output_map.borrow();
|
||||
if let Some(output) = outputs.get(num) {
|
||||
let x = outputs.iter().take(num).fold(0, |acc, output| acc + output.size.0) as f64 + (output.size.0 as f64 / 2.0);
|
||||
let x = outputs
|
||||
.iter()
|
||||
.take(num)
|
||||
.fold(0, |acc, output| acc + output.size.0) as f64
|
||||
+ (output.size.0 as f64 / 2.0);
|
||||
let y = output.size.1 as f64 / 2.0;
|
||||
*self.pointer_location.borrow_mut() = (x as f64, y as f64)
|
||||
}
|
||||
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -149,8 +151,7 @@ impl AnvilState {
|
|||
|
||||
#[cfg(feature = "udev")]
|
||||
fn clamp_coords(&self, pos: (f64, f64)) -> (f64, f64) {
|
||||
let output_map = self.output_map
|
||||
.as_ref().unwrap();
|
||||
let output_map = self.output_map.as_ref().unwrap();
|
||||
let outputs = output_map.borrow();
|
||||
|
||||
if outputs.len() == 0 {
|
||||
|
@ -159,9 +160,7 @@ impl AnvilState {
|
|||
|
||||
let (mut x, mut y) = pos;
|
||||
// max_x is the sum of the width of all outputs
|
||||
let max_x = outputs
|
||||
.iter()
|
||||
.fold(0u32, |acc, output| acc + output.size.0);
|
||||
let max_x = outputs.iter().fold(0u32, |acc, output| acc + output.size.0);
|
||||
x = x.max(0.0).min(max_x as f64);
|
||||
|
||||
// max y depends on the current output
|
||||
|
|
|
@ -24,14 +24,11 @@ use smithay::{
|
|||
};
|
||||
|
||||
#[cfg(feature = "udev")]
|
||||
use smithay::backend::session::{
|
||||
auto::AutoSession,
|
||||
Session,
|
||||
};
|
||||
use smithay::backend::session::{auto::AutoSession, Session};
|
||||
|
||||
use crate::{buffer_utils::BufferUtils, shell::init_shell};
|
||||
#[cfg(feature = "udev")]
|
||||
use crate::udev::MyOutput;
|
||||
use crate::{buffer_utils::BufferUtils, shell::init_shell};
|
||||
|
||||
pub struct AnvilState {
|
||||
pub socket_name: String,
|
||||
|
|
|
@ -143,7 +143,7 @@ pub fn run_udev(
|
|||
|
||||
let mut udev_handler = UdevHandlerImpl {
|
||||
compositor_token: state.ctoken,
|
||||
buffer_utils: buffer_utils,
|
||||
buffer_utils,
|
||||
#[cfg(feature = "egl")]
|
||||
egl_buffer_reader,
|
||||
session: state.session.clone().unwrap(),
|
||||
|
@ -165,7 +165,6 @@ pub fn run_udev(
|
|||
* Initialize a fake output (we render one screen to every device in this example)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Initialize libinput backend
|
||||
*/
|
||||
|
@ -238,7 +237,13 @@ pub struct MyOutput {
|
|||
}
|
||||
|
||||
impl MyOutput {
|
||||
fn new(display: &mut Display, device_id: dev_t, crtc: crtc::Handle, conn: ConnectorInfo, logger: ::slog::Logger) -> MyOutput {
|
||||
fn new(
|
||||
display: &mut Display,
|
||||
device_id: dev_t,
|
||||
crtc: crtc::Handle,
|
||||
conn: ConnectorInfo,
|
||||
logger: ::slog::Logger,
|
||||
) -> MyOutput {
|
||||
let (output, global) = Output::new(
|
||||
display,
|
||||
format!("{:?}", conn.interface()),
|
||||
|
@ -351,7 +356,13 @@ impl<Data: 'static> UdevHandlerImpl<Data> {
|
|||
buffer_utils.clone(),
|
||||
logger.clone(),
|
||||
);
|
||||
output_map.push(MyOutput::new(display, device.device_id(), crtc, connector_info, logger.clone()));
|
||||
output_map.push(MyOutput::new(
|
||||
display,
|
||||
device.device_id(),
|
||||
crtc,
|
||||
connector_info,
|
||||
logger.clone(),
|
||||
));
|
||||
|
||||
entry.insert(Rc::new(renderer));
|
||||
break 'outer;
|
||||
|
@ -408,7 +419,10 @@ impl<Data: 'static> UdevHandlerImpl<Data> {
|
|||
#[cfg(feature = "egl")]
|
||||
{
|
||||
if path.canonicalize().ok() == self.primary_gpu {
|
||||
info!(self.logger, "Initializing EGL Hardware Acceleration via {:?}", path);
|
||||
info!(
|
||||
self.logger,
|
||||
"Initializing EGL Hardware Acceleration via {:?}", path
|
||||
);
|
||||
*self.egl_buffer_reader.borrow_mut() =
|
||||
device.bind_wl_display(&*self.display.borrow()).ok();
|
||||
}
|
||||
|
@ -484,13 +498,13 @@ impl<Data: 'static> UdevHandlerImpl<Data> {
|
|||
self.loop_handle
|
||||
.with_source(&backend_data.event_source, |source| {
|
||||
let mut backends = backend_data.surfaces.borrow_mut();
|
||||
*backends =
|
||||
UdevHandlerImpl::<Data>::scan_connectors(
|
||||
*backends = UdevHandlerImpl::<Data>::scan_connectors(
|
||||
&mut source.file,
|
||||
buffer_utils,
|
||||
&mut *display,
|
||||
&mut *output_map,
|
||||
logger);
|
||||
logger,
|
||||
);
|
||||
|
||||
for renderer in backends.values() {
|
||||
// render first frame
|
||||
|
@ -507,7 +521,9 @@ impl<Data: 'static> UdevHandlerImpl<Data> {
|
|||
backend_data.surfaces.borrow_mut().clear();
|
||||
debug!(self.logger, "Surfaces dropped");
|
||||
// clear outputs
|
||||
self.output_map.borrow_mut().retain(|output| output.device_id != device);
|
||||
self.output_map
|
||||
.borrow_mut()
|
||||
.retain(|output| output.device_id != device);
|
||||
|
||||
let device = self.loop_handle.remove(backend_data.event_source).unwrap();
|
||||
|
||||
|
@ -582,11 +598,15 @@ impl DrmRenderer {
|
|||
) {
|
||||
if let Some(drawer) = self.backends.borrow().get(&crtc) {
|
||||
// get output coordinates
|
||||
let (x, y) = self.output_map.borrow()
|
||||
let (x, y) = self
|
||||
.output_map
|
||||
.borrow()
|
||||
.iter()
|
||||
.take_while(|output| output.device_id != self.device_id || output.crtc != crtc)
|
||||
.fold((0u32, 0u32), |pos, output| (pos.0 + output.size.0, pos.1));
|
||||
let (width, height) = self.output_map.borrow()
|
||||
let (width, height) = self
|
||||
.output_map
|
||||
.borrow()
|
||||
.iter()
|
||||
.find(|output| output.device_id == self.device_id && output.crtc == crtc)
|
||||
.map(|output| output.size)
|
||||
|
@ -600,7 +620,8 @@ impl DrmRenderer {
|
|||
&mut frame,
|
||||
&*self.window_map.borrow(),
|
||||
Some(Rectangle {
|
||||
x: x as i32, y: y as i32,
|
||||
x: x as i32,
|
||||
y: y as i32,
|
||||
width: width as i32,
|
||||
height: height as i32,
|
||||
}),
|
||||
|
@ -614,21 +635,14 @@ impl DrmRenderer {
|
|||
|
||||
// set cursor
|
||||
if ptr_x >= 0 && ptr_x < width as i32 && ptr_y >= 0 && ptr_y < height as i32 {
|
||||
let _ = drawer
|
||||
.borrow()
|
||||
.set_cursor_position(ptr_x as u32, ptr_y as u32);
|
||||
let _ = drawer.borrow().set_cursor_position(ptr_x as u32, ptr_y as u32);
|
||||
|
||||
// draw the dnd icon if applicable
|
||||
{
|
||||
let guard = self.dnd_icon.lock().unwrap();
|
||||
if let Some(ref surface) = *guard {
|
||||
if surface.as_ref().is_alive() {
|
||||
drawer.draw_dnd_icon(
|
||||
&mut frame,
|
||||
surface,
|
||||
(ptr_x, ptr_y),
|
||||
self.compositor_token,
|
||||
);
|
||||
drawer.draw_dnd_icon(&mut frame, surface, (ptr_x, ptr_y), self.compositor_token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -644,7 +658,12 @@ impl DrmRenderer {
|
|||
*guard = CursorImageStatus::Default;
|
||||
}
|
||||
if let CursorImageStatus::Image(ref surface) = *guard {
|
||||
drawer.draw_software_cursor(&mut frame, surface, (ptr_x, ptr_y), self.compositor_token);
|
||||
drawer.draw_software_cursor(
|
||||
&mut frame,
|
||||
surface,
|
||||
(ptr_x, ptr_y),
|
||||
self.compositor_token,
|
||||
);
|
||||
} else {
|
||||
drawer.draw_hardware_cursor(&self.pointer_image, (2, 2), (ptr_x, ptr_y));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::{cell::RefCell, rc::Rc, sync::atomic::Ordering, time::Duration};
|
||||
|
||||
#[cfg(feature = "egl")]
|
||||
use smithay::backend::egl::EGLGraphicsBackend;
|
||||
use smithay::{
|
||||
backend::{graphics::gl::GLGraphicsBackend, input::InputBackend, winit},
|
||||
reexports::{
|
||||
|
@ -13,8 +15,6 @@ use smithay::{
|
|||
SERIAL_COUNTER as SCOUNTER,
|
||||
},
|
||||
};
|
||||
#[cfg(feature = "egl")]
|
||||
use smithay::backend::egl::EGLGraphicsBackend;
|
||||
|
||||
use slog::Logger;
|
||||
|
||||
|
|
|
@ -192,7 +192,8 @@ impl<S: RawSurface + 'static> CursorBackend for EglStreamSurfaceInternal<S> {
|
|||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.crtc.set_cursor(self.crtc.crtc(), Option::<&DumbBuffer>::None)
|
||||
self.crtc
|
||||
.set_cursor(self.crtc.crtc(), Option::<&DumbBuffer>::None)
|
||||
.compat()
|
||||
.map_err(|source| DrmError::Access {
|
||||
errmsg: "Failed to clear cursor",
|
||||
|
|
|
@ -307,7 +307,9 @@ where
|
|||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
*self.cursor.lock().unwrap() = (self.dev.lock()
|
||||
*self.cursor.lock().unwrap() = (
|
||||
self.dev
|
||||
.lock()
|
||||
.unwrap()
|
||||
.create_buffer_object(
|
||||
1,
|
||||
|
@ -316,10 +318,9 @@ where
|
|||
BufferObjectFlags::CURSOR | BufferObjectFlags::WRITE,
|
||||
)
|
||||
.map_err(Error::BufferCreationFailed)?,
|
||||
(0, 0)
|
||||
(0, 0),
|
||||
);
|
||||
self.crtc.clear_cursor_representation()
|
||||
.map_err(Error::Underlying)
|
||||
self.crtc.clear_cursor_representation().map_err(Error::Underlying)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue