1
0
Fork 0
forked from wry/wry

render: split rendering into two phases

In the first phase we collect a list of simple operations (copying
textures and filling rectangles.)

In the second phase we send this list to the graphics API to be
executed.

As part of this, we also remove the use of scissors.
This commit is contained in:
Julian Orth 2023-10-22 16:10:10 +02:00
parent a2a04512ed
commit 5e8a6eb86f
27 changed files with 732 additions and 384 deletions

View file

@ -12,7 +12,10 @@ use {
GL_FRAMEBUFFER,
},
},
renderer::{context::RenderContext, renderer::Renderer, renderer_base::RendererBase},
renderer::{
context::RenderContext, gfx_apis::gl::run_ops, renderer::Renderer,
renderer_base::RendererBase,
},
sys::{glBlendFunc, glFlush, glReadnPixels, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
RenderResult, Texture,
},
@ -55,7 +58,31 @@ impl Framebuffer {
});
}
pub fn copy_texture(&self, state: &State, texture: &Texture, x: i32, y: i32, alpha: bool) {
pub fn copy_texture(&self, state: &State, texture: &Rc<Texture>, x: i32, y: i32, alpha: bool) {
let mut ops = self.ctx.gfx_ops.borrow_mut();
ops.clear();
let scale = Scale::from_int(1);
let extents = Rect::new_sized(0, 0, self.gl.width, self.gl.height).unwrap();
let mut renderer = Renderer {
base: RendererBase {
ops: &mut ops,
scaled: false,
scale,
scalef: 1.0,
},
state,
on_output: false,
result: &mut RenderResult::default(),
logical_extents: extents,
physical_extents: extents,
};
let format = match alpha {
true => ARGB8888,
false => XRGB8888,
};
renderer
.base
.render_texture(texture, x, y, format, None, None, scale, i32::MAX, i32::MAX);
let _ = self.ctx.ctx.with_current(|| {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);
@ -66,27 +93,7 @@ impl Framebuffer {
}
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let scale = Scale::from_int(1);
let mut renderer = Renderer {
base: RendererBase {
ctx: &self.ctx,
fb: &self.gl,
scaled: false,
scale,
scalef: 1.0,
},
state,
on_output: false,
result: &mut RenderResult::default(),
logical_extents: Rect::new_sized(0, 0, self.gl.width, self.gl.height).unwrap(),
};
let format = match alpha {
true => ARGB8888,
false => XRGB8888,
};
renderer
.base
.render_texture(texture, x, y, format, None, None, scale);
run_ops(self, &ops);
unsafe {
glFlush();
}
@ -124,20 +131,22 @@ impl Framebuffer {
}
pub fn render_custom(&self, scale: Scale, f: impl FnOnce(&mut RendererBase)) {
let mut ops = self.ctx.gfx_ops.borrow_mut();
ops.clear();
let mut renderer = RendererBase {
ops: &mut ops,
scaled: scale != 1,
scale,
scalef: scale.to_f64(),
};
f(&mut renderer);
let _ = self.ctx.ctx.with_current(|| {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);
glViewport(0, 0, self.gl.width, self.gl.height);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let mut renderer = RendererBase {
ctx: &self.ctx,
fb: &self.gl,
scaled: scale != 1,
scale,
scalef: scale.to_f64(),
};
f(&mut renderer);
run_ops(self, &ops);
unsafe {
glFlush();
}
@ -155,6 +164,47 @@ impl Framebuffer {
scale: Scale,
render_hardware_cursor: bool,
) {
let mut ops = self.ctx.gfx_ops.borrow_mut();
ops.clear();
let mut renderer = Renderer {
base: RendererBase {
ops: &mut ops,
scaled: scale != 1,
scale,
scalef: scale.to_f64(),
},
state,
on_output,
result,
logical_extents: node.node_absolute_position().at_point(0, 0),
physical_extents: Rect::new(0, 0, self.gl.width, self.gl.height).unwrap(),
};
node.node_render(&mut renderer, 0, 0, i32::MAX, i32::MAX);
if let Some(rect) = cursor_rect {
let seats = state.globals.lock_seats();
for seat in seats.values() {
if !render_hardware_cursor && seat.hardware_cursor() {
continue;
}
if let Some(cursor) = seat.get_cursor() {
let (mut x, mut y) = seat.get_position();
if let Some(dnd_icon) = seat.dnd_icon() {
let extents = dnd_icon.extents.get().move_(
x.round_down() + dnd_icon.buf_x.get(),
y.round_down() + dnd_icon.buf_y.get(),
);
if extents.intersects(&rect) {
let (x, y) = rect.translate(extents.x1(), extents.y1());
renderer.render_surface(&dnd_icon, x, y, i32::MAX, i32::MAX);
}
}
cursor.tick();
x -= Fixed::from_int(rect.x1());
y -= Fixed::from_int(rect.y1());
cursor.render(&mut renderer, x, y);
}
}
}
let _ = self.ctx.ctx.with_current(|| {
let c = state.theme.colors.background.get();
unsafe {
@ -164,45 +214,7 @@ impl Framebuffer {
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let mut renderer = Renderer {
base: RendererBase {
ctx: &self.ctx,
fb: &self.gl,
scaled: scale != 1,
scale,
scalef: scale.to_f64(),
},
state,
on_output,
result,
logical_extents: node.node_absolute_position().at_point(0, 0),
};
node.node_render(&mut renderer, 0, 0);
if let Some(rect) = cursor_rect {
let seats = state.globals.lock_seats();
for seat in seats.values() {
if !render_hardware_cursor && seat.hardware_cursor() {
continue;
}
if let Some(cursor) = seat.get_cursor() {
let (mut x, mut y) = seat.get_position();
if let Some(dnd_icon) = seat.dnd_icon() {
let extents = dnd_icon.extents.get().move_(
x.round_down() + dnd_icon.buf_x.get(),
y.round_down() + dnd_icon.buf_y.get(),
);
if extents.intersects(&rect) {
let (x, y) = rect.translate(extents.x1(), extents.y1());
renderer.render_surface(&dnd_icon, x, y);
}
}
cursor.tick();
x -= Fixed::from_int(rect.x1());
y -= Fixed::from_int(rect.y1());
cursor.render(&mut renderer, x, y);
}
}
}
run_ops(self, &ops);
unsafe {
glFlush();
}
@ -211,6 +223,23 @@ impl Framebuffer {
}
pub fn render_hardware_cursor(&self, cursor: &dyn Cursor, state: &State, scale: Scale) {
let mut ops = self.ctx.gfx_ops.borrow_mut();
ops.clear();
let mut res = RenderResult::default();
let mut renderer = Renderer {
base: RendererBase {
ops: &mut ops,
scaled: scale != 1,
scale,
scalef: scale.to_f64(),
},
state,
on_output: false,
result: &mut res,
logical_extents: Rect::new_empty(0, 0),
physical_extents: Rect::new(0, 0, self.gl.width, self.gl.height).unwrap(),
};
cursor.render_hardware_cursor(&mut renderer);
let _ = self.ctx.ctx.with_current(|| {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);
@ -219,21 +248,7 @@ impl Framebuffer {
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let mut res = RenderResult::default();
let mut renderer = Renderer {
base: RendererBase {
ctx: &self.ctx,
fb: &self.gl,
scaled: scale != 1,
scale,
scalef: scale.to_f64(),
},
state,
on_output: false,
result: &mut res,
logical_extents: Rect::new_empty(0, 0),
};
cursor.render_hardware_cursor(&mut renderer);
run_ops(self, &ops);
unsafe {
glFlush();
}