render: hide graphics API behind traits
This commit is contained in:
parent
d650b3375d
commit
24e410a5b5
40 changed files with 601 additions and 246 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
gfx_apis::gl::RenderContext,
|
||||
gfx_apis::create_gfx_context,
|
||||
ifs::wl_seat::POINTER,
|
||||
portal::{
|
||||
ptl_render_ctx::PortalRenderCtx, ptl_screencast::ScreencastSession,
|
||||
|
|
@ -169,7 +169,7 @@ impl UsrJayRenderCtxOwner for PortalDisplay {
|
|||
}
|
||||
if self.render_ctx.get().is_none() {
|
||||
let drm = Drm::open_existing(fd);
|
||||
let ctx = match RenderContext::from_drm_device(&drm) {
|
||||
let ctx = match create_gfx_context(&drm) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
|
|
@ -179,10 +179,7 @@ impl UsrJayRenderCtxOwner for PortalDisplay {
|
|||
return;
|
||||
}
|
||||
};
|
||||
let ctx = Rc::new(PortalRenderCtx {
|
||||
dev_id,
|
||||
ctx: Rc::new(ctx),
|
||||
});
|
||||
let ctx = Rc::new(PortalRenderCtx { dev_id, ctx });
|
||||
self.render_ctx.set(Some(ctx.clone()));
|
||||
self.state.render_ctxs.set(dev_id, Rc::downgrade(&ctx));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use {crate::gfx_apis::gl::RenderContext, std::rc::Rc, uapi::c};
|
||||
use {crate::gfx_api::GfxContext, std::rc::Rc, uapi::c};
|
||||
|
||||
pub struct PortalRenderCtx {
|
||||
pub dev_id: c::dev_t,
|
||||
pub ctx: Rc<RenderContext>,
|
||||
pub ctx: Rc<dyn GfxContext>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use {
|
|||
cursor::KnownCursor,
|
||||
fixed::Fixed,
|
||||
format::ARGB8888,
|
||||
gfx_apis::gl::{Framebuffer, RenderContext, Texture},
|
||||
gfx_api::{GfxContext, GfxFramebuffer, GfxTexture},
|
||||
ifs::zwlr_layer_shell_v1::OVERLAY,
|
||||
portal::ptl_display::{PortalDisplay, PortalOutput, PortalSeat},
|
||||
renderer::renderer_base::RendererBase,
|
||||
|
|
@ -50,7 +50,7 @@ pub trait GuiElement {
|
|||
fn data(&self) -> &GuiElementData;
|
||||
fn layout(
|
||||
&self,
|
||||
ctx: &Rc<RenderContext>,
|
||||
ctx: &Rc<dyn GfxContext>,
|
||||
scale: f32,
|
||||
max_width: f32,
|
||||
max_height: f32,
|
||||
|
|
@ -118,7 +118,7 @@ pub struct Button {
|
|||
pub bg_hover_color: Cell<Color>,
|
||||
pub text: RefCell<String>,
|
||||
pub font: RefCell<Cow<'static, str>>,
|
||||
pub tex: CloneCell<Option<Rc<Texture>>>,
|
||||
pub tex: CloneCell<Option<Rc<dyn GfxTexture>>>,
|
||||
pub owner: CloneCell<Option<Rc<dyn ButtonOwner>>>,
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ impl GuiElement for Button {
|
|||
|
||||
fn layout(
|
||||
&self,
|
||||
ctx: &Rc<RenderContext>,
|
||||
ctx: &Rc<dyn GfxContext>,
|
||||
scale: f32,
|
||||
_max_width: f32,
|
||||
_max_height: f32,
|
||||
|
|
@ -260,7 +260,7 @@ pub struct Label {
|
|||
pub data: GuiElementData,
|
||||
pub font: RefCell<Cow<'static, str>>,
|
||||
pub text: RefCell<String>,
|
||||
pub tex: CloneCell<Option<Rc<Texture>>>,
|
||||
pub tex: CloneCell<Option<Rc<dyn GfxTexture>>>,
|
||||
}
|
||||
|
||||
impl Default for Label {
|
||||
|
|
@ -281,7 +281,7 @@ impl GuiElement for Label {
|
|||
|
||||
fn layout(
|
||||
&self,
|
||||
ctx: &Rc<RenderContext>,
|
||||
ctx: &Rc<dyn GfxContext>,
|
||||
scale: f32,
|
||||
_max_width: f32,
|
||||
_max_height: f32,
|
||||
|
|
@ -364,7 +364,7 @@ impl GuiElement for Flow {
|
|||
|
||||
fn layout(
|
||||
&self,
|
||||
ctx: &Rc<RenderContext>,
|
||||
ctx: &Rc<dyn GfxContext>,
|
||||
scale: f32,
|
||||
max_width: f32,
|
||||
max_height: f32,
|
||||
|
|
@ -638,7 +638,7 @@ impl WindowData {
|
|||
self.have_frame.set(false);
|
||||
buf.free.set(false);
|
||||
|
||||
buf.fb.render_custom(self.scale.get(), |r| {
|
||||
buf.fb.render_custom(self.scale.get(), &mut |r| {
|
||||
r.clear(&Color::from_gray(0));
|
||||
if let Some(content) = self.content.get() {
|
||||
content.render_at(r, 0.0, 0.0)
|
||||
|
|
@ -700,7 +700,7 @@ impl WindowData {
|
|||
};
|
||||
let bo = match ctx
|
||||
.ctx
|
||||
.gbm
|
||||
.gbm()
|
||||
.create_bo(width, height, &format, GBM_BO_USE_RENDERING)
|
||||
{
|
||||
Ok(b) => b,
|
||||
|
|
@ -709,7 +709,7 @@ impl WindowData {
|
|||
return;
|
||||
}
|
||||
};
|
||||
let img = match ctx.ctx.dmabuf_img(bo.dmabuf()) {
|
||||
let img = match ctx.ctx.clone().dmabuf_img(bo.dmabuf()) {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
log::error!("Could not import dmabuf into EGL: {}", ErrorFmt(e));
|
||||
|
|
@ -814,14 +814,14 @@ impl WindowData {
|
|||
pub struct GuiBuffer {
|
||||
pub wl: Rc<UsrWlBuffer>,
|
||||
pub window: Rc<WindowData>,
|
||||
pub fb: Rc<Framebuffer>,
|
||||
pub fb: Rc<dyn GfxFramebuffer>,
|
||||
pub free: Cell<bool>,
|
||||
pub size: (i32, i32),
|
||||
}
|
||||
|
||||
struct GuiBufferPending {
|
||||
pub window: Rc<WindowData>,
|
||||
pub fb: Rc<Framebuffer>,
|
||||
pub fb: Rc<dyn GfxFramebuffer>,
|
||||
pub params: Rc<UsrLinuxBufferParams>,
|
||||
pub size: (i32, i32),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue