From df2722437259b708912017ac16c8e092d64b51fa Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sun, 19 Apr 2020 01:26:45 +0200 Subject: [PATCH] gbm: implement CursorBackend generically --- src/backend/drm/gbm/surface.rs | 41 +++++++++------------------------- src/backend/winit.rs | 15 +++++-------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/src/backend/drm/gbm/surface.rs b/src/backend/drm/gbm/surface.rs index dd2709f..ef682d5 100644 --- a/src/backend/drm/gbm/surface.rs +++ b/src/backend/drm/gbm/surface.rs @@ -6,11 +6,8 @@ use gbm::{self, BufferObject, BufferObjectFlags, Format as GbmFormat, SurfaceBuf use image::{ImageBuffer, Rgba}; use std::cell::{Cell, RefCell}; -use std::os::unix::io::AsRawFd; use std::rc::Rc; -#[cfg(feature = "backend_drm_legacy")] -use crate::backend::drm::legacy::LegacyDrmDevice; use crate::backend::graphics::CursorBackend; use crate::backend::graphics::SwapBuffersError; @@ -172,32 +169,12 @@ impl Surface for GbmSurfaceInternal { } } -// FIXME: -// -// Option 1: When there is GAT support, impl `GraphicsBackend` for `LegacyDrmBackend` -// using a new generic `B: Buffer` and use this: -/* -impl<'a, D: RawDevice + 'static> CursorBackend<'a> for GbmSurfaceInternal +#[cfg(feature = "backend_drm")] +impl CursorBackend for GbmSurfaceInternal where - ::Surface: CursorBackend<'a>, - <::Surface as CursorBackend<'a>>::CursorFormat: Buffer, - <::Surface as CursorBackend<'a>>::Error: ::std::error::Error + Send + ::Surface: CursorBackend, + <::Surface as CursorBackend>::Error: ::std::error::Error + Send, { -*/ -// -// Option 2: When equality checks in where clauses are supported, we could at least do this: -/* -impl<'a, D: RawDevice + 'static> GraphicsBackend<'a> for GbmSurfaceInternal -where - ::Surface: CursorBackend<'a>, - <::Surface as CursorBackend<'a>>::CursorFormat=&'a Buffer, - <::Surface as CursorBackend<'a>>::Error: ::std::error::Error + Send -{ -*/ -// But for now got to do this: - -#[cfg(feature = "backend_drm_legacy")] -impl CursorBackend for GbmSurfaceInternal> { type CursorFormat = ImageBuffer, Vec>; type Error = Error<<::Surface as CursorBackend>::Error>; @@ -346,10 +323,14 @@ impl Surface for GbmSurface { } } -#[cfg(feature = "backend_drm_legacy")] -impl CursorBackend for GbmSurface> { +#[cfg(feature = "backend_drm")] +impl CursorBackend for GbmSurface +where + ::Surface: CursorBackend, + <::Surface as CursorBackend>::Error: ::std::error::Error + Send, +{ type CursorFormat = ImageBuffer, Vec>; - type Error = ::Error; + type Error = Error<<::Surface as CursorBackend>::Error>; fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> { self.0.set_cursor_position(x, y) diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 4c4e6ea..c1960bb 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -247,8 +247,8 @@ impl WinitGraphicsBackend { } } -impl<'a> CursorBackend<'a> for WinitGraphicsBackend { - type CursorFormat = &'a CursorIcon; +impl CursorBackend for WinitGraphicsBackend { + type CursorFormat = CursorIcon; type Error = (); fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), ()> { @@ -261,14 +261,11 @@ impl<'a> CursorBackend<'a> for WinitGraphicsBackend { }) } - fn set_cursor_representation<'b>( - &'b self, - cursor: Self::CursorFormat, + fn set_cursor_representation( + &self, + cursor: &Self::CursorFormat, _hotspot: (u32, u32), - ) -> ::std::result::Result<(), ()> - where - 'a: 'b, - { + ) -> ::std::result::Result<(), ()> { // Cannot log this one, as `CursorFormat` is not `Debug` and should not be debug!(self.logger, "Changing cursor representation"); self.window.window().set_cursor_icon(*cursor);