gbm: implement CursorBackend generically

This commit is contained in:
Victor Brekenfeld 2020-04-19 01:26:45 +02:00
parent cde06eb99a
commit df27224372
2 changed files with 17 additions and 39 deletions

View File

@ -6,11 +6,8 @@ use gbm::{self, BufferObject, BufferObjectFlags, Format as GbmFormat, SurfaceBuf
use image::{ImageBuffer, Rgba}; use image::{ImageBuffer, Rgba};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::os::unix::io::AsRawFd;
use std::rc::Rc; use std::rc::Rc;
#[cfg(feature = "backend_drm_legacy")]
use crate::backend::drm::legacy::LegacyDrmDevice;
use crate::backend::graphics::CursorBackend; use crate::backend::graphics::CursorBackend;
use crate::backend::graphics::SwapBuffersError; use crate::backend::graphics::SwapBuffersError;
@ -172,32 +169,12 @@ impl<D: RawDevice + 'static> Surface for GbmSurfaceInternal<D> {
} }
} }
// FIXME: #[cfg(feature = "backend_drm")]
// impl<D: RawDevice + 'static> CursorBackend for GbmSurfaceInternal<D>
// 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<D>
where where
<D as RawDevice>::Surface: CursorBackend<'a>, <D as RawDevice>::Surface: CursorBackend<CursorFormat = dyn drm::buffer::Buffer>,
<<D as RawDevice>::Surface as CursorBackend<'a>>::CursorFormat: Buffer, <<D as RawDevice>::Surface as CursorBackend>::Error: ::std::error::Error + Send,
<<D as RawDevice>::Surface as CursorBackend<'a>>::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<D>
where
<D as RawDevice>::Surface: CursorBackend<'a>,
<<D as RawDevice>::Surface as CursorBackend<'a>>::CursorFormat=&'a Buffer,
<<D as RawDevice>::Surface as CursorBackend<'a>>::Error: ::std::error::Error + Send
{
*/
// But for now got to do this:
#[cfg(feature = "backend_drm_legacy")]
impl<A: AsRawFd + 'static> CursorBackend for GbmSurfaceInternal<LegacyDrmDevice<A>> {
type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>; type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = Error<<<D as Device>::Surface as CursorBackend>::Error>; type Error = Error<<<D as Device>::Surface as CursorBackend>::Error>;
@ -346,10 +323,14 @@ impl<D: RawDevice + 'static> Surface for GbmSurface<D> {
} }
} }
#[cfg(feature = "backend_drm_legacy")] #[cfg(feature = "backend_drm")]
impl<A: AsRawFd + 'static> CursorBackend for GbmSurface<LegacyDrmDevice<A>> { impl<D: RawDevice + 'static> CursorBackend for GbmSurface<D>
where
<D as RawDevice>::Surface: CursorBackend<CursorFormat = dyn drm::buffer::Buffer>,
<<D as RawDevice>::Surface as CursorBackend>::Error: ::std::error::Error + Send,
{
type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>; type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = <Self 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.0.set_cursor_position(x, y) self.0.set_cursor_position(x, y)

View File

@ -247,8 +247,8 @@ impl WinitGraphicsBackend {
} }
} }
impl<'a> CursorBackend<'a> for WinitGraphicsBackend { impl CursorBackend for WinitGraphicsBackend {
type CursorFormat = &'a CursorIcon; type CursorFormat = CursorIcon;
type Error = (); type Error = ();
fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), ()> { 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>( fn set_cursor_representation(
&'b self, &self,
cursor: Self::CursorFormat, cursor: &Self::CursorFormat,
_hotspot: (u32, u32), _hotspot: (u32, u32),
) -> ::std::result::Result<(), ()> ) -> ::std::result::Result<(), ()> {
where
'a: 'b,
{
// Cannot log this one, as `CursorFormat` is not `Debug` and should not be // Cannot log this one, as `CursorFormat` is not `Debug` and should not be
debug!(self.logger, "Changing cursor representation"); debug!(self.logger, "Changing cursor representation");
self.window.window().set_cursor_icon(*cursor); self.window.window().set_cursor_icon(*cursor);