From e020347c6bbb3f9157a8b36133d2316121c5877d Mon Sep 17 00:00:00 2001 From: i509VCB Date: Sat, 21 Aug 2021 16:55:10 -0500 Subject: [PATCH 1/2] anvil: Split out logic for drawing layers and windows At the moment also splitting our Drag and Drop requires unraveling some backend specific stuff. --- anvil/src/lib.rs | 1 + anvil/src/render.rs | 56 +++++++++++++++++++++++++++++++++++++ anvil/src/udev.rs | 68 ++++++++++++++++++--------------------------- anvil/src/winit.rs | 45 ++++++++---------------------- 4 files changed, 96 insertions(+), 74 deletions(-) create mode 100644 anvil/src/render.rs diff --git a/anvil/src/lib.rs b/anvil/src/lib.rs index 5a1d98a..c41d2b6 100644 --- a/anvil/src/lib.rs +++ b/anvil/src/lib.rs @@ -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")] diff --git a/anvil/src/render.rs b/anvil/src/render.rs new file mode 100644 index 0000000..4848c45 --- /dev/null +++ b/anvil/src/render.rs @@ -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, + 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(()) +} diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 8811df2..fbec837 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -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(()) }, ) diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 8e3e87c..cc8c8ef 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -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, From 5d2e6014269e7ea2548531e5d38a48ad7a4696ad Mon Sep 17 00:00:00 2001 From: i509VCB Date: Sat, 21 Aug 2021 17:18:54 -0500 Subject: [PATCH 2/2] Fence the module I guess --- anvil/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/anvil/src/lib.rs b/anvil/src/lib.rs index c41d2b6..8a94884 100644 --- a/anvil/src/lib.rs +++ b/anvil/src/lib.rs @@ -14,6 +14,7 @@ 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;