mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
74 lines
2.0 KiB
Rust
74 lines
2.0 KiB
Rust
use smithay::backend::allocator::dmabuf::Dmabuf;
|
|
use smithay::backend::renderer::gles::{GlesFrame, GlesRenderer, GlesTexture};
|
|
use smithay::backend::renderer::{
|
|
Bind, ExportMem, ImportAll, ImportMem, Offscreen, Renderer, Texture,
|
|
};
|
|
|
|
use crate::backend::tty::{TtyFrame, TtyRenderer};
|
|
|
|
/// Trait with our main renderer requirements to save on the typing.
|
|
pub trait NiriRenderer:
|
|
ImportAll
|
|
+ ImportMem
|
|
+ ExportMem
|
|
+ Bind<Dmabuf>
|
|
+ Offscreen<GlesTexture>
|
|
+ Renderer<TextureId = Self::NiriTextureId, Error = Self::NiriError>
|
|
+ AsGlesRenderer
|
|
{
|
|
// Associated types to work around the instability of associated type bounds.
|
|
type NiriTextureId: Texture + Clone + 'static;
|
|
type NiriError: std::error::Error
|
|
+ Send
|
|
+ Sync
|
|
+ From<<GlesRenderer as Renderer>::Error>
|
|
+ 'static;
|
|
}
|
|
|
|
impl<R> NiriRenderer for R
|
|
where
|
|
R: ImportAll + ImportMem + ExportMem + Bind<Dmabuf> + Offscreen<GlesTexture> + AsGlesRenderer,
|
|
R::TextureId: Texture + Clone + 'static,
|
|
R::Error: std::error::Error + Send + Sync + From<<GlesRenderer as Renderer>::Error> + 'static,
|
|
{
|
|
type NiriTextureId = R::TextureId;
|
|
type NiriError = R::Error;
|
|
}
|
|
|
|
/// Trait for getting the underlying `GlesRenderer`.
|
|
pub trait AsGlesRenderer {
|
|
fn as_gles_renderer(&mut self) -> &mut GlesRenderer;
|
|
}
|
|
|
|
impl AsGlesRenderer for GlesRenderer {
|
|
fn as_gles_renderer(&mut self) -> &mut GlesRenderer {
|
|
self
|
|
}
|
|
}
|
|
|
|
impl<'render> AsGlesRenderer for TtyRenderer<'render> {
|
|
fn as_gles_renderer(&mut self) -> &mut GlesRenderer {
|
|
self.as_mut()
|
|
}
|
|
}
|
|
|
|
/// Trait for getting the underlying `GlesFrame`.
|
|
pub trait AsGlesFrame<'frame>
|
|
where
|
|
Self: 'frame,
|
|
{
|
|
fn as_gles_frame(&mut self) -> &mut GlesFrame<'frame>;
|
|
}
|
|
|
|
impl<'frame> AsGlesFrame<'frame> for GlesFrame<'frame> {
|
|
fn as_gles_frame(&mut self) -> &mut GlesFrame<'frame> {
|
|
self
|
|
}
|
|
}
|
|
|
|
impl<'render, 'frame> AsGlesFrame<'frame> for TtyFrame<'render, 'frame> {
|
|
fn as_gles_frame(&mut self) -> &mut GlesFrame<'frame> {
|
|
self.as_mut()
|
|
}
|
|
}
|