anvil: Split out logic for drawing layers and windows

At the moment also splitting our Drag and Drop requires unraveling some backend specific stuff.
This commit is contained in:
i509VCB 2021-08-21 16:55:10 -05:00
parent daef0a11df
commit e020347c6b
4 changed files with 96 additions and 74 deletions

View File

@ -14,6 +14,7 @@ pub mod cursor;
pub mod drawing;
pub mod input_handler;
pub mod output_map;
pub mod render;
pub mod shell;
pub mod state;
#[cfg(feature = "udev")]

56
anvil/src/render.rs Normal file
View File

@ -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(())
}

View File

@ -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(
render_layers_and_windows(
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,
)?;
}
// 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,7 +811,6 @@ fn render_surface(
)?;
}
}
}
#[cfg(feature = "debug")]
{
@ -838,8 +821,11 @@ fn render_surface(
output_scale as f64,
surface.fps.avg().round() as u32,
)?;
surface.fps.tick();
}
}
Ok(())
},
)

View File

@ -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(
render_layers_and_windows(
renderer,
frame,
window_map,
layer,
&*state.window_map.borrow(),
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,
)?;
}
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,