render: hide graphics API behind traits
This commit is contained in:
parent
d650b3375d
commit
24e410a5b5
40 changed files with 601 additions and 246 deletions
140
src/gfx_api.rs
140
src/gfx_api.rs
|
|
@ -1,6 +1,25 @@
|
|||
use {
|
||||
crate::{format::Format, gfx_apis::gl::Texture, theme::Color},
|
||||
std::rc::Rc,
|
||||
crate::{
|
||||
cursor::Cursor,
|
||||
format::Format,
|
||||
rect::Rect,
|
||||
renderer::{renderer_base::RendererBase, RenderResult},
|
||||
scale::Scale,
|
||||
state::State,
|
||||
theme::Color,
|
||||
tree::Node,
|
||||
video::{dmabuf::DmaBuf, gbm::GbmDevice},
|
||||
},
|
||||
ahash::AHashMap,
|
||||
std::{
|
||||
any::Any,
|
||||
cell::Cell,
|
||||
error::Error,
|
||||
ffi::CString,
|
||||
fmt::{Debug, Formatter},
|
||||
rc::Rc,
|
||||
},
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub enum GfxApiOpt {
|
||||
|
|
@ -77,8 +96,123 @@ pub struct FillRect {
|
|||
}
|
||||
|
||||
pub struct CopyTexture {
|
||||
pub tex: Rc<Texture>,
|
||||
pub tex: Rc<dyn GfxTexture>,
|
||||
pub format: &'static Format,
|
||||
pub source: BufferPoints,
|
||||
pub target: AbsoluteRect,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum ResetStatus {
|
||||
Guilty,
|
||||
Innocent,
|
||||
Unknown,
|
||||
Other(u32),
|
||||
}
|
||||
|
||||
pub trait GfxFramebuffer: Debug {
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
fn clear(&self);
|
||||
|
||||
fn clear_with(&self, r: f32, g: f32, b: f32, a: f32);
|
||||
|
||||
fn copy_texture(
|
||||
&self,
|
||||
state: &State,
|
||||
texture: &Rc<dyn GfxTexture>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
alpha: bool,
|
||||
);
|
||||
|
||||
fn copy_to_shm(
|
||||
&self,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
format: &Format,
|
||||
shm: &[Cell<u8>],
|
||||
);
|
||||
|
||||
fn render_custom(&self, scale: Scale, f: &mut dyn FnMut(&mut RendererBase));
|
||||
|
||||
fn render(
|
||||
&self,
|
||||
node: &dyn Node,
|
||||
state: &State,
|
||||
cursor_rect: Option<Rect>,
|
||||
on_output: bool,
|
||||
result: &mut RenderResult,
|
||||
scale: Scale,
|
||||
render_hardware_cursor: bool,
|
||||
);
|
||||
|
||||
fn render_hardware_cursor(&self, cursor: &dyn Cursor, state: &State, scale: Scale);
|
||||
}
|
||||
|
||||
pub trait GfxImage {
|
||||
fn to_framebuffer(self: Rc<Self>) -> Result<Rc<dyn GfxFramebuffer>, GfxError>;
|
||||
|
||||
fn to_texture(self: Rc<Self>) -> Result<Rc<dyn GfxTexture>, GfxError>;
|
||||
|
||||
fn width(&self) -> i32;
|
||||
fn height(&self) -> i32;
|
||||
}
|
||||
|
||||
pub trait GfxTexture: Debug {
|
||||
fn width(&self) -> i32;
|
||||
fn height(&self) -> i32;
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
}
|
||||
|
||||
pub trait GfxContext: Debug {
|
||||
fn take_render_ops(&self) -> Vec<GfxApiOpt>;
|
||||
|
||||
fn reset_status(&self) -> Option<ResetStatus>;
|
||||
|
||||
fn supports_external_texture(&self) -> bool;
|
||||
|
||||
fn render_node(&self) -> Rc<CString>;
|
||||
|
||||
fn formats(&self) -> Rc<AHashMap<u32, GfxFormat>>;
|
||||
|
||||
fn dmabuf_fb(self: Rc<Self>, buf: &DmaBuf) -> Result<Rc<dyn GfxFramebuffer>, GfxError>;
|
||||
|
||||
fn dmabuf_img(self: Rc<Self>, buf: &DmaBuf) -> Result<Rc<dyn GfxImage>, GfxError>;
|
||||
|
||||
fn shmem_texture(
|
||||
self: Rc<Self>,
|
||||
data: &[Cell<u8>],
|
||||
format: &'static Format,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
) -> Result<Rc<dyn GfxTexture>, GfxError>;
|
||||
|
||||
fn gbm(&self) -> &GbmDevice;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GfxFormat {
|
||||
pub format: &'static Format,
|
||||
pub implicit_external_only: bool,
|
||||
pub modifiers: AHashMap<u64, GfxModifier>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GfxModifier {
|
||||
pub modifier: u64,
|
||||
pub external_only: bool,
|
||||
}
|
||||
|
||||
#[derive(Error)]
|
||||
#[error(transparent)]
|
||||
pub struct GfxError(pub Box<dyn Error>);
|
||||
|
||||
impl Debug for GfxError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Debug::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue