diff --git a/anvil/src/drawing.rs b/anvil/src/drawing.rs index 17220aa..7fa1a0a 100644 --- a/anvil/src/drawing.rs +++ b/anvil/src/drawing.rs @@ -9,7 +9,10 @@ use smithay::{ renderer::{Renderer, Texture, Transform}, SwapBuffersError, }, - reexports::{calloop::LoopHandle, wayland_server::protocol::{wl_buffer,wl_surface}}, + reexports::{ + calloop::LoopHandle, + wayland_server::protocol::{wl_buffer, wl_surface}, + }, utils::Rectangle, wayland::{ compositor::{roles::Role, SubsurfaceRole, TraversalAction}, @@ -54,14 +57,7 @@ where (0, 0) } }; - draw_surface_tree( - renderer, - surface, - egl_buffer_reader, - (x - dx, y - dy), - token, - log, - ) + draw_surface_tree(renderer, surface, egl_buffer_reader, (x - dx, y - dy), token, log) } fn draw_surface_tree( @@ -89,7 +85,10 @@ where if data.texture.is_none() { if let Some(buffer) = data.current_state.buffer.take() { match renderer.import_buffer(&buffer, egl_buffer_reader) { - Ok(m) => data.texture = Some(Box::new(BufferTextures { buffer, texture: m }) as Box), + Ok(m) => { + data.texture = Some(Box::new(BufferTextures { buffer, texture: m }) + as Box) + } // there was an error reading the buffer, release it, we // already logged the error Err(err) => { @@ -154,9 +153,12 @@ where x += sub_x; y += sub_y; } - if let Err(err) = - renderer.render_texture_at(&texture.texture, (x, y), Transform::Normal /* TODO */, 1.0) - { + if let Err(err) = renderer.render_texture_at( + &texture.texture, + (x, y), + Transform::Normal, /* TODO */ + 1.0, + ) { result = Err(err.into()); } } @@ -229,14 +231,7 @@ where "Trying to display as a dnd icon a surface that does not have the DndIcon role." ); } - draw_surface_tree( - renderer, - surface, - egl_buffer_reader, - (x, y), - token, - log, - ) + draw_surface_tree(renderer, surface, egl_buffer_reader, (x, y), token, log) } pub fn schedule_initial_render( diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index e5454c2..f74bc7c 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -4,6 +4,8 @@ use std::{ sync::{Arc, Mutex}, }; +#[cfg(feature = "egl")] +use smithay::backend::egl::display::EGLBufferReader; use smithay::{ backend::renderer::buffer_dimensions, reexports::{ @@ -33,8 +35,6 @@ use smithay::{ Serial, }, }; -#[cfg(feature = "egl")] -use smithay::backend::egl::display::EGLBufferReader; use crate::window_map::{Kind as SurfaceKind, WindowMap}; @@ -310,9 +310,8 @@ pub struct ShellHandles { pub fn init_shell( display: &mut Display, - #[cfg(feature = "egl")] - egl_reader: Rc>>, - log: ::slog::Logger + #[cfg(feature = "egl")] egl_reader: Rc>>, + log: ::slog::Logger, ) -> ShellHandles { // TODO: this is awkward... let almost_window_map = Rc::new(RefCell::new(None::>>)); @@ -794,8 +793,7 @@ impl SurfaceData { fn surface_commit( surface: &wl_surface::WlSurface, token: CompositorToken, - #[cfg(feature = "egl")] - egl_reader: Option<&EGLBufferReader>, + #[cfg(feature = "egl")] egl_reader: Option<&EGLBufferReader>, window_map: &RefCell, ) { #[cfg(feature = "xwayland")] diff --git a/anvil/src/state.rs b/anvil/src/state.rs index 9fa7ff7..2d377f2 100644 --- a/anvil/src/state.rs +++ b/anvil/src/state.rs @@ -23,18 +23,18 @@ use smithay::{ }, }; +#[cfg(feature = "egl")] +use smithay::backend::egl::display::EGLBufferReader; #[cfg(feature = "udev")] use smithay::backend::session::{auto::AutoSession, Session}; #[cfg(feature = "xwayland")] use smithay::xwayland::XWayland; -#[cfg(feature = "egl")] -use smithay::backend::egl::display::EGLBufferReader; +use crate::shell::init_shell; #[cfg(feature = "udev")] use crate::udev::MyOutput; #[cfg(feature = "xwayland")] use crate::xwayland::XWm; -use crate::shell::init_shell; pub struct AnvilState { pub socket_name: String, diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index b64da5a..cdad566 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -12,6 +12,8 @@ use std::{ use image::{ImageBuffer, Rgba}; use slog::Logger; +#[cfg(feature = "egl")] +use smithay::backend::{drm::DevPath, egl::display::EGLBufferReader, udev::primary_gpu}; use smithay::{ backend::{ drm::{device_bind, DeviceHandler, DrmDevice, DrmError, DrmRenderSurface}, @@ -56,10 +58,6 @@ use smithay::{ seat::CursorImageStatus, }, }; -#[cfg(feature = "egl")] -use smithay::{ - backend::{drm::DevPath, egl::display::EGLBufferReader, udev::primary_gpu}, -}; use crate::drawing::*; use crate::shell::{MyWindowMap, Roles}; @@ -501,7 +499,11 @@ impl UdevHandlerImpl { let renderer = Rc::new(DrmRenderer { device_id, #[cfg(feature = "egl")] - egl_buffer_reader: if is_primary { self.egl_buffer_reader.borrow().clone() } else { None }, + egl_buffer_reader: if is_primary { + self.egl_buffer_reader.borrow().clone() + } else { + None + }, compositor_token: self.compositor_token, backends: backends.clone(), window_map: self.window_map.clone(), @@ -741,8 +743,7 @@ impl DrmRenderer { #[allow(clippy::too_many_arguments)] fn render_surface( surface: &mut RenderSurface, - #[cfg(feature = "egl")] - egl_buffer_reader: Option<&EGLBufferReader>, + #[cfg(feature = "egl")] egl_buffer_reader: Option<&EGLBufferReader>, device_id: dev_t, crtc: crtc::Handle, window_map: &mut MyWindowMap, diff --git a/examples/raw_drm.rs b/examples/raw_drm.rs index a01c645..8847bfa 100644 --- a/examples/raw_drm.rs +++ b/examples/raw_drm.rs @@ -132,8 +132,7 @@ fn main() { } pub struct DrmHandlerImpl { - swapchain: - Swapchain, DumbBuffer, framebuffer::Handle>, + swapchain: Swapchain, DumbBuffer, framebuffer::Handle>, current: Slot, framebuffer::Handle>, surface: Rc>, } diff --git a/src/backend/allocator/dumb.rs b/src/backend/allocator/dumb.rs index d418e3c..88601c0 100644 --- a/src/backend/allocator/dumb.rs +++ b/src/backend/allocator/dumb.rs @@ -20,9 +20,9 @@ pub struct DumbBuffer { impl fmt::Debug for DumbBuffer { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("DumbBuffer") - .field("handle", &self.handle) - .field("format", &self.format) - .finish() + .field("handle", &self.handle) + .field("format", &self.format) + .finish() } } diff --git a/src/backend/allocator/gbm.rs b/src/backend/allocator/gbm.rs index 2621d2f..d3c65d7 100644 --- a/src/backend/allocator/gbm.rs +++ b/src/backend/allocator/gbm.rs @@ -1,6 +1,9 @@ //! Module for Buffers created using [libgbm](reexports::gbm) -use super::{dmabuf::{AsDmabuf, Dmabuf}, Allocator, Buffer, Format, Fourcc, Modifier}; +use super::{ + dmabuf::{AsDmabuf, Dmabuf}, + Allocator, Buffer, Format, Fourcc, Modifier, +}; use gbm::{BufferObject as GbmBuffer, BufferObjectFlags, Device as GbmDevice}; use std::os::unix::io::AsRawFd; diff --git a/src/backend/allocator/swapchain.rs b/src/backend/allocator/swapchain.rs index fc8defb..8fc52b3 100644 --- a/src/backend/allocator/swapchain.rs +++ b/src/backend/allocator/swapchain.rs @@ -132,10 +132,11 @@ where pub fn acquire(&mut self) -> Result>, A::Error> { if let Some(free_slot) = self.slots.iter_mut().find(|s| !s.acquired.load(Ordering::SeqCst)) { if free_slot.buffer.is_none() { - free_slot.buffer = Arc::new(Some( - self.allocator - .create_buffer(self.width, self.height, self.format)? - )); + free_slot.buffer = Arc::new(Some(self.allocator.create_buffer( + self.width, + self.height, + self.format, + )?)); } assert!(free_slot.buffer.is_some()); diff --git a/src/backend/drm/render.rs b/src/backend/drm/render.rs index 467727c..2f19f76 100644 --- a/src/backend/drm/render.rs +++ b/src/backend/drm/render.rs @@ -10,12 +10,15 @@ use gbm::{BufferObject, BufferObjectFlags, Device as GbmDevice}; use wayland_server::protocol::{wl_buffer, wl_shm}; use super::{device::DevPath, surface::DrmSurfaceInternal, DrmError, DrmSurface}; -use crate::backend::{ - allocator::{dmabuf::{AsDmabuf, Dmabuf}, Allocator, Buffer, Format, Fourcc, Modifier, Slot, Swapchain}, - egl::display::EGLBufferReader, -}; use crate::backend::renderer::{Bind, Renderer, Texture, Transform}; use crate::backend::SwapBuffersError; +use crate::backend::{ + allocator::{ + dmabuf::{AsDmabuf, Dmabuf}, + Allocator, Buffer, Format, Fourcc, Modifier, Slot, Swapchain, + }, + egl::display::EGLBufferReader, +}; /// Simplified by limited abstraction to link single [`DrmSurface`]s to renderers. /// @@ -24,12 +27,7 @@ use crate::backend::SwapBuffersError; /// In some scenarios it might be enough to use of a drm-surface as the one and only target /// of a single renderer. In these cases `DrmRenderSurface` provides a way to quickly /// get up and running without manually handling and binding buffers. -pub struct DrmRenderSurface< - D: AsRawFd + 'static, - A: Allocator, - R: Bind, - B: Buffer, -> { +pub struct DrmRenderSurface, R: Bind, B: Buffer> { _format: Format, buffers: Buffers, current_buffer: Option<(Slot>)>, Dmabuf)>, @@ -42,7 +40,7 @@ impl DrmRenderSurface where D: AsRawFd + 'static, A: Allocator, - B: Buffer + AsDmabuf, + B: Buffer + AsDmabuf, R: Bind + Renderer, E1: std::error::Error + 'static, E2: std::error::Error + 'static, @@ -328,7 +326,7 @@ impl Renderer for DrmRenderSurface where D: AsRawFd + 'static, A: Allocator, - B: Buffer + AsDmabuf, + B: Buffer + AsDmabuf, R: Bind + Renderer, T: Texture, E1: std::error::Error + 'static, @@ -352,19 +350,29 @@ where } #[cfg(feature = "wayland_frontend")] - fn import_buffer(&mut self, buffer: &wl_buffer::WlBuffer, egl: Option<&EGLBufferReader>) -> Result { - self.renderer.import_buffer(buffer, egl).map_err(Error::RenderError) + fn import_buffer( + &mut self, + buffer: &wl_buffer::WlBuffer, + egl: Option<&EGLBufferReader>, + ) -> Result { + self.renderer + .import_buffer(buffer, egl) + .map_err(Error::RenderError) } - + fn begin(&mut self, width: u32, height: u32, _transform: Transform) -> Result<(), Error> { if self.current_buffer.is_some() { return Ok(()); } - let slot = self.swapchain.acquire().map_err(Error::SwapchainError)?.ok_or(Error::NoFreeSlotsError)?; + let slot = self + .swapchain + .acquire() + .map_err(Error::SwapchainError)? + .ok_or(Error::NoFreeSlotsError)?; let dmabuf = match &*slot.userdata() { Some((buf, _)) => buf.clone(), - None => (*slot).export().map_err(Error::AsDmabufError)?, + None => (*slot).export().map_err(Error::AsDmabufError)?, }; self.renderer.bind(dmabuf.clone()).map_err(Error::RenderError)?; self.current_buffer = Some((slot, dmabuf)); @@ -396,10 +404,7 @@ where let result = self.renderer.finish(); if result.is_ok() { let (slot, dmabuf) = self.current_buffer.take().unwrap(); - match self - .buffers - .queue::(slot, dmabuf) - { + match self.buffers.queue::(slot, dmabuf) { Ok(()) => {} Err(Error::DrmError(drm)) => return Err(drm.into()), Err(Error::GbmError(err)) => return Err(SwapBuffersError::ContextLost(Box::new(err))), @@ -454,7 +459,7 @@ where dmabuf: Dmabuf, ) -> Result<(), Error> where - B: AsDmabuf, + B: AsDmabuf, E1: std::error::Error + 'static, E2: std::error::Error + 'static, E3: std::error::Error + 'static, @@ -497,7 +502,15 @@ where { // yes it does not look like it, but both of these lines should be safe in all cases. let slot = self.queued_fb.take().unwrap(); - let fb = slot.userdata().as_ref().unwrap().1.userdata().unwrap().unwrap().fb; + let fb = slot + .userdata() + .as_ref() + .unwrap() + .1 + .userdata() + .unwrap() + .unwrap() + .fb; let flip = if self.drm.commit_pending() { self.drm.commit(fb, true) diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 5fcf076..9d6f092 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -617,7 +617,10 @@ pub struct EGLBufferReader { #[cfg(feature = "use_system_lib")] impl EGLBufferReader { fn new(display: Arc, wayland: *mut wl_display) -> Self { - Self { display, wayland: Some(Arc::new(wayland)) } + Self { + display, + wayland: Some(Arc::new(wayland)), + } } /// Try to receive [`EGLImages`] from a given [`WlBuffer`]. diff --git a/src/backend/egl/surface.rs b/src/backend/egl/surface.rs index 0c86b38..0e6ce06 100644 --- a/src/backend/egl/surface.rs +++ b/src/backend/egl/surface.rs @@ -29,14 +29,14 @@ pub struct EGLSurface { impl fmt::Debug for EGLSurface { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("EGLSurface") - .field("display", &self.display) - // native does not necessarily implement Debug - .field("surface", &self.surface) - .field("config_id", &self.config_id) - .field("pixel_format", &self.pixel_format) - .field("surface_attributes", &self.surface_attributes) - .field("logger", &self.logger) - .finish() + .field("display", &self.display) + // native does not necessarily implement Debug + .field("surface", &self.surface) + .field("config_id", &self.config_id) + .field("pixel_format", &self.pixel_format) + .field("surface_attributes", &self.surface_attributes) + .field("logger", &self.logger) + .finish() } } diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index d96c3d4..bece9f3 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -1,15 +1,15 @@ //! Implementation of the rendering traits using OpenGL ES 2 -use std::{collections::HashSet, os::raw::c_char}; use std::cell::RefCell; -use std::fmt; use std::ffi::CStr; +use std::fmt; use std::ptr; use std::rc::Rc; use std::sync::{ - atomic::{Ordering, AtomicUsize}, - mpsc::{Sender, Receiver, channel} + atomic::{AtomicUsize, Ordering}, + mpsc::{channel, Receiver, Sender}, }; +use std::{collections::HashSet, os::raw::c_char}; use cgmath::{prelude::*, Matrix3}; @@ -20,7 +20,8 @@ use crate::backend::allocator::{ Format, }; use crate::backend::egl::{ - ffi::egl::types::EGLImage, EGLBuffer, EGLContext, EGLSurface, Format as EGLFormat, MakeCurrentError, display::EGLBufferReader, + display::EGLBufferReader, ffi::egl::types::EGLImage, EGLBuffer, EGLContext, EGLSurface, + Format as EGLFormat, MakeCurrentError, }; use crate::backend::SwapBuffersError; @@ -109,17 +110,17 @@ pub struct Gles2Renderer { impl fmt::Debug for Gles2Renderer { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Gles2Renderer") - .field("id", &self.id) - .field("buffers", &self.buffers) - .field("target_buffer", &self.target_buffer) - .field("target_surface", &self.target_surface) - .field("current_projection", &self.current_projection) - .field("extensions", &self.extensions) - .field("programs", &self.programs) - // ffi::Gles2 does not implement Debug - .field("egl", &self.egl) - .field("logger", &self.logger) - .finish() + .field("id", &self.id) + .field("buffers", &self.buffers) + .field("target_buffer", &self.target_buffer) + .field("target_surface", &self.target_surface) + .field("current_projection", &self.current_projection) + .field("extensions", &self.extensions) + .field("programs", &self.programs) + // ffi::Gles2 does not implement Debug + .field("egl", &self.egl) + .field("logger", &self.logger) + .finish() } } @@ -409,8 +410,8 @@ struct BufferCache { } enum BufferCacheVariant { - Egl(Option), - Shm(Option), + Egl(Option), + Shm(Option), } struct EglCache { @@ -424,7 +425,11 @@ struct ShmCache { impl Gles2Renderer { #[cfg(feature = "wayland_frontend")] - fn import_shm(&mut self, buffer: &wl_buffer::WlBuffer, cache: &mut Option) -> Result { + fn import_shm( + &mut self, + buffer: &wl_buffer::WlBuffer, + cache: &mut Option, + ) -> Result { use crate::wayland::shm::with_buffer_contents; with_buffer_contents(&buffer, |slice, data| { @@ -500,22 +505,34 @@ impl Gles2Renderer { } #[cfg(feature = "wayland_frontend")] - fn import_egl(&mut self, buffer: &wl_buffer::WlBuffer, reader: &EGLBufferReader, cache: &mut Option) -> Result { + fn import_egl( + &mut self, + buffer: &wl_buffer::WlBuffer, + reader: &EGLBufferReader, + cache: &mut Option, + ) -> Result { if !self.extensions.iter().any(|ext| ext == "GL_OES_EGL_image") { return Err(Gles2Error::GLExtensionNotSupported(&["GL_OES_EGL_image"])); } self.make_current()?; - let egl_buffer = cache.as_mut().and_then(|x| x.buf.take()).map(Ok).unwrap_or_else(|| { - reader.egl_buffer_contents(&buffer) - }).map_err(Gles2Error::EGLBufferAccessError)?; + let egl_buffer = cache + .as_mut() + .and_then(|x| x.buf.take()) + .map(Ok) + .unwrap_or_else(|| reader.egl_buffer_contents(&buffer)) + .map_err(Gles2Error::EGLBufferAccessError)?; // we do not need to re-import external textures if egl_buffer.format == EGLFormat::External && cache.is_some() { return Ok(cache.as_ref().map(|x| x.texture.clone()).unwrap()); } - let tex = self.import_egl_image(egl_buffer.image(0).unwrap(), egl_buffer.format == EGLFormat::External, cache.as_ref().map(|x| x.texture.0.texture))?; + let tex = self.import_egl_image( + egl_buffer.image(0).unwrap(), + egl_buffer.format == EGLFormat::External, + cache.as_ref().map(|x| x.texture.0.texture), + )?; let texture = cache.as_ref().map(|x| x.texture.clone()).unwrap_or_else(|| { Gles2Texture(Rc::new(Gles2TextureInternal { texture: tex, @@ -542,7 +559,12 @@ impl Gles2Renderer { Ok(texture) } - fn import_egl_image(&self, image: EGLImage, is_external: bool, tex: Option) -> Result { + fn import_egl_image( + &self, + image: EGLImage, + is_external: bool, + tex: Option, + ) -> Result { let tex = tex.unwrap_or_else(|| unsafe { let mut tex = 0; self.gl.GenTextures(1, &mut tex); @@ -556,8 +578,7 @@ impl Gles2Renderer { unsafe { self.gl.BindTexture(target, tex); - self.gl - .EGLImageTargetTexture2DOES(target, image); + self.gl.EGLImageTargetTexture2DOES(target, image); } Ok(tex) @@ -593,7 +614,13 @@ impl Bind for Gles2Renderer { let buffer = self .buffers .iter() - .find(|buffer| if let Some(dma) = buffer.dmabuf.upgrade() { dma == dmabuf } else { false }) + .find(|buffer| { + if let Some(dma) = buffer.dmabuf.upgrade() { + dma == dmabuf + } else { + false + } + }) .map(|buf| { let dmabuf = buf .dmabuf @@ -773,15 +800,18 @@ impl Renderer for Gles2Renderer { Ok(texture) } - #[cfg(feature = "wayland_frontend")] - fn import_buffer(&mut self, buffer: &wl_buffer::WlBuffer, egl: Option<&EGLBufferReader>) -> Result { + fn import_buffer( + &mut self, + buffer: &wl_buffer::WlBuffer, + egl: Option<&EGLBufferReader>, + ) -> Result { // init cache if not existing let cache_cell = match buffer.as_ref().user_data().get::>>() { Some(cache) => cache.clone(), None => { let cache = BufferCache { - cache: Vec::with_capacity(self.id+1), + cache: Vec::with_capacity(self.id + 1), }; let data: Rc> = Rc::new(RefCell::new(cache)); @@ -790,7 +820,7 @@ impl Renderer for Gles2Renderer { result } }; - + // init cache let mut cache = cache_cell.borrow_mut(); while cache.cache.len() < self.id { @@ -805,10 +835,10 @@ impl Renderer for Gles2Renderer { BufferCacheVariant::Shm(None) } else { unreachable!("Completely unknown buffer format. How did we got here?"); - } + }, )); } - + // delegate for different buffer types match cache.cache[self.id].as_mut() { Some(BufferCacheVariant::Egl(cache)) => self.import_egl(&buffer, egl.unwrap(), cache), @@ -889,7 +919,8 @@ impl Renderer for Gles2Renderer { .TexParameteri(target, ffi::TEXTURE_MIN_FILTER, ffi::LINEAR as i32); self.gl.UseProgram(self.programs[tex.0.texture_kind].program); - self.gl.Uniform1i(self.programs[tex.0.texture_kind].uniform_tex, 0); + self.gl + .Uniform1i(self.programs[tex.0.texture_kind].uniform_tex, 0); self.gl.UniformMatrix3fv( self.programs[tex.0.texture_kind].uniform_matrix, 1, diff --git a/src/backend/renderer/mod.rs b/src/backend/renderer/mod.rs index 0d872d3..0d36b1c 100644 --- a/src/backend/renderer/mod.rs +++ b/src/backend/renderer/mod.rs @@ -164,7 +164,6 @@ pub trait Renderer { &[wl_shm::Format::Argb8888, wl_shm::Format::Xrgb8888] } - /// Import a given buffer into the renderer. /// /// Returns a texture_id, which can be used with `render_texture(_at)` or implementation-specific functions. @@ -176,7 +175,11 @@ pub trait Renderer { /// The implementation defines, if the id keeps being valid, if the buffer is released, /// to avoid relying on implementation details, keep the buffer alive, until you destroyed this texture again. #[cfg(feature = "wayland_frontend")] - fn import_buffer(&mut self, buffer: &wl_buffer::WlBuffer, egl: Option<&EGLBufferReader>) -> Result; + fn import_buffer( + &mut self, + buffer: &wl_buffer::WlBuffer, + egl: Option<&EGLBufferReader>, + ) -> Result; /// Initialize a rendering context on the current rendering target with given dimensions and transformation. /// @@ -248,10 +251,18 @@ pub trait Renderer { /// Returns the dimensions of a wl_buffer #[cfg(all(feature = "wayland_frontend", feature = "backend_egl"))] -pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer, egl_buffer_reader: Option<&EGLBufferReader>) -> Option<(i32, i32)> { - if let Some((w, h)) = egl_buffer_reader.as_ref().and_then(|x| x.egl_buffer_dimensions(&buffer)) { +pub fn buffer_dimensions( + buffer: &wl_buffer::WlBuffer, + egl_buffer_reader: Option<&EGLBufferReader>, +) -> Option<(i32, i32)> { + if let Some((w, h)) = egl_buffer_reader + .as_ref() + .and_then(|x| x.egl_buffer_dimensions(&buffer)) + { Some((w, h)) - } else if let Ok((w, h)) = crate::wayland::shm::with_buffer_contents(&buffer, |_, data| (data.width, data.height)) { + } else if let Ok((w, h)) = + crate::wayland::shm::with_buffer_contents(&buffer, |_, data| (data.width, data.height)) + { Some((w, h)) } else { None @@ -263,9 +274,11 @@ pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer, egl_buffer_reader: Option pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<(i32, i32)> { use crate::backend::allocator::Buffer; - if let Ok((w, h)) = crate::wayland::shm::with_buffer_contents(&buffer, |_, data| (data.width, data.height)) { + if let Ok((w, h)) = + crate::wayland::shm::with_buffer_contents(&buffer, |_, data| (data.width, data.height)) + { Some((w, h)) } else { None } -} \ No newline at end of file +} diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 7f4fe94..bf3876e 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -291,7 +291,11 @@ impl Renderer for WinitGraphicsBackend { } #[cfg(feature = "wayland_frontend")] - fn import_buffer(&mut self, buffer: &wl_buffer::WlBuffer, egl: Option<&EGLBufferReader>) -> Result { + fn import_buffer( + &mut self, + buffer: &wl_buffer::WlBuffer, + egl: Option<&EGLBufferReader>, + ) -> Result { self.renderer.import_buffer(buffer, egl) }