From cde06eb99acc17d20956eae81d63e4bd7fc3a960 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sun, 19 Apr 2020 01:26:09 +0200 Subject: [PATCH] cursor: simplify trait by removing barely utilized lifetimes --- src/backend/drm/egl/surface.rs | 19 ++++++++----------- src/backend/drm/gbm/surface.rs | 28 +++++++++++----------------- src/backend/drm/legacy/surface.rs | 30 ++++++++++++------------------ src/backend/graphics/cursor.rs | 18 ++++++++---------- 4 files changed, 39 insertions(+), 56 deletions(-) diff --git a/src/backend/drm/egl/surface.rs b/src/backend/drm/egl/surface.rs index 1e1f97c..20e419f 100644 --- a/src/backend/drm/egl/surface.rs +++ b/src/backend/drm/egl/surface.rs @@ -62,25 +62,22 @@ where } } -impl<'a, N> CursorBackend<'a> for EglSurface +impl CursorBackend for EglSurface where - N: NativeSurface + Surface + CursorBackend<'a>, + N: NativeSurface + Surface + CursorBackend, { - type CursorFormat = >::CursorFormat; - type Error = >::Error; + type CursorFormat = ::CursorFormat; + type Error = ::Error; fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), Self::Error> { self.surface.set_cursor_position(x, y) } - fn set_cursor_representation<'b>( - &'b self, - buffer: Self::CursorFormat, + fn set_cursor_representation( + &self, + buffer: &Self::CursorFormat, hotspot: (u32, u32), - ) -> ::std::result::Result<(), Self::Error> - where - 'a: 'b, - { + ) -> ::std::result::Result<(), Self::Error> { self.surface.set_cursor_representation(buffer, hotspot) } } diff --git a/src/backend/drm/gbm/surface.rs b/src/backend/drm/gbm/surface.rs index 79c85ec..dd2709f 100644 --- a/src/backend/drm/gbm/surface.rs +++ b/src/backend/drm/gbm/surface.rs @@ -197,22 +197,19 @@ where // But for now got to do this: #[cfg(feature = "backend_drm_legacy")] -impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurfaceInternal> { - type CursorFormat = &'a ImageBuffer, Vec>; - type Error = Error<< as Device>::Surface as Surface>::Error>; +impl CursorBackend for GbmSurfaceInternal> { + type CursorFormat = ImageBuffer, Vec>; + type Error = Error<<::Surface as CursorBackend>::Error>; fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> { self.crtc.set_cursor_position(x, y).map_err(Error::Underlying) } - fn set_cursor_representation<'b>( - &'b self, + fn set_cursor_representation( + &self, buffer: &ImageBuffer, Vec>, hotspot: (u32, u32), - ) -> Result<(), Self::Error> - where - 'a: 'b, - { + ) -> Result<(), Self::Error> { let (w, h) = buffer.dimensions(); debug!(self.logger, "Importing cursor"); @@ -350,22 +347,19 @@ impl Surface for GbmSurface { } #[cfg(feature = "backend_drm_legacy")] -impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface> { - type CursorFormat = &'a ImageBuffer, Vec>; +impl CursorBackend for GbmSurface> { + type CursorFormat = ImageBuffer, Vec>; type Error = ::Error; fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> { self.0.set_cursor_position(x, y) } - fn set_cursor_representation<'b>( - &'b self, + fn set_cursor_representation( + &self, buffer: &ImageBuffer, Vec>, hotspot: (u32, u32), - ) -> Result<(), Self::Error> - where - 'a: 'b, - { + ) -> Result<(), Self::Error> { self.0.set_cursor_representation(buffer, hotspot) } } diff --git a/src/backend/drm/legacy/surface.rs b/src/backend/drm/legacy/surface.rs index 53c178c..3ac3bb5 100644 --- a/src/backend/drm/legacy/surface.rs +++ b/src/backend/drm/legacy/surface.rs @@ -41,8 +41,8 @@ impl AsRawFd for LegacyDrmSurfaceInternal { impl BasicDevice for LegacyDrmSurfaceInternal {} impl ControlDevice for LegacyDrmSurfaceInternal {} -impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal { - type CursorFormat = &'a dyn Buffer; +impl CursorBackend for LegacyDrmSurfaceInternal { + type CursorFormat = dyn Buffer; type Error = Error; fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Error> { @@ -56,14 +56,11 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal }) } - fn set_cursor_representation<'b>( - &'b self, - buffer: Self::CursorFormat, + fn set_cursor_representation( + &self, + buffer: &Self::CursorFormat, hotspot: (u32, u32), - ) -> Result<(), Error> - where - 'a: 'b, - { + ) -> Result<(), Error> { trace!(self.logger, "Setting the new imported cursor"); if self @@ -291,22 +288,19 @@ impl AsRawFd for LegacyDrmSurface { impl BasicDevice for LegacyDrmSurface {} impl ControlDevice for LegacyDrmSurface {} -impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurface { - type CursorFormat = &'a dyn Buffer; +impl CursorBackend for LegacyDrmSurface { + type CursorFormat = dyn Buffer; type Error = Error; fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Error> { self.0.set_cursor_position(x, y) } - fn set_cursor_representation<'b>( - &'b self, - buffer: Self::CursorFormat, + fn set_cursor_representation( + &self, + buffer: &Self::CursorFormat, hotspot: (u32, u32), - ) -> Result<(), Error> - where - 'a: 'b, - { + ) -> Result<(), Error> { self.0.set_cursor_representation(buffer, hotspot) } } diff --git a/src/backend/graphics/cursor.rs b/src/backend/graphics/cursor.rs index 7be3bc0..f1ff46c 100644 --- a/src/backend/graphics/cursor.rs +++ b/src/backend/graphics/cursor.rs @@ -4,18 +4,18 @@ /// where possible. This may however be quite restrictive in terms of supported formats. /// /// For those reasons you may always choose to render your cursor(s) (partially) in software instead. -pub trait CursorBackend<'a> { +pub trait CursorBackend { /// Format representing the image drawn for the cursor. - type CursorFormat: 'a; + type CursorFormat: ?Sized; /// Error the underlying backend throws if operations fail - type Error; + type Error: 'static; /// Sets the cursor position and therefore updates the drawn cursors position. /// Useful as well for e.g. pointer wrapping. /// /// Not guaranteed to be supported on every backend. The result usually - /// depends on the backend, the cursor might be "owned" by another more priviledged + /// depends on the backend, the cursor might be "owned" by another more privileged /// compositor (running nested). /// /// In these cases setting the position is actually not required, as movement is done @@ -29,11 +29,9 @@ pub trait CursorBackend<'a> { /// The format is entirely dictated by the concrete implementation and might range /// from raw image buffers over a fixed list of possible cursor types to simply the /// void type () to represent no possible customization of the cursor itself. - fn set_cursor_representation<'b>( - &'b self, - cursor: Self::CursorFormat, + fn set_cursor_representation( + &self, + cursor: &Self::CursorFormat, hotspot: (u32, u32), - ) -> Result<(), Self::Error> - where - 'a: 'b; + ) -> Result<(), Self::Error>; }