wip: New shell logic
This commit is contained in:
parent
146a4893ca
commit
00f1b029da
39 changed files with 3922 additions and 2503 deletions
|
|
@ -2,14 +2,20 @@
|
|||
|
||||
use crate::utils::prelude::*;
|
||||
use smithay::{
|
||||
backend::renderer::{Frame, ImportAll, ImportMem, Renderer, Texture},
|
||||
desktop::space::{RenderElement, SpaceOutputTuple, SurfaceTree},
|
||||
backend::renderer::{
|
||||
element::{
|
||||
surface::{render_elements_from_surface_tree, WaylandSurfaceRenderElement},
|
||||
texture::{TextureBuffer, TextureRenderElement},
|
||||
},
|
||||
ImportAll, ImportMem, Renderer,
|
||||
},
|
||||
input::{
|
||||
pointer::{CursorImageAttributes, CursorImageStatus},
|
||||
Seat,
|
||||
},
|
||||
reexports::wayland_server::protocol::wl_surface,
|
||||
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Size, Transform},
|
||||
render_elements,
|
||||
utils::{IsAlive, Logical, Point, Scale, Transform},
|
||||
wayland::compositor::{get_role, with_states},
|
||||
};
|
||||
use std::{
|
||||
|
|
@ -119,13 +125,21 @@ fn load_icon(theme: &CursorTheme) -> Result<Vec<Image>, Error> {
|
|||
parse_xcursor(&cursor_data).ok_or(Error::Parse)
|
||||
}
|
||||
|
||||
pub fn draw_surface_cursor(
|
||||
surface: wl_surface::WlSurface,
|
||||
render_elements! {
|
||||
pub CursorRenderElement<R> where R: ImportAll;
|
||||
Static=TextureRenderElement<<R as Renderer>::TextureId>,
|
||||
Surface=WaylandSurfaceRenderElement,
|
||||
}
|
||||
|
||||
pub fn draw_surface_cursor<R: Renderer + ImportAll>(
|
||||
surface: &wl_surface::WlSurface,
|
||||
location: impl Into<Point<i32, Logical>>,
|
||||
) -> SurfaceTree
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Vec<CursorRenderElement<R>>
|
||||
where
|
||||
{
|
||||
let mut position = location.into();
|
||||
let scale = scale.into();
|
||||
let h = with_states(&surface, |states| {
|
||||
states
|
||||
.data_map
|
||||
|
|
@ -136,125 +150,26 @@ where
|
|||
.hotspot
|
||||
});
|
||||
position -= h;
|
||||
SurfaceTree {
|
||||
surface,
|
||||
position,
|
||||
z_index: 100,
|
||||
}
|
||||
|
||||
render_elements_from_surface_tree(surface, position.to_physical_precise_round(scale), scale)
|
||||
}
|
||||
|
||||
pub fn draw_dnd_icon(
|
||||
surface: wl_surface::WlSurface,
|
||||
pub fn draw_dnd_icon<R: Renderer + ImportAll>(
|
||||
surface: &wl_surface::WlSurface,
|
||||
location: impl Into<Point<i32, Logical>>,
|
||||
) -> SurfaceTree {
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Vec<CursorRenderElement<R>> {
|
||||
if get_role(&surface) != Some("dnd_icon") {
|
||||
slog_scope::warn!(
|
||||
"Trying to display as a dnd icon a surface that does not have the DndIcon role."
|
||||
);
|
||||
}
|
||||
SurfaceTree {
|
||||
let scale = scale.into();
|
||||
render_elements_from_surface_tree(
|
||||
surface,
|
||||
position: location.into(),
|
||||
z_index: 100,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PointerElement<T: Texture> {
|
||||
seat_id: usize,
|
||||
texture: T,
|
||||
position: Point<f64, Logical>,
|
||||
size: Size<i32, Logical>,
|
||||
new_frame: bool,
|
||||
}
|
||||
|
||||
impl<T: Texture> PointerElement<T> {
|
||||
pub fn new(
|
||||
seat: &Seat<State>,
|
||||
texture: T,
|
||||
relative_pointer_pos: Point<f64, Logical>,
|
||||
new_frame: bool,
|
||||
) -> PointerElement<T> {
|
||||
let size = texture.size().to_logical(1, Transform::Normal);
|
||||
PointerElement {
|
||||
seat_id: seat.id(),
|
||||
texture,
|
||||
position: relative_pointer_pos,
|
||||
size,
|
||||
new_frame,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> RenderElement<R> for PointerElement<<R as Renderer>::TextureId>
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
fn id(&self) -> usize {
|
||||
self.seat_id
|
||||
}
|
||||
|
||||
fn location(&self, scale: impl Into<Scale<f64>>) -> Point<f64, Physical> {
|
||||
self.position.to_physical(scale)
|
||||
}
|
||||
|
||||
fn geometry(&self, scale: impl Into<Scale<f64>>) -> Rectangle<i32, Physical> {
|
||||
Rectangle::from_loc_and_size(self.position, self.size.to_f64())
|
||||
.to_physical(scale)
|
||||
.to_i32_round()
|
||||
}
|
||||
|
||||
fn accumulated_damage(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
_: Option<SpaceOutputTuple<'_, '_>>,
|
||||
) -> Vec<Rectangle<i32, Physical>> {
|
||||
if self.new_frame {
|
||||
let scale = scale.into();
|
||||
vec![Rectangle::from_loc_and_size(
|
||||
self.position.to_physical(scale).to_i32_round(),
|
||||
self.size.to_physical_precise_round(scale),
|
||||
)]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
fn opaque_regions(
|
||||
&self,
|
||||
_scale: impl Into<Scale<f64>>,
|
||||
) -> Option<Vec<Rectangle<i32, Physical>>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
_renderer: &mut R,
|
||||
frame: &mut <R as Renderer>::Frame,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
position: Point<f64, Physical>,
|
||||
damage: &[Rectangle<i32, Physical>],
|
||||
_log: &slog::Logger,
|
||||
) -> Result<(), <R as Renderer>::Error> {
|
||||
let scale = scale.into();
|
||||
frame.render_texture_at(
|
||||
&self.texture,
|
||||
position.to_i32_round(),
|
||||
1,
|
||||
scale,
|
||||
Transform::Normal,
|
||||
&damage
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|mut rect| {
|
||||
rect.loc -= self.position.to_physical(scale).to_i32_round();
|
||||
rect
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
1.0,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
location.into().to_physical_precise_round(scale),
|
||||
scale,
|
||||
)
|
||||
}
|
||||
|
||||
struct CursorState {
|
||||
|
|
@ -273,15 +188,15 @@ impl Default for CursorState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw_cursor<R, I>(
|
||||
pub fn draw_cursor<R>(
|
||||
renderer: &mut R,
|
||||
seat: &Seat<State>,
|
||||
location: Point<f64, Logical>,
|
||||
scale: Scale<f64>,
|
||||
start_time: &std::time::Instant,
|
||||
draw_default: bool,
|
||||
) -> Option<I>
|
||||
) -> Vec<CursorRenderElement<R>>
|
||||
where
|
||||
I: From<SurfaceTree> + From<PointerElement<<R as Renderer>::TextureId>>,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
{
|
||||
|
|
@ -302,50 +217,69 @@ where
|
|||
})
|
||||
.unwrap_or(CursorImageStatus::Default);
|
||||
|
||||
if let CursorImageStatus::Surface(wl_surface) = cursor_status {
|
||||
Some(draw_surface_cursor(wl_surface.clone(), location.to_i32_round()).into())
|
||||
if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
|
||||
return draw_surface_cursor(wl_surface, location.to_i32_round(), scale);
|
||||
} else if draw_default {
|
||||
let integer_scale = scale.x.max(scale.y).ceil() as u32;
|
||||
|
||||
let seat_userdata = seat.user_data();
|
||||
seat_userdata.insert_if_missing(CursorState::default);
|
||||
let state = seat_userdata.get::<CursorState>().unwrap();
|
||||
let frame = state
|
||||
.cursor
|
||||
.get_image(1, start_time.elapsed().as_millis() as u32);
|
||||
let new_frame = state.current_image.borrow().as_ref() != Some(&frame);
|
||||
.get_image(integer_scale, start_time.elapsed().as_millis() as u32);
|
||||
|
||||
let mut cache = state.image_cache.borrow_mut();
|
||||
let pointer_images = cache
|
||||
.entry((TypeId::of::<<R as Renderer>::TextureId>(), renderer.id()))
|
||||
.entry((
|
||||
TypeId::of::<TextureBuffer<<R as Renderer>::TextureId>>(),
|
||||
renderer.id(),
|
||||
))
|
||||
.or_default();
|
||||
let pointer_image = pointer_images
|
||||
|
||||
let maybe_image = pointer_images
|
||||
.iter()
|
||||
.find_map(|(image, texture)| if image == &frame { Some(texture) } else { None })
|
||||
.and_then(|texture| {
|
||||
texture
|
||||
.downcast_ref::<<R as Renderer>::TextureId>()
|
||||
.cloned()
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
let texture = renderer
|
||||
.import_memory(
|
||||
&frame.pixels_rgba,
|
||||
(frame.width as i32, frame.height as i32).into(),
|
||||
false,
|
||||
)
|
||||
.expect("Failed to import cursor bitmap");
|
||||
pointer_images.push((frame.clone(), Box::new(texture.clone())));
|
||||
texture
|
||||
texture.downcast_ref::<TextureBuffer<<R as Renderer>::TextureId>>()
|
||||
});
|
||||
let pointer_image = match maybe_image {
|
||||
Some(image) => image,
|
||||
None => {
|
||||
let texture = TextureBuffer::from_memory(
|
||||
renderer,
|
||||
&frame.pixels_rgba,
|
||||
(frame.width as i32, frame.height as i32),
|
||||
false,
|
||||
integer_scale as i32,
|
||||
Transform::Normal,
|
||||
None,
|
||||
)
|
||||
.expect("Failed to import cursor bitmap");
|
||||
pointer_images.push((frame.clone(), Box::new(texture.clone())));
|
||||
pointer_images
|
||||
.last()
|
||||
.and_then(|(_, i)| {
|
||||
i.downcast_ref::<TextureBuffer<<R as Renderer>::TextureId>>()
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
let hotspot =
|
||||
Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32)).to_f64();
|
||||
*state.current_image.borrow_mut() = Some(frame);
|
||||
|
||||
Some(
|
||||
PointerElement::new(seat, pointer_image.clone(), location - hotspot, new_frame)
|
||||
.into(),
|
||||
)
|
||||
return vec![CursorRenderElement::Static(
|
||||
TextureRenderElement::from_texture_buffer(
|
||||
(location - hotspot).to_physical(scale),
|
||||
pointer_image,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
)];
|
||||
} else {
|
||||
None
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,162 +6,74 @@ use crate::{
|
|||
state::Fps,
|
||||
utils::prelude::*,
|
||||
};
|
||||
//grabs::{MoveGrabRenderElement, SeatMoveGrabState},
|
||||
use crate::{
|
||||
shell::grabs::{MoveGrabRenderElement, SeatMoveGrabState},
|
||||
state::Common,
|
||||
wayland::handlers::data_device::get_dnd_icon,
|
||||
shell::WorkspaceRenderElement, state::Common, wayland::handlers::data_device::get_dnd_icon,
|
||||
};
|
||||
|
||||
use slog::Logger;
|
||||
use smithay::{
|
||||
backend::{
|
||||
drm::DrmNode,
|
||||
renderer::{
|
||||
gles2::{Gles2Renderbuffer, Gles2Renderer, Gles2Texture},
|
||||
multigpu::{egl::EglGlesBackend, Error as MultiError, MultiFrame, MultiRenderer},
|
||||
Frame, ImportAll, Renderer,
|
||||
damage::{
|
||||
DamageTrackedRenderer, DamageTrackedRendererError as RenderError, OutputNoMode,
|
||||
},
|
||||
gles2::{Gles2Renderbuffer, Gles2Renderer},
|
||||
multigpu::{egl::EglGlesBackend, MultiFrame, MultiRenderer},
|
||||
ImportAll, ImportMem, Renderer,
|
||||
},
|
||||
},
|
||||
desktop::{
|
||||
draw_layer_popups, draw_layer_surface, draw_window, draw_window_popups,
|
||||
layer_map_for_output,
|
||||
space::{RenderElement, RenderError, SpaceOutputTuple, SurfaceTree},
|
||||
utils::damage_from_surface_tree,
|
||||
Window,
|
||||
},
|
||||
output::Output,
|
||||
utils::{Physical, Point, Rectangle, Scale, Transform},
|
||||
wayland::shell::wlr_layer::Layer as WlrLayer,
|
||||
utils::{Physical, Rectangle},
|
||||
};
|
||||
|
||||
pub mod cursor;
|
||||
use self::cursor::PointerElement;
|
||||
use self::cursor::CursorRenderElement;
|
||||
|
||||
pub type GlMultiRenderer<'a> =
|
||||
MultiRenderer<'a, 'a, EglGlesBackend, EglGlesBackend, Gles2Renderbuffer>;
|
||||
pub type GlMultiFrame = MultiFrame<EglGlesBackend, EglGlesBackend>;
|
||||
pub type GlMultiRenderer<'a> = MultiRenderer<
|
||||
'a,
|
||||
'a,
|
||||
EglGlesBackend<Gles2Renderer>,
|
||||
EglGlesBackend<Gles2Renderer>,
|
||||
Gles2Renderbuffer,
|
||||
>;
|
||||
pub type GlMultiFrame = MultiFrame<EglGlesBackend<Gles2Renderer>, EglGlesBackend<Gles2Renderer>>;
|
||||
|
||||
static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0];
|
||||
|
||||
smithay::custom_elements! {
|
||||
pub CustomElem<=Gles2Renderer>;
|
||||
SurfaceTree=SurfaceTree,
|
||||
PointerElement=PointerElement::<Gles2Texture>,
|
||||
MoveGrabRenderElement=MoveGrabRenderElement,
|
||||
#[cfg(feature = "debug")]
|
||||
EguiFrame=EguiFrame,
|
||||
smithay::render_elements! {
|
||||
pub CosmicElement<R> where R: ImportAll;
|
||||
WorkspaceElement=WorkspaceRenderElement<R>,
|
||||
CursorElement=CursorRenderElement<R>,
|
||||
//MoveGrabRenderElement=MoveGrabRenderElement,
|
||||
//#[cfg(feature = "debug")]
|
||||
//EguiFrame=EguiFrame,
|
||||
}
|
||||
|
||||
// TODO: due to the lifetime of MultiRenderer, we cannot be generic over CustomElem's renderer
|
||||
// util after GATs land. So we generate with the macro for Gles2 and then
|
||||
// do a manual impl for MultiRenderer.
|
||||
impl RenderElement<GlMultiRenderer<'_>> for CustomElem {
|
||||
fn id(&self) -> usize {
|
||||
RenderElement::<Gles2Renderer>::id(self)
|
||||
}
|
||||
|
||||
fn location(&self, scale: impl Into<Scale<f64>>) -> Point<f64, Physical> {
|
||||
RenderElement::<Gles2Renderer>::location(self, scale)
|
||||
}
|
||||
|
||||
fn geometry(&self, scale: impl Into<Scale<f64>>) -> Rectangle<i32, Physical> {
|
||||
RenderElement::<Gles2Renderer>::geometry(self, scale)
|
||||
}
|
||||
|
||||
fn accumulated_damage(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
for_values: Option<SpaceOutputTuple<'_, '_>>,
|
||||
) -> Vec<Rectangle<i32, Physical>> {
|
||||
RenderElement::<Gles2Renderer>::accumulated_damage(self, scale, for_values)
|
||||
}
|
||||
|
||||
fn opaque_regions(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Option<Vec<Rectangle<i32, Physical>>> {
|
||||
RenderElement::<Gles2Renderer>::opaque_regions(self, scale)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
renderer: &mut GlMultiRenderer<'_>,
|
||||
frame: &mut GlMultiFrame,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
location: Point<f64, Physical>,
|
||||
damage: &[Rectangle<i32, Physical>],
|
||||
log: &Logger,
|
||||
) -> Result<(), MultiError<EglGlesBackend, EglGlesBackend>> {
|
||||
RenderElement::<Gles2Renderer>::draw(
|
||||
self,
|
||||
renderer.as_mut(),
|
||||
frame.as_mut(),
|
||||
scale,
|
||||
location,
|
||||
damage,
|
||||
log,
|
||||
)
|
||||
.map_err(MultiError::Render)
|
||||
}
|
||||
|
||||
fn z_index(&self) -> u8 {
|
||||
RenderElement::<Gles2Renderer>::z_index(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AsGles2Renderer {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer;
|
||||
}
|
||||
impl AsGles2Renderer for Gles2Renderer {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl AsGles2Renderer for GlMultiRenderer<'_> {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer {
|
||||
self.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn needs_buffer_reset(output: &Output, state: &Common) -> bool {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
struct DidCustomRendering(AtomicBool);
|
||||
|
||||
let will_render_custom = {
|
||||
let workspace = state.shell.active_space(output);
|
||||
workspace.get_fullscreen(output).is_some()
|
||||
};
|
||||
|
||||
let userdata = output.user_data();
|
||||
userdata.insert_if_missing(|| DidCustomRendering(AtomicBool::new(false)));
|
||||
userdata
|
||||
.get::<DidCustomRendering>()
|
||||
.unwrap()
|
||||
.0
|
||||
.swap(will_render_custom, Ordering::AcqRel)
|
||||
!= will_render_custom
|
||||
}
|
||||
|
||||
pub fn cursor_custom_elements<R>(
|
||||
pub fn cursor_elements<E, R>(
|
||||
renderer: &mut R,
|
||||
state: &Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
) -> Vec<CustomElem>
|
||||
) -> Vec<E>
|
||||
where
|
||||
R: AsGles2Renderer,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
E: From<CursorRenderElement<R>>,
|
||||
{
|
||||
let mut custom_elements = Vec::new();
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
let mut elements = Vec::new();
|
||||
|
||||
for seat in &state.seats {
|
||||
for seat in state.seats() {
|
||||
let pointer = match seat.get_pointer() {
|
||||
Some(ptr) => ptr,
|
||||
None => continue,
|
||||
};
|
||||
let location = state
|
||||
.shell
|
||||
.space_relative_output_geometry(pointer.current_location().to_i32_round(), output);
|
||||
.map_global_to_space(pointer.current_location().to_i32_round(), output);
|
||||
|
||||
/*
|
||||
if let Some(grab) = seat
|
||||
.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
|
|
@ -172,147 +84,92 @@ where
|
|||
{
|
||||
custom_elements.push(grab);
|
||||
}
|
||||
*/
|
||||
|
||||
if let Some(wl_surface) = get_dnd_icon(seat) {
|
||||
custom_elements.push(cursor::draw_dnd_icon(wl_surface, location.to_i32_round()).into());
|
||||
elements.extend(
|
||||
cursor::draw_dnd_icon(&wl_surface, location.to_i32_round(), scale)
|
||||
.into_iter()
|
||||
.map(E::from),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(cursor) = cursor::draw_cursor(
|
||||
renderer.as_gles2(),
|
||||
seat,
|
||||
location,
|
||||
&state.start_time,
|
||||
!hardware_cursor,
|
||||
) {
|
||||
custom_elements.push(cursor)
|
||||
}
|
||||
elements.extend(
|
||||
cursor::draw_cursor(
|
||||
renderer,
|
||||
seat,
|
||||
location,
|
||||
scale.into(),
|
||||
&state.start_time,
|
||||
!hardware_cursor,
|
||||
)
|
||||
.into_iter()
|
||||
.map(E::from),
|
||||
);
|
||||
}
|
||||
|
||||
custom_elements
|
||||
elements
|
||||
}
|
||||
|
||||
pub fn render_output<R>(
|
||||
gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
damage_tracker: &mut DamageTrackedRenderer,
|
||||
age: usize,
|
||||
state: &mut Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let workspace = state.shell.active_space(output).idx;
|
||||
let idx = state.shell.workspaces.active_num(output);
|
||||
render_workspace(
|
||||
gpu,
|
||||
renderer,
|
||||
damage_tracker,
|
||||
age,
|
||||
state,
|
||||
workspace,
|
||||
output,
|
||||
idx,
|
||||
hardware_cursor,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_workspace<R>(
|
||||
gpu: Option<&DrmNode>,
|
||||
_gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
damage_tracker: &mut DamageTrackedRenderer,
|
||||
age: usize,
|
||||
state: &mut Common,
|
||||
space_idx: u8,
|
||||
output: &Output,
|
||||
idx: usize,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
#[cfg(feature = "debug")]
|
||||
if let Some(ref mut fps) = fps {
|
||||
fps.start();
|
||||
}
|
||||
|
||||
let space_idx = space_idx as usize;
|
||||
let workspace = &mut state.shell.spaces[space_idx];
|
||||
let maybe_fullscreen_window = workspace.get_fullscreen(output).cloned();
|
||||
let workspace = &state
|
||||
.shell
|
||||
.workspaces
|
||||
.get(idx, output)
|
||||
.ok_or(OutputNoMode)?;
|
||||
|
||||
let res = if let Some(window) = maybe_fullscreen_window {
|
||||
#[cfg(not(feature = "debug"))]
|
||||
{
|
||||
render_fullscreen(gpu, renderer, window, state, output, hardware_cursor)
|
||||
}
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
render_fullscreen(
|
||||
gpu,
|
||||
renderer,
|
||||
window,
|
||||
state,
|
||||
output,
|
||||
hardware_cursor,
|
||||
fps.as_deref_mut(),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(feature = "debug"))]
|
||||
{
|
||||
render_desktop(
|
||||
gpu,
|
||||
renderer,
|
||||
age,
|
||||
state,
|
||||
space_idx,
|
||||
output,
|
||||
hardware_cursor,
|
||||
)
|
||||
}
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
render_desktop(
|
||||
gpu,
|
||||
renderer,
|
||||
age,
|
||||
state,
|
||||
space_idx,
|
||||
output,
|
||||
hardware_cursor,
|
||||
fps.as_deref_mut(),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
if let Some(ref mut fps) = fps {
|
||||
fps.end();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
fn render_desktop<R>(
|
||||
_gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
state: &mut Common,
|
||||
space_idx: usize,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let mut custom_elements = Vec::<CustomElem>::new();
|
||||
let mut elements: Vec<CosmicElement<R>> =
|
||||
cursor_elements(renderer, state, output, hardware_cursor);
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
// TODO add debug elements
|
||||
let workspace = &state.shell.spaces[space_idx];
|
||||
let output_geo = workspace
|
||||
.space
|
||||
|
|
@ -346,132 +203,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
custom_elements.extend(cursor_custom_elements(
|
||||
renderer,
|
||||
state,
|
||||
output,
|
||||
hardware_cursor,
|
||||
));
|
||||
elements.extend(
|
||||
workspace
|
||||
.render_output(output)
|
||||
.map_err(|_| OutputNoMode)?
|
||||
.into_iter()
|
||||
.map(Into::into),
|
||||
);
|
||||
|
||||
state.shell.spaces[space_idx].space.render_output(
|
||||
renderer,
|
||||
&output,
|
||||
age as usize,
|
||||
CLEAR_COLOR,
|
||||
&*custom_elements,
|
||||
)
|
||||
}
|
||||
|
||||
fn render_fullscreen<R>(
|
||||
_gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
window: Window,
|
||||
state: &mut Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let transform = Transform::from(output.current_transform());
|
||||
let mode = output.current_mode().unwrap();
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
|
||||
let mut custom_elements = Vec::<CustomElem>::new();
|
||||
let res = damage_tracker.render_output(renderer, age, &elements, CLEAR_COLOR, None);
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
if let Some(fps) = fps {
|
||||
let output_geo = output.geometry();
|
||||
let fps_overlay = fps_ui(
|
||||
_gpu,
|
||||
state,
|
||||
fps,
|
||||
Rectangle::from_loc_and_size((0, 0), output_geo.size)
|
||||
.to_f64()
|
||||
.to_physical(scale),
|
||||
scale,
|
||||
);
|
||||
custom_elements.push(fps_overlay.into());
|
||||
if let Some(ref mut fps) = fps {
|
||||
fps.end();
|
||||
}
|
||||
|
||||
custom_elements.extend(cursor_custom_elements(
|
||||
renderer,
|
||||
state,
|
||||
output,
|
||||
hardware_cursor,
|
||||
));
|
||||
|
||||
renderer
|
||||
.render(mode.size, transform, |renderer, frame| {
|
||||
let mut damage = window.accumulated_damage((0.0, 0.0), scale, None);
|
||||
frame.clear(
|
||||
CLEAR_COLOR,
|
||||
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
|
||||
)?;
|
||||
draw_window(
|
||||
renderer,
|
||||
frame,
|
||||
&window,
|
||||
scale,
|
||||
(0.0, 0.0),
|
||||
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
draw_window_popups(
|
||||
renderer,
|
||||
frame,
|
||||
&window,
|
||||
scale,
|
||||
(0.0, 0.0),
|
||||
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
let layer_map = layer_map_for_output(output);
|
||||
for layer_surface in layer_map.layers_on(WlrLayer::Overlay) {
|
||||
let geo = layer_map.layer_geometry(&layer_surface).unwrap();
|
||||
draw_layer_surface(
|
||||
renderer,
|
||||
frame,
|
||||
layer_surface,
|
||||
scale,
|
||||
geo.loc.to_f64().to_physical(scale),
|
||||
&[Rectangle::from_loc_and_size(
|
||||
(0, 0),
|
||||
geo.size.to_physical_precise_round(scale),
|
||||
)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
draw_layer_popups(
|
||||
renderer,
|
||||
frame,
|
||||
layer_surface,
|
||||
scale,
|
||||
geo.loc.to_f64().to_physical(scale),
|
||||
&[Rectangle::from_loc_and_size(
|
||||
(0, 0),
|
||||
geo.size.to_physical_precise_round(scale),
|
||||
)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
damage.extend(damage_from_surface_tree(
|
||||
layer_surface.wl_surface(),
|
||||
geo.loc.to_f64().to_physical(scale),
|
||||
scale,
|
||||
None,
|
||||
));
|
||||
}
|
||||
for elem in custom_elements {
|
||||
let loc = elem.location(scale);
|
||||
let geo = elem.geometry(scale);
|
||||
let elem_damage = elem.accumulated_damage(scale, None);
|
||||
elem.draw(renderer, frame, scale, loc, &[geo], &slog_scope::logger())?;
|
||||
damage.extend(elem_damage)
|
||||
}
|
||||
Ok(Some(damage))
|
||||
})
|
||||
.and_then(std::convert::identity)
|
||||
.map_err(RenderError::<R>::Rendering)
|
||||
res
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue