2022-02-04 21:04:17 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "debug")]
|
|
|
|
|
use crate::{
|
2022-03-16 20:05:24 +01:00
|
|
|
debug::{debug_ui, fps_ui, log_ui, EguiFrame},
|
2022-02-04 21:04:17 +01:00
|
|
|
state::Fps,
|
2022-07-04 16:00:03 +02:00
|
|
|
utils::prelude::*,
|
2022-07-04 16:00:29 +02:00
|
|
|
};
|
2022-08-30 13:28:36 +02:00
|
|
|
use crate::{
|
2022-10-26 15:26:07 +02:00
|
|
|
shell::{
|
|
|
|
|
layout::floating::SeatMoveGrabState, CosmicMappedRenderElement, WorkspaceRenderElement,
|
|
|
|
|
},
|
|
|
|
|
state::Common,
|
|
|
|
|
wayland::handlers::data_device::get_dnd_icon,
|
2022-08-30 13:28:36 +02:00
|
|
|
};
|
2022-02-04 21:04:17 +01:00
|
|
|
|
|
|
|
|
use smithay::{
|
2022-03-22 12:36:03 +01:00
|
|
|
backend::{
|
|
|
|
|
drm::DrmNode,
|
|
|
|
|
renderer::{
|
2022-09-28 12:01:29 +02:00
|
|
|
damage::{
|
|
|
|
|
DamageTrackedRenderer, DamageTrackedRendererError as RenderError, OutputNoMode,
|
|
|
|
|
},
|
|
|
|
|
gles2::{Gles2Renderbuffer, Gles2Renderer},
|
|
|
|
|
multigpu::{egl::EglGlesBackend, MultiFrame, MultiRenderer},
|
|
|
|
|
ImportAll, ImportMem, Renderer,
|
2022-03-22 12:36:03 +01:00
|
|
|
},
|
2022-03-16 20:05:24 +01:00
|
|
|
},
|
2022-09-09 20:00:00 -07:00
|
|
|
output::Output,
|
2022-09-28 12:01:29 +02:00
|
|
|
utils::{Physical, Rectangle},
|
2022-02-04 21:04:17 +01:00
|
|
|
};
|
|
|
|
|
|
2022-08-05 14:28:37 +02:00
|
|
|
pub mod cursor;
|
2022-09-28 12:01:29 +02:00
|
|
|
use self::cursor::CursorRenderElement;
|
2022-02-04 21:04:17 +01:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub type GlMultiRenderer<'a> = MultiRenderer<
|
|
|
|
|
'a,
|
|
|
|
|
'a,
|
|
|
|
|
EglGlesBackend<Gles2Renderer>,
|
|
|
|
|
EglGlesBackend<Gles2Renderer>,
|
|
|
|
|
Gles2Renderbuffer,
|
|
|
|
|
>;
|
|
|
|
|
pub type GlMultiFrame = MultiFrame<EglGlesBackend<Gles2Renderer>, EglGlesBackend<Gles2Renderer>>;
|
2022-03-16 20:06:31 +01:00
|
|
|
|
2022-04-22 15:18:28 +02:00
|
|
|
static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0];
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
smithay::render_elements! {
|
|
|
|
|
pub CosmicElement<R> where R: ImportAll;
|
|
|
|
|
WorkspaceElement=WorkspaceRenderElement<R>,
|
|
|
|
|
CursorElement=CursorRenderElement<R>,
|
2022-10-26 15:26:07 +02:00
|
|
|
MoveGrabRenderElement=CosmicMappedRenderElement<R>,
|
2022-09-28 12:01:29 +02:00
|
|
|
//#[cfg(feature = "debug")]
|
|
|
|
|
//EguiFrame=EguiFrame,
|
2022-04-26 16:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub fn cursor_elements<E, R>(
|
2022-08-05 16:28:05 +02:00
|
|
|
renderer: &mut R,
|
|
|
|
|
state: &Common,
|
|
|
|
|
output: &Output,
|
|
|
|
|
hardware_cursor: bool,
|
2022-09-28 12:01:29 +02:00
|
|
|
) -> Vec<E>
|
2022-08-05 16:28:05 +02:00
|
|
|
where
|
2022-09-28 12:01:29 +02:00
|
|
|
R: Renderer + ImportAll + ImportMem,
|
|
|
|
|
<R as Renderer>::TextureId: Clone + 'static,
|
2022-10-26 15:26:07 +02:00
|
|
|
E: From<CursorRenderElement<R>> + From<CosmicMappedRenderElement<R>>,
|
2022-08-05 16:28:05 +02:00
|
|
|
{
|
2022-09-28 12:01:29 +02:00
|
|
|
let scale = output.current_scale().fractional_scale();
|
|
|
|
|
let mut elements = Vec::new();
|
2022-08-05 16:28:05 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
for seat in state.seats() {
|
2022-08-05 16:28:05 +02:00
|
|
|
let pointer = match seat.get_pointer() {
|
|
|
|
|
Some(ptr) => ptr,
|
|
|
|
|
None => continue,
|
|
|
|
|
};
|
|
|
|
|
let location = state
|
|
|
|
|
.shell
|
2022-09-28 12:01:29 +02:00
|
|
|
.map_global_to_space(pointer.current_location().to_i32_round(), output);
|
2022-08-05 16:28:05 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
elements.extend(
|
|
|
|
|
cursor::draw_cursor(
|
|
|
|
|
renderer,
|
|
|
|
|
seat,
|
|
|
|
|
location,
|
|
|
|
|
scale.into(),
|
|
|
|
|
&state.start_time,
|
|
|
|
|
!hardware_cursor,
|
|
|
|
|
)
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(E::from),
|
|
|
|
|
);
|
2022-10-26 15:26:07 +02:00
|
|
|
|
|
|
|
|
if let Some(wl_surface) = get_dnd_icon(seat) {
|
|
|
|
|
elements.extend(
|
|
|
|
|
cursor::draw_dnd_icon(&wl_surface, location.to_i32_round(), scale)
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(E::from),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(grab_elements) = seat
|
|
|
|
|
.user_data()
|
|
|
|
|
.get::<SeatMoveGrabState>()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.borrow()
|
|
|
|
|
.as_ref()
|
|
|
|
|
.map(|state| state.render::<E, R>(seat, output))
|
|
|
|
|
{
|
|
|
|
|
elements.extend(grab_elements);
|
|
|
|
|
}
|
2022-08-05 16:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
elements
|
2022-08-05 16:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-16 20:05:24 +01:00
|
|
|
pub fn render_output<R>(
|
2022-04-22 15:18:28 +02:00
|
|
|
gpu: Option<&DrmNode>,
|
2022-03-16 20:05:24 +01:00
|
|
|
renderer: &mut R,
|
2022-09-28 12:01:29 +02:00
|
|
|
damage_tracker: &mut DamageTrackedRenderer,
|
|
|
|
|
age: usize,
|
2022-02-04 21:04:17 +01:00
|
|
|
state: &mut Common,
|
|
|
|
|
output: &Output,
|
|
|
|
|
hardware_cursor: bool,
|
2022-08-03 16:34:04 +02:00
|
|
|
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
2022-07-04 15:29:31 +02:00
|
|
|
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
2022-08-05 14:28:37 +02:00
|
|
|
where
|
2022-09-28 12:01:29 +02:00
|
|
|
R: Renderer + ImportAll + ImportMem,
|
2022-08-05 14:28:37 +02:00
|
|
|
<R as Renderer>::TextureId: Clone + 'static,
|
|
|
|
|
{
|
2022-09-28 12:01:29 +02:00
|
|
|
let idx = state.shell.workspaces.active_num(output);
|
2022-08-05 14:28:37 +02:00
|
|
|
render_workspace(
|
|
|
|
|
gpu,
|
|
|
|
|
renderer,
|
2022-09-28 12:01:29 +02:00
|
|
|
damage_tracker,
|
2022-08-05 14:28:37 +02:00
|
|
|
age,
|
|
|
|
|
state,
|
|
|
|
|
output,
|
2022-09-28 12:01:29 +02:00
|
|
|
idx,
|
2022-08-05 14:28:37 +02:00
|
|
|
hardware_cursor,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn render_workspace<R>(
|
2022-09-28 12:01:29 +02:00
|
|
|
_gpu: Option<&DrmNode>,
|
2022-08-05 14:28:37 +02:00
|
|
|
renderer: &mut R,
|
2022-09-28 12:01:29 +02:00
|
|
|
damage_tracker: &mut DamageTrackedRenderer,
|
|
|
|
|
age: usize,
|
2022-08-05 14:28:37 +02:00
|
|
|
state: &mut Common,
|
|
|
|
|
output: &Output,
|
2022-09-28 12:01:29 +02:00
|
|
|
idx: usize,
|
2022-08-05 14:28:37 +02:00
|
|
|
hardware_cursor: bool,
|
|
|
|
|
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
|
|
|
|
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
2022-03-16 20:05:24 +01:00
|
|
|
where
|
2022-09-28 12:01:29 +02:00
|
|
|
R: Renderer + ImportAll + ImportMem,
|
2022-03-16 20:05:24 +01:00
|
|
|
<R as Renderer>::TextureId: Clone + 'static,
|
|
|
|
|
{
|
2022-02-04 21:04:17 +01:00
|
|
|
#[cfg(feature = "debug")]
|
2022-08-03 16:34:04 +02:00
|
|
|
if let Some(ref mut fps) = fps {
|
2022-02-04 21:04:17 +01:00
|
|
|
fps.start();
|
|
|
|
|
}
|
2022-08-05 14:28:37 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
let workspace = &state
|
|
|
|
|
.shell
|
|
|
|
|
.workspaces
|
|
|
|
|
.get(idx, output)
|
|
|
|
|
.ok_or(OutputNoMode)?;
|
2022-04-22 15:18:28 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
let mut elements: Vec<CosmicElement<R>> =
|
|
|
|
|
cursor_elements(renderer, state, output, hardware_cursor);
|
2022-02-04 21:04:17 +01:00
|
|
|
|
|
|
|
|
#[cfg(feature = "debug")]
|
|
|
|
|
{
|
2022-09-28 12:01:29 +02:00
|
|
|
// TODO add debug elements
|
2022-08-05 14:28:37 +02:00
|
|
|
let workspace = &state.shell.spaces[space_idx];
|
2022-03-24 20:32:31 +01:00
|
|
|
let output_geo = workspace
|
|
|
|
|
.space
|
2022-03-16 20:05:24 +01:00
|
|
|
.output_geometry(output)
|
2022-02-04 21:04:17 +01:00
|
|
|
.unwrap_or(Rectangle::from_loc_and_size((0, 0), (0, 0)));
|
2022-04-20 16:06:37 +02:00
|
|
|
let scale = output.current_scale().fractional_scale();
|
2022-02-04 21:04:17 +01:00
|
|
|
|
2022-07-20 17:25:36 +02:00
|
|
|
if let Some(fps) = fps {
|
|
|
|
|
let fps_overlay = fps_ui(
|
|
|
|
|
_gpu,
|
|
|
|
|
state,
|
|
|
|
|
fps,
|
|
|
|
|
output_geo.to_f64().to_physical(scale),
|
|
|
|
|
scale,
|
|
|
|
|
);
|
|
|
|
|
custom_elements.push(fps_overlay.into());
|
|
|
|
|
}
|
2022-02-04 21:04:17 +01:00
|
|
|
|
2022-07-04 16:00:03 +02:00
|
|
|
let area = Rectangle::<f64, smithay::utils::Logical>::from_loc_and_size(
|
2022-07-04 16:00:29 +02:00
|
|
|
state
|
|
|
|
|
.shell
|
|
|
|
|
.space_relative_output_geometry((0.0f64, 0.0f64), output),
|
2022-07-04 16:00:03 +02:00
|
|
|
state.shell.global_space().to_f64().size,
|
2022-07-04 16:00:29 +02:00
|
|
|
)
|
|
|
|
|
.to_physical(scale);
|
2022-02-05 00:40:17 +01:00
|
|
|
if let Some(log_ui) = log_ui(state, area, scale, output_geo.size.w as f32 * 0.6) {
|
2022-03-16 20:05:24 +01:00
|
|
|
custom_elements.push(log_ui.into());
|
2022-02-05 00:40:17 +01:00
|
|
|
}
|
2022-02-04 21:04:17 +01:00
|
|
|
if let Some(debug_overlay) = debug_ui(state, area, scale) {
|
2022-03-16 20:05:24 +01:00
|
|
|
custom_elements.push(debug_overlay.into());
|
2022-02-04 21:04:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
elements.extend(
|
|
|
|
|
workspace
|
|
|
|
|
.render_output(output)
|
|
|
|
|
.map_err(|_| OutputNoMode)?
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(Into::into),
|
|
|
|
|
);
|
2022-04-22 15:18:28 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
let res = damage_tracker.render_output(renderer, age, &elements, CLEAR_COLOR, None);
|
2022-02-04 21:04:17 +01:00
|
|
|
|
|
|
|
|
#[cfg(feature = "debug")]
|
2022-09-28 12:01:29 +02:00
|
|
|
if let Some(ref mut fps) = fps {
|
|
|
|
|
fps.end();
|
2022-04-22 15:18:28 +02:00
|
|
|
}
|
2022-05-03 13:37:51 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
res
|
2022-02-04 21:04:17 +01:00
|
|
|
}
|