Merge pull request #369 from i509VCB/anvil_render_fn
anvil: Split out logic for drawing layers and windows from backends
This commit is contained in:
commit
cc48759338
|
@ -14,6 +14,8 @@ pub mod cursor;
|
|||
pub mod drawing;
|
||||
pub mod input_handler;
|
||||
pub mod output_map;
|
||||
#[cfg(any(feature = "udev", feature = "winit"))]
|
||||
pub mod render;
|
||||
pub mod shell;
|
||||
pub mod state;
|
||||
#[cfg(feature = "udev")]
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
use slog::Logger;
|
||||
use smithay::{
|
||||
backend::{
|
||||
renderer::{
|
||||
gles2::{Gles2Frame, Gles2Renderer},
|
||||
Frame,
|
||||
},
|
||||
SwapBuffersError,
|
||||
},
|
||||
utils::{Logical, Rectangle},
|
||||
wayland::shell::wlr_layer::Layer,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
drawing::{draw_layers, draw_windows},
|
||||
window_map::WindowMap,
|
||||
};
|
||||
|
||||
pub fn render_layers_and_windows(
|
||||
renderer: &mut Gles2Renderer,
|
||||
frame: &mut Gles2Frame,
|
||||
window_map: &WindowMap,
|
||||
output_geometry: Rectangle<i32, Logical>,
|
||||
output_scale: f32,
|
||||
logger: &Logger,
|
||||
) -> Result<(), SwapBuffersError> {
|
||||
frame.clear([0.8, 0.8, 0.9, 1.0])?;
|
||||
|
||||
for layer in [Layer::Background, Layer::Bottom] {
|
||||
draw_layers(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
layer,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
logger,
|
||||
)?;
|
||||
}
|
||||
|
||||
draw_windows(renderer, frame, window_map, output_geometry, output_scale, logger)?;
|
||||
|
||||
for layer in [Layer::Top, Layer::Overlay] {
|
||||
draw_layers(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
layer,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
logger,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -55,7 +55,6 @@ use smithay::{
|
|||
wayland::{
|
||||
output::{Mode, PhysicalProperties},
|
||||
seat::CursorImageStatus,
|
||||
shell::wlr_layer::Layer,
|
||||
},
|
||||
};
|
||||
#[cfg(feature = "egl")]
|
||||
|
@ -68,8 +67,11 @@ use smithay::{
|
|||
wayland::dmabuf::init_dmabuf_global,
|
||||
};
|
||||
|
||||
use crate::state::{AnvilState, Backend};
|
||||
use crate::{drawing::*, window_map::WindowMap};
|
||||
use crate::{
|
||||
render::render_layers_and_windows,
|
||||
state::{AnvilState, Backend},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SessionFd(RawFd);
|
||||
|
@ -738,40 +740,21 @@ fn render_surface(
|
|||
|
||||
let dmabuf = surface.surface.next_buffer()?;
|
||||
renderer.bind(dmabuf)?;
|
||||
|
||||
// and draw to our buffer
|
||||
match renderer
|
||||
.render(
|
||||
mode.size,
|
||||
Transform::Flipped180, // Scanout is rotated
|
||||
|renderer, frame| {
|
||||
frame.clear([0.8, 0.8, 0.9, 1.0])?;
|
||||
|
||||
for layer in [Layer::Background, Layer::Bottom] {
|
||||
draw_layers(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
layer,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
logger,
|
||||
)?;
|
||||
}
|
||||
|
||||
// draw the surfaces
|
||||
draw_windows(renderer, frame, window_map, output_geometry, output_scale, logger)?;
|
||||
|
||||
for layer in [Layer::Top, Layer::Overlay] {
|
||||
draw_layers(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
layer,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
logger,
|
||||
)?;
|
||||
}
|
||||
render_layers_and_windows(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
logger,
|
||||
)?;
|
||||
|
||||
// set cursor
|
||||
if output_geometry.to_f64().contains(pointer_location) {
|
||||
|
@ -793,6 +776,7 @@ fn render_surface(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw the cursor as relevant
|
||||
{
|
||||
// reset the cursor if the surface is no longer alive
|
||||
|
@ -827,19 +811,21 @@ fn render_surface(
|
|||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
draw_fps(
|
||||
renderer,
|
||||
frame,
|
||||
fps_texture,
|
||||
output_scale as f64,
|
||||
surface.fps.avg().round() as u32,
|
||||
)?;
|
||||
|
||||
surface.fps.tick();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
draw_fps(
|
||||
renderer,
|
||||
frame,
|
||||
fps_texture,
|
||||
output_scale as f64,
|
||||
surface.fps.avg().round() as u32,
|
||||
)?;
|
||||
surface.fps.tick();
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
|
|
|
@ -8,7 +8,7 @@ use smithay::{
|
|||
wayland::dmabuf::init_dmabuf_global,
|
||||
};
|
||||
use smithay::{
|
||||
backend::{input::InputBackend, renderer::Frame, winit, SwapBuffersError},
|
||||
backend::{input::InputBackend, winit, SwapBuffersError},
|
||||
reexports::{
|
||||
calloop::EventLoop,
|
||||
wayland_server::{protocol::wl_output, Display},
|
||||
|
@ -16,14 +16,13 @@ use smithay::{
|
|||
wayland::{
|
||||
output::{Mode, PhysicalProperties},
|
||||
seat::CursorImageStatus,
|
||||
shell::wlr_layer::Layer,
|
||||
},
|
||||
};
|
||||
|
||||
use slog::Logger;
|
||||
|
||||
use crate::drawing::*;
|
||||
use crate::state::{AnvilState, Backend};
|
||||
use crate::{drawing::*, render::render_layers_and_windows};
|
||||
|
||||
pub const OUTPUT_NAME: &str = "winit";
|
||||
|
||||
|
@ -143,38 +142,17 @@ pub fn run_winit(log: Logger) {
|
|||
|
||||
let result = renderer
|
||||
.render(|renderer, frame| {
|
||||
frame.clear([0.8, 0.8, 0.9, 1.0])?;
|
||||
|
||||
let window_map = &*state.window_map.borrow();
|
||||
|
||||
for layer in [Layer::Background, Layer::Bottom] {
|
||||
draw_layers(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
layer,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
&log,
|
||||
)?;
|
||||
}
|
||||
|
||||
// draw the windows
|
||||
draw_windows(renderer, frame, window_map, output_geometry, output_scale, &log)?;
|
||||
|
||||
for layer in [Layer::Top, Layer::Overlay] {
|
||||
draw_layers(
|
||||
renderer,
|
||||
frame,
|
||||
window_map,
|
||||
layer,
|
||||
output_geometry,
|
||||
output_scale,
|
||||
&log,
|
||||
)?;
|
||||
}
|
||||
render_layers_and_windows(
|
||||
renderer,
|
||||
frame,
|
||||
&*state.window_map.borrow(),
|
||||
output_geometry,
|
||||
output_scale,
|
||||
&log,
|
||||
)?;
|
||||
|
||||
let (x, y) = state.pointer_location.into();
|
||||
|
||||
// draw the dnd icon if any
|
||||
{
|
||||
let guard = state.dnd_icon.lock().unwrap();
|
||||
|
@ -222,6 +200,7 @@ pub fn run_winit(log: Logger) {
|
|||
#[cfg(feature = "debug")]
|
||||
{
|
||||
let fps = state.backend_data.fps.avg().round() as u32;
|
||||
|
||||
draw_fps(
|
||||
renderer,
|
||||
frame,
|
||||
|
|
Loading…
Reference in New Issue