cursor: simplify trait by removing barely utilized lifetimes

This commit is contained in:
Victor Brekenfeld 2020-04-19 01:26:09 +02:00
parent 8ba33f2473
commit cde06eb99a
4 changed files with 39 additions and 56 deletions

View File

@ -62,25 +62,22 @@ where
} }
} }
impl<'a, N> CursorBackend<'a> for EglSurface<N> impl<N> CursorBackend for EglSurface<N>
where where
N: NativeSurface + Surface + CursorBackend<'a>, N: NativeSurface + Surface + CursorBackend,
{ {
type CursorFormat = <N as CursorBackend<'a>>::CursorFormat; type CursorFormat = <N as CursorBackend>::CursorFormat;
type Error = <N as CursorBackend<'a>>::Error; type Error = <N as CursorBackend>::Error;
fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), Self::Error> { fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), Self::Error> {
self.surface.set_cursor_position(x, y) self.surface.set_cursor_position(x, y)
} }
fn set_cursor_representation<'b>( fn set_cursor_representation(
&'b self, &self,
buffer: Self::CursorFormat, buffer: &Self::CursorFormat,
hotspot: (u32, u32), hotspot: (u32, u32),
) -> ::std::result::Result<(), Self::Error> ) -> ::std::result::Result<(), Self::Error> {
where
'a: 'b,
{
self.surface.set_cursor_representation(buffer, hotspot) self.surface.set_cursor_representation(buffer, hotspot)
} }
} }

View File

@ -197,22 +197,19 @@ where
// But for now got to do this: // But for now got to do this:
#[cfg(feature = "backend_drm_legacy")] #[cfg(feature = "backend_drm_legacy")]
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurfaceInternal<LegacyDrmDevice<A>> { impl<A: AsRawFd + 'static> CursorBackend for GbmSurfaceInternal<LegacyDrmDevice<A>> {
type CursorFormat = &'a ImageBuffer<Rgba<u8>, Vec<u8>>; type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = Error<<<LegacyDrmDevice<A> as Device>::Surface as Surface>::Error>; type Error = Error<<<D as Device>::Surface as CursorBackend>::Error>;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> { fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> {
self.crtc.set_cursor_position(x, y).map_err(Error::Underlying) self.crtc.set_cursor_position(x, y).map_err(Error::Underlying)
} }
fn set_cursor_representation<'b>( fn set_cursor_representation(
&'b self, &self,
buffer: &ImageBuffer<Rgba<u8>, Vec<u8>>, buffer: &ImageBuffer<Rgba<u8>, Vec<u8>>,
hotspot: (u32, u32), hotspot: (u32, u32),
) -> Result<(), Self::Error> ) -> Result<(), Self::Error> {
where
'a: 'b,
{
let (w, h) = buffer.dimensions(); let (w, h) = buffer.dimensions();
debug!(self.logger, "Importing cursor"); debug!(self.logger, "Importing cursor");
@ -350,22 +347,19 @@ impl<D: RawDevice + 'static> Surface for GbmSurface<D> {
} }
#[cfg(feature = "backend_drm_legacy")] #[cfg(feature = "backend_drm_legacy")]
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface<LegacyDrmDevice<A>> { impl<A: AsRawFd + 'static> CursorBackend for GbmSurface<LegacyDrmDevice<A>> {
type CursorFormat = &'a ImageBuffer<Rgba<u8>, Vec<u8>>; type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = <Self as Surface>::Error; type Error = <Self as Surface>::Error;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> { fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> {
self.0.set_cursor_position(x, y) self.0.set_cursor_position(x, y)
} }
fn set_cursor_representation<'b>( fn set_cursor_representation(
&'b self, &self,
buffer: &ImageBuffer<Rgba<u8>, Vec<u8>>, buffer: &ImageBuffer<Rgba<u8>, Vec<u8>>,
hotspot: (u32, u32), hotspot: (u32, u32),
) -> Result<(), Self::Error> ) -> Result<(), Self::Error> {
where
'a: 'b,
{
self.0.set_cursor_representation(buffer, hotspot) self.0.set_cursor_representation(buffer, hotspot)
} }
} }

View File

@ -41,8 +41,8 @@ impl<A: AsRawFd + 'static> AsRawFd for LegacyDrmSurfaceInternal<A> {
impl<A: AsRawFd + 'static> BasicDevice for LegacyDrmSurfaceInternal<A> {} impl<A: AsRawFd + 'static> BasicDevice for LegacyDrmSurfaceInternal<A> {}
impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmSurfaceInternal<A> {} impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmSurfaceInternal<A> {}
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal<A> { impl<A: AsRawFd + 'static> CursorBackend for LegacyDrmSurfaceInternal<A> {
type CursorFormat = &'a dyn Buffer; type CursorFormat = dyn Buffer;
type Error = Error; type Error = Error;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), 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<A>
}) })
} }
fn set_cursor_representation<'b>( fn set_cursor_representation(
&'b self, &self,
buffer: Self::CursorFormat, buffer: &Self::CursorFormat,
hotspot: (u32, u32), hotspot: (u32, u32),
) -> Result<(), Error> ) -> Result<(), Error> {
where
'a: 'b,
{
trace!(self.logger, "Setting the new imported cursor"); trace!(self.logger, "Setting the new imported cursor");
if self if self
@ -291,22 +288,19 @@ impl<A: AsRawFd + 'static> AsRawFd for LegacyDrmSurface<A> {
impl<A: AsRawFd + 'static> BasicDevice for LegacyDrmSurface<A> {} impl<A: AsRawFd + 'static> BasicDevice for LegacyDrmSurface<A> {}
impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmSurface<A> {} impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmSurface<A> {}
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurface<A> { impl<A: AsRawFd + 'static> CursorBackend for LegacyDrmSurface<A> {
type CursorFormat = &'a dyn Buffer; type CursorFormat = dyn Buffer;
type Error = Error; type Error = Error;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Error> { fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Error> {
self.0.set_cursor_position(x, y) self.0.set_cursor_position(x, y)
} }
fn set_cursor_representation<'b>( fn set_cursor_representation(
&'b self, &self,
buffer: Self::CursorFormat, buffer: &Self::CursorFormat,
hotspot: (u32, u32), hotspot: (u32, u32),
) -> Result<(), Error> ) -> Result<(), Error> {
where
'a: 'b,
{
self.0.set_cursor_representation(buffer, hotspot) self.0.set_cursor_representation(buffer, hotspot)
} }
} }

View File

@ -4,18 +4,18 @@
/// where possible. This may however be quite restrictive in terms of supported formats. /// 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. /// 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. /// Format representing the image drawn for the cursor.
type CursorFormat: 'a; type CursorFormat: ?Sized;
/// Error the underlying backend throws if operations fail /// Error the underlying backend throws if operations fail
type Error; type Error: 'static;
/// Sets the cursor position and therefore updates the drawn cursors position. /// Sets the cursor position and therefore updates the drawn cursors position.
/// Useful as well for e.g. pointer wrapping. /// Useful as well for e.g. pointer wrapping.
/// ///
/// Not guaranteed to be supported on every backend. The result usually /// 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). /// compositor (running nested).
/// ///
/// In these cases setting the position is actually not required, as movement is done /// 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 /// 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 /// 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. /// void type () to represent no possible customization of the cursor itself.
fn set_cursor_representation<'b>( fn set_cursor_representation(
&'b self, &self,
cursor: Self::CursorFormat, cursor: &Self::CursorFormat,
hotspot: (u32, u32), hotspot: (u32, u32),
) -> Result<(), Self::Error> ) -> Result<(), Self::Error>;
where
'a: 'b;
} }