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 drawing;
pub mod input_handler; pub mod input_handler;
pub mod output_map; pub mod output_map;
pub mod render;
pub mod shell; pub mod shell;
pub mod state; pub mod state;
#[cfg(feature = "udev")] #[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::{ wayland::{
output::{Mode, PhysicalProperties}, output::{Mode, PhysicalProperties},
seat::CursorImageStatus, seat::CursorImageStatus,
shell::wlr_layer::Layer,
}, },
}; };
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
@ -68,8 +67,11 @@ use smithay::{
wayland::dmabuf::init_dmabuf_global, wayland::dmabuf::init_dmabuf_global,
}; };
use crate::state::{AnvilState, Backend};
use crate::{drawing::*, window_map::WindowMap}; use crate::{drawing::*, window_map::WindowMap};
use crate::{
render::render_layers_and_windows,
state::{AnvilState, Backend},
};
#[derive(Clone)] #[derive(Clone)]
pub struct SessionFd(RawFd); pub struct SessionFd(RawFd);
@ -738,40 +740,21 @@ fn render_surface(
let dmabuf = surface.surface.next_buffer()?; let dmabuf = surface.surface.next_buffer()?;
renderer.bind(dmabuf)?; renderer.bind(dmabuf)?;
// and draw to our buffer // and draw to our buffer
match renderer match renderer
.render( .render(
mode.size, mode.size,
Transform::Flipped180, // Scanout is rotated Transform::Flipped180, // Scanout is rotated
|renderer, frame| { |renderer, frame| {
frame.clear([0.8, 0.8, 0.9, 1.0])?; render_layers_and_windows(
for layer in [Layer::Background, Layer::Bottom] {
draw_layers(
renderer, renderer,
frame, frame,
window_map, window_map,
layer,
output_geometry, output_geometry,
output_scale, output_scale,
logger, 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 // set cursor
if output_geometry.to_f64().contains(pointer_location) { if output_geometry.to_f64().contains(pointer_location) {
@ -793,6 +776,7 @@ fn render_surface(
} }
} }
} }
// draw the cursor as relevant // draw the cursor as relevant
{ {
// reset the cursor if the surface is no longer alive // reset the cursor if the surface is no longer alive
@ -827,7 +811,6 @@ fn render_surface(
)?; )?;
} }
} }
}
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
{ {
@ -838,8 +821,11 @@ fn render_surface(
output_scale as f64, output_scale as f64,
surface.fps.avg().round() as u32, surface.fps.avg().round() as u32,
)?; )?;
surface.fps.tick(); surface.fps.tick();
} }
}
Ok(()) Ok(())
}, },
) )

View File

@ -8,7 +8,7 @@ use smithay::{
wayland::dmabuf::init_dmabuf_global, wayland::dmabuf::init_dmabuf_global,
}; };
use smithay::{ use smithay::{
backend::{input::InputBackend, renderer::Frame, winit, SwapBuffersError}, backend::{input::InputBackend, winit, SwapBuffersError},
reexports::{ reexports::{
calloop::EventLoop, calloop::EventLoop,
wayland_server::{protocol::wl_output, Display}, wayland_server::{protocol::wl_output, Display},
@ -16,14 +16,13 @@ use smithay::{
wayland::{ wayland::{
output::{Mode, PhysicalProperties}, output::{Mode, PhysicalProperties},
seat::CursorImageStatus, seat::CursorImageStatus,
shell::wlr_layer::Layer,
}, },
}; };
use slog::Logger; use slog::Logger;
use crate::drawing::*;
use crate::state::{AnvilState, Backend}; use crate::state::{AnvilState, Backend};
use crate::{drawing::*, render::render_layers_and_windows};
pub const OUTPUT_NAME: &str = "winit"; pub const OUTPUT_NAME: &str = "winit";
@ -143,38 +142,17 @@ pub fn run_winit(log: Logger) {
let result = renderer let result = renderer
.render(|renderer, frame| { .render(|renderer, frame| {
frame.clear([0.8, 0.8, 0.9, 1.0])?; render_layers_and_windows(
let window_map = &*state.window_map.borrow();
for layer in [Layer::Background, Layer::Bottom] {
draw_layers(
renderer, renderer,
frame, frame,
window_map, &*state.window_map.borrow(),
layer,
output_geometry, output_geometry,
output_scale, output_scale,
&log, &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(); let (x, y) = state.pointer_location.into();
// draw the dnd icon if any // draw the dnd icon if any
{ {
let guard = state.dnd_icon.lock().unwrap(); let guard = state.dnd_icon.lock().unwrap();
@ -222,6 +200,7 @@ pub fn run_winit(log: Logger) {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
{ {
let fps = state.backend_data.fps.avg().round() as u32; let fps = state.backend_data.fps.avg().round() as u32;
draw_fps( draw_fps(
renderer, renderer,
frame, frame,