From d9ce00439de7f4f77b1c16e84bf76dc91774445d Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 10 Dec 2024 18:46:16 +0100 Subject: [PATCH] chore: Fix clippy issues --- anvil/src/udev.rs | 11 +- src/backend/drm/compositor/frame_result.rs | 12 +-- src/backend/drm/compositor/mod.rs | 12 +-- src/backend/drm/output.rs | 112 +++++++-------------- 4 files changed, 54 insertions(+), 93 deletions(-) diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 1ff452dd5709..cc74e09cbadb 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -430,7 +430,7 @@ pub fn run_udev() { primary_gpu, surface_data.render_node, gpus, - &compositor.surface(), + compositor.surface(), ) }) }); @@ -1512,10 +1512,11 @@ fn render_surface<'a>( let (elements, clear_color) = output_elements(output, space, custom_elements, renderer, show_window_preview); - let frame_mode = surface - .disable_direct_scanout - .then_some(FrameMode::COMPOSITE) - .unwrap_or(FrameMode::ALL); + let frame_mode = if surface.disable_direct_scanout { + FrameMode::COMPOSITE + } else { + FrameMode::ALL + }; let (rendered, states) = surface .drm_output .render_frame(renderer, &elements, clear_color, frame_mode) diff --git a/src/backend/drm/compositor/frame_result.rs b/src/backend/drm/compositor/frame_result.rs index 9816258b0b3f..2edfa46df19d 100644 --- a/src/backend/drm/compositor/frame_result.rs +++ b/src/backend/drm/compositor/frame_result.rs @@ -55,7 +55,7 @@ pub struct RenderFrameResult<'a, B: Buffer, F: Framebuffer, E> { pub(super) supports_fencing: bool, } -impl<'a, B: Buffer, F: Framebuffer, E> RenderFrameResult<'a, B, F, E> { +impl RenderFrameResult<'_, B, F, E> { /// Returns if synchronization with kms submission can't be guaranteed through the available apis. pub fn needs_sync(&self) -> bool { if let PrimaryPlaneElement::Swapchain(ref element) = self.primary_element { @@ -73,7 +73,7 @@ struct SwapchainElement<'a, 'b, B: Buffer> { damage: &'b DamageSnapshot, } -impl<'a, 'b, B: Buffer> Element for SwapchainElement<'a, 'b, B> { +impl Element for SwapchainElement<'_, '_, B> { fn id(&self) -> &Id { &self.id } @@ -118,7 +118,7 @@ enum FrameResultDamageElement<'a, 'b, E, B: Buffer> { Swapchain(SwapchainElement<'a, 'b, B>), } -impl<'a, 'b, E, B> Element for FrameResultDamageElement<'a, 'b, E, B> +impl Element for FrameResultDamageElement<'_, '_, E, B> where E: Element, B: Buffer, @@ -201,7 +201,7 @@ pub enum BlitFrameResultError { Export(E), } -impl<'a, B, F, E> RenderFrameResult<'a, B, F, E> +impl RenderFrameResult<'_, B, F, E> where B: Buffer, F: Framebuffer, @@ -413,8 +413,8 @@ where } } -impl<'a, B: Buffer + std::fmt::Debug, F: Framebuffer + std::fmt::Debug, E: std::fmt::Debug> std::fmt::Debug - for RenderFrameResult<'a, B, F, E> +impl std::fmt::Debug + for RenderFrameResult<'_, B, F, E> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("RenderFrameResult") diff --git a/src/backend/drm/compositor/mod.rs b/src/backend/drm/compositor/mod.rs index aef093b102bd..a4744a02f987 100644 --- a/src/backend/drm/compositor/mod.rs +++ b/src/backend/drm/compositor/mod.rs @@ -1288,6 +1288,7 @@ where /// - `modifiers` is the set of modifiers allowed, when allocating buffers with the specified color format /// - `cursor_size` as reported by the drm device, used for creating buffer for the cursor plane /// - `gbm` device used for creating buffers for the cursor plane, `None` will disable the cursor plane + #[allow(clippy::too_many_arguments)] pub fn with_format( output_mode_source: impl Into + Debug, surface: DrmSurface, @@ -1514,10 +1515,9 @@ where Ok(None) => return Err((swapchain.allocator, FrameError::NoFramebuffer)), Err(err) => return Err((swapchain.allocator, FrameError::FramebufferExport(err))), }; - buffer.userdata().insert_if_missing(|| { - let init = CachedDrmFramebuffer::new(DrmFramebuffer::Exporter(fb_buffer)); - init - }); + buffer + .userdata() + .insert_if_missing(|| CachedDrmFramebuffer::new(DrmFramebuffer::Exporter(fb_buffer))); let mode = drm.pending_mode(); let handle = buffer @@ -1559,7 +1559,7 @@ where }), }; - match current_frame_state.test_state(&drm, supports_fencing, drm.plane(), plane_state, true) { + match current_frame_state.test_state(drm, supports_fencing, drm.plane(), plane_state, true) { Ok(_) => Ok((swapchain, use_opaque)), Err(err) => { warn!( @@ -1652,7 +1652,7 @@ where let modifiers = formats.iter().map(|x| x.modifier).collect::>(); let (swapchain, use_opaque) = Self::test_format( - &*drm, + &drm, supports_fencing, planes, allocator, diff --git a/src/backend/drm/output.rs b/src/backend/drm/output.rs index f5ea23744ff8..1ebc11b87ff2 100644 --- a/src/backend/drm/output.rs +++ b/src/backend/drm/output.rs @@ -135,6 +135,17 @@ where RenderFrame(RenderFrameError), } +/// Result returned by `DrmOutputManager`'s methods +pub type DrmOutputManagerResult = Result< + U, + DrmOutputManagerError< + ::Error, + <::Buffer as AsDmabuf>::Error, + ::Buffer>>::Error, + ::Error, + >, +>; + impl DrmOutputManager where A: Allocator + std::clone::Clone + std::fmt::Debug, @@ -172,7 +183,7 @@ where ) -> Self { Self { device, - allocator: allocator, + allocator, exporter, gbm, compositor: Default::default(), @@ -199,8 +210,9 @@ where /// `None` will result in the compositor to use all planes as specified by [`DrmSurface::planes`] /// - `renderer` used for compositing, when commits are necessarily to realize bandwidth constraints /// - `render_elements` used for rendering, when commits are necessarily to realize bandwidth constraints - pub fn initialize_output<'a, R, E>( - &'a mut self, + #[allow(clippy::too_many_arguments)] + pub fn initialize_output( + &mut self, crtc: crtc::Handle, mode: control::Mode, connectors: &[connector::Handle], @@ -208,15 +220,7 @@ where planes: Option, renderer: &mut R, render_elements: &DrmOutputRenderElements, - ) -> Result< - DrmOutput, - DrmOutputManagerError< - ::Error, - <::Buffer as AsDmabuf>::Error, - ::Buffer>>::Error, - R::Error, - >, - > + ) -> DrmOutputManagerResult, A, F, R> where E: RenderElement, R: Renderer + Bind, @@ -302,7 +306,7 @@ where ); for compositor in write_guard.values_mut() { - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); if let Err(err) = render_elements.submit_composited_frame(&mut *compositor, renderer) { if !matches!(err, DrmOutputManagerError::Frame(FrameError::EmptyFrame)) { return Err(err); @@ -324,7 +328,7 @@ where ); for compositor in write_guard.values_mut() { - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); let current_format = compositor.format(); if let Err(err) = compositor.set_format( @@ -348,7 +352,7 @@ where Err(err) => { // try to reset formats for compositor in write_guard.values_mut() { - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); let current_format = compositor.format(); if let Err(err) = compositor.set_format( @@ -378,7 +382,7 @@ where // when downstream potentially uses `FrameMode::ALL` immediately after this. let compositor = write_guard.get_mut(&crtc).unwrap(); - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); render_elements.submit_composited_frame(&mut *compositor, renderer)?; Ok(DrmOutput { @@ -410,15 +414,7 @@ where mode: Mode, renderer: &mut R, render_elements: &DrmOutputRenderElements, - ) -> Result< - (), - DrmOutputManagerError< - ::Error, - <::Buffer as AsDmabuf>::Error, - ::Buffer>>::Error, - R::Error, - >, - > + ) -> DrmOutputManagerResult<(), A, F, R> where E: RenderElement, R: Renderer + Bind, @@ -439,15 +435,7 @@ where &mut self, renderer: &mut R, render_elements: &DrmOutputRenderElements, - ) -> Result< - (), - DrmOutputManagerError< - ::Error, - <::Buffer as AsDmabuf>::Error, - ::Buffer>>::Error, - R::Error, - >, - > + ) -> DrmOutputManagerResult<(), A, F, R> where E: RenderElement, R: Renderer + Bind, @@ -459,11 +447,11 @@ where // check if implicit modifiers are in use if write_guard .values_mut() - .any(|c| c.lock().unwrap().modifiers() == &[DrmModifier::Invalid]) + .any(|c| c.get_mut().unwrap().modifiers() == [DrmModifier::Invalid]) { // if so, first lower the bandwidth by disabling planes on all compositors for compositor in write_guard.values_mut() { - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); if let Err(err) = render_elements.submit_composited_frame(&mut *compositor, renderer) { if !matches!(err, DrmOutputManagerError::Frame(FrameError::EmptyFrame)) { return Err(err); @@ -472,8 +460,8 @@ where } for compositor in write_guard.values_mut() { - let mut compositor = compositor.lock().unwrap(); - if compositor.modifiers() != &[DrmModifier::Invalid] { + let compositor = compositor.get_mut().unwrap(); + if compositor.modifiers() != [DrmModifier::Invalid] { continue; } @@ -507,9 +495,9 @@ where self.device.activate(disable_connectors)?; // We request a write guard here to guarantee unique access - let write_guard = self.compositor.write().unwrap(); - for compositor in write_guard.values() { - if let Err(err) = compositor.lock().unwrap().reset_state() { + let mut write_guard = self.compositor.write().unwrap(); + for compositor in write_guard.values_mut() { + if let Err(err) = compositor.get_mut().unwrap().reset_state() { tracing::warn!("Failed to reset drm surface state: {}", err); } } @@ -645,7 +633,6 @@ where /// /// *Note*: This function should not be followed up with [`DrmOutput::frame_submitted`] /// and will not generate a vblank event on the underlying device. - pub fn commit_frame(&mut self) -> FrameResult<(), A, F> { self.with_compositor(|compositor| compositor.commit_frame()) } @@ -663,15 +650,7 @@ where mode: Mode, renderer: &mut R, render_elements: &DrmOutputRenderElements, - ) -> Result< - (), - DrmOutputManagerError< - ::Error, - <::Buffer as AsDmabuf>::Error, - ::Buffer>>::Error, - R::Error, - >, - > + ) -> DrmOutputManagerResult<(), A, F, R> where E: RenderElement, R: Renderer + Bind, @@ -724,15 +703,7 @@ fn use_mode_internal( mode: Mode, renderer: &mut R, render_elements: &DrmOutputRenderElements, -) -> Result< - (), - DrmOutputManagerError< - ::Error, - <::Buffer as AsDmabuf>::Error, - ::Buffer>>::Error, - R::Error, - >, -> +) -> DrmOutputManagerResult<(), A, F, R> where A: Allocator + std::clone::Clone + fmt::Debug, ::Buffer: AsDmabuf, @@ -752,14 +723,11 @@ where { let mut write_guard = compositor.write().unwrap(); - let mut res = { - let mut compositor_guard = write_guard.get(crtc).unwrap().lock().unwrap(); - compositor_guard.use_mode(mode) - }; + let mut res = write_guard.get(crtc).unwrap().lock().unwrap().use_mode(mode); if res.is_err() { for compositor in write_guard.values_mut() { - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); if let Err(err) = render_elements.submit_composited_frame(&mut *compositor, renderer) { if !matches!(err, DrmOutputManagerError::Frame(FrameError::EmptyFrame)) { return Err(err); @@ -768,7 +736,7 @@ where } let compositor = write_guard.get_mut(crtc).unwrap(); - let mut compositor = compositor.lock().unwrap(); + let compositor = compositor.get_mut().unwrap(); res = compositor.use_mode(mode); if res.is_ok() { @@ -842,15 +810,7 @@ where &self, compositor: &mut DrmCompositor, renderer: &mut R, - ) -> Result< - (), - DrmOutputManagerError< - ::Error, - <::Buffer as AsDmabuf>::Error, - ::Buffer>>::Error, - R::Error, - >, - > + ) -> DrmOutputManagerResult<(), A, F, R> where A: Allocator + std::clone::Clone + std::fmt::Debug, ::Buffer: AsDmabuf, @@ -870,7 +830,7 @@ where .map(|(ref elements, ref color)| (&**elements, color)) .unwrap_or((&[], &Color32F::BLACK)); compositor - .render_frame(renderer, &elements, *clear_color, FrameMode::COMPOSITE) + .render_frame(renderer, elements, *clear_color, FrameMode::COMPOSITE) .map_err(DrmOutputManagerError::RenderFrame)?; compositor.commit_frame().map_err(DrmOutputManagerError::Frame)?; Ok(())