use crate::{Color, Error, Viewport};
use raw_window_handle::HasRawWindowHandle;
use thiserror::Error;
pub trait Compositor: Sized {
type Settings: Default;
type Renderer: iced_native::Renderer;
type Surface;
fn new<W: HasRawWindowHandle>(
settings: Self::Settings,
compatible_window: Option<&W>,
) -> Result<(Self, Self::Renderer), Error>;
fn create_surface<W: HasRawWindowHandle>(
&mut self,
window: &W,
) -> Self::Surface;
fn configure_surface(
&mut self,
surface: &mut Self::Surface,
width: u32,
height: u32,
);
fn present<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
) -> Result<(), SurfaceError>;
}
#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum SurfaceError {
#[error(
"A timeout was encountered while trying to acquire the next frame"
)]
Timeout,
#[error(
"The underlying surface has changed, and therefore the surface must be updated."
)]
Outdated,
#[error("The surface has been lost and needs to be recreated")]
Lost,
#[error("There is no more memory left to allocate a new frame")]
OutOfMemory,
}