Skip to content

Commit

Permalink
chore: Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Dec 12, 2024
1 parent 86e359a commit d9ce004
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 93 deletions.
11 changes: 6 additions & 5 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub fn run_udev() {
primary_gpu,
surface_data.render_node,
gpus,
&compositor.surface(),
compositor.surface(),
)
})
});
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/backend/drm/compositor/frame_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: Buffer, F: Framebuffer, E> 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 {
Expand All @@ -73,7 +73,7 @@ struct SwapchainElement<'a, 'b, B: Buffer> {
damage: &'b DamageSnapshot<i32, BufferCoords>,
}

impl<'a, 'b, B: Buffer> Element for SwapchainElement<'a, 'b, B> {
impl<B: Buffer> Element for SwapchainElement<'_, '_, B> {
fn id(&self) -> &Id {
&self.id
}
Expand Down Expand Up @@ -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<E, B> Element for FrameResultDamageElement<'_, '_, E, B>
where
E: Element,
B: Buffer,
Expand Down Expand Up @@ -201,7 +201,7 @@ pub enum BlitFrameResultError<R: std::error::Error, E: std::error::Error> {
Export(E),
}

impl<'a, B, F, E> RenderFrameResult<'a, B, F, E>
impl<B, F, E> RenderFrameResult<'_, B, F, E>
where
B: Buffer,
F: Framebuffer,
Expand Down Expand Up @@ -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<B: Buffer + std::fmt::Debug, F: Framebuffer + std::fmt::Debug, E: std::fmt::Debug> std::fmt::Debug
for RenderFrameResult<'_, B, F, E>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RenderFrameResult")
Expand Down
12 changes: 6 additions & 6 deletions src/backend/drm/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OutputModeSource> + Debug,
surface: DrmSurface,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -1652,7 +1652,7 @@ where
let modifiers = formats.iter().map(|x| x.modifier).collect::<Vec<_>>();

let (swapchain, use_opaque) = Self::test_format(
&*drm,
&drm,
supports_fencing,
planes,
allocator,
Expand Down
112 changes: 36 additions & 76 deletions src/backend/drm/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ where
RenderFrame(RenderFrameError<A, B, F, R>),
}

/// Result returned by `DrmOutputManager`'s methods
pub type DrmOutputManagerResult<U, A, F, R> = Result<
U,
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
<R as Renderer>::Error,
>,
>;

impl<A, F, U, G> DrmOutputManager<A, F, U, G>
where
A: Allocator + std::clone::Clone + std::fmt::Debug,
Expand Down Expand Up @@ -172,7 +183,7 @@ where
) -> Self {
Self {
device,
allocator: allocator,
allocator,
exporter,
gbm,
compositor: Default::default(),
Expand All @@ -199,24 +210,17 @@ 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<R, E>(
&mut self,
crtc: crtc::Handle,
mode: control::Mode,
connectors: &[connector::Handle],
output_mode_source: impl Into<OutputModeSource> + std::fmt::Debug,
planes: Option<Planes>,
renderer: &mut R,
render_elements: &DrmOutputRenderElements<R, E>,
) -> Result<
DrmOutput<A, F, U, G>,
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
R::Error,
>,
>
) -> DrmOutputManagerResult<DrmOutput<A, F, U, G>, A, F, R>
where
E: RenderElement<R>,
R: Renderer + Bind<Dmabuf>,
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -410,15 +414,7 @@ where
mode: Mode,
renderer: &mut R,
render_elements: &DrmOutputRenderElements<R, E>,
) -> Result<
(),
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
R::Error,
>,
>
) -> DrmOutputManagerResult<(), A, F, R>
where
E: RenderElement<R>,
R: Renderer + Bind<Dmabuf>,
Expand All @@ -439,15 +435,7 @@ where
&mut self,
renderer: &mut R,
render_elements: &DrmOutputRenderElements<R, E>,
) -> Result<
(),
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
R::Error,
>,
>
) -> DrmOutputManagerResult<(), A, F, R>
where
E: RenderElement<R>,
R: Renderer + Bind<Dmabuf>,
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -663,15 +650,7 @@ where
mode: Mode,
renderer: &mut R,
render_elements: &DrmOutputRenderElements<R, E>,
) -> Result<
(),
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
R::Error,
>,
>
) -> DrmOutputManagerResult<(), A, F, R>
where
E: RenderElement<R>,
R: Renderer + Bind<Dmabuf>,
Expand Down Expand Up @@ -724,15 +703,7 @@ fn use_mode_internal<A, F, U, G, R, E>(
mode: Mode,
renderer: &mut R,
render_elements: &DrmOutputRenderElements<R, E>,
) -> Result<
(),
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
R::Error,
>,
>
) -> DrmOutputManagerResult<(), A, F, R>
where
A: Allocator + std::clone::Clone + fmt::Debug,
<A as Allocator>::Buffer: AsDmabuf,
Expand All @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -842,15 +810,7 @@ where
&self,
compositor: &mut DrmCompositor<A, F, U, G>,
renderer: &mut R,
) -> Result<
(),
DrmOutputManagerError<
<A as Allocator>::Error,
<<A as Allocator>::Buffer as AsDmabuf>::Error,
<F as ExportFramebuffer<<A as Allocator>::Buffer>>::Error,
R::Error,
>,
>
) -> DrmOutputManagerResult<(), A, F, R>
where
A: Allocator + std::clone::Clone + std::fmt::Debug,
<A as Allocator>::Buffer: AsDmabuf,
Expand All @@ -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(())
Expand Down

0 comments on commit d9ce004

Please sign in to comment.