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 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<D: RawDevice + 'static> Surface for GbmSurfaceInternal<D> {
}
}
// 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<D>
#[cfg(feature = "backend_drm")]
impl<D: RawDevice + 'static> CursorBackend for GbmSurfaceInternal<D>
where
<D as RawDevice>::Surface: CursorBackend<'a>,
<<D as RawDevice>::Surface as CursorBackend<'a>>::CursorFormat: Buffer,
<<D as RawDevice>::Surface as CursorBackend<'a>>::Error: ::std::error::Error + Send
<D as RawDevice>::Surface: CursorBackend<CursorFormat = dyn drm::buffer::Buffer>,
<<D as RawDevice>::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<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 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")]
impl<A: AsRawFd + 'static> CursorBackend for GbmSurface<LegacyDrmDevice<A>> {
#[cfg(feature = "backend_drm")]
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 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> {
self.0.set_cursor_position(x, y)

View File

@ -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);