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 drawing;
|
||||||
pub mod input_handler;
|
pub mod input_handler;
|
||||||
pub mod output_map;
|
pub mod output_map;
|
||||||
|
#[cfg(any(feature = "udev", feature = "winit"))]
|
||||||
|
pub mod render;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
#[cfg(feature = "udev")]
|
#[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::{
|
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(
|
||||||
|
renderer,
|
||||||
for layer in [Layer::Background, Layer::Bottom] {
|
frame,
|
||||||
draw_layers(
|
window_map,
|
||||||
renderer,
|
output_geometry,
|
||||||
frame,
|
output_scale,
|
||||||
window_map,
|
logger,
|
||||||
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
|
// 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,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(())
|
Ok(())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -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(
|
||||||
|
renderer,
|
||||||
let window_map = &*state.window_map.borrow();
|
frame,
|
||||||
|
&*state.window_map.borrow(),
|
||||||
for layer in [Layer::Background, Layer::Bottom] {
|
output_geometry,
|
||||||
draw_layers(
|
output_scale,
|
||||||
renderer,
|
&log,
|
||||||
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,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
||||||
|
|
Loading…
Reference in New Issue