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,
|
2022-11-03 18:51:27 +01:00
|
|
|
wayland::{
|
|
|
|
|
handlers::{data_device::get_dnd_icon, screencopy::render_to_buffer},
|
|
|
|
|
protocols::{
|
|
|
|
|
screencopy::{BufferParams, Session as ScreencopySession},
|
|
|
|
|
workspace::WorkspaceHandle,
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-08-30 13:28:36 +02:00
|
|
|
};
|
2022-02-04 21:04:17 +01:00
|
|
|
|
2022-11-03 18:51:27 +01:00
|
|
|
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::FailureReason;
|
2022-02-04 21:04:17 +01:00
|
|
|
use smithay::{
|
2022-03-22 12:36:03 +01:00
|
|
|
backend::{
|
2022-11-03 18:51:27 +01:00
|
|
|
allocator::dmabuf::Dmabuf,
|
2022-03-22 12:36:03 +01:00
|
|
|
drm::DrmNode,
|
|
|
|
|
renderer::{
|
2022-11-04 14:14:11 +01:00
|
|
|
buffer_dimensions,
|
2022-09-28 12:01:29 +02:00
|
|
|
damage::{
|
|
|
|
|
DamageTrackedRenderer, DamageTrackedRendererError as RenderError, OutputNoMode,
|
|
|
|
|
},
|
2022-11-03 18:51:27 +01:00
|
|
|
element::RenderElementStates,
|
2022-09-28 12:01:29 +02:00
|
|
|
gles2::{Gles2Renderbuffer, Gles2Renderer},
|
|
|
|
|
multigpu::{egl::EglGlesBackend, MultiFrame, MultiRenderer},
|
2022-11-03 18:51:27 +01:00
|
|
|
Bind, Blit, ExportMem, ImportAll, ImportMem, Offscreen, Renderer, TextureFilter,
|
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-11-04 14:14:11 +01:00
|
|
|
utils::{Physical, Rectangle, Transform},
|
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-11-03 18:51:27 +01:00
|
|
|
pub static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0];
|
2022-04-22 15:18:28 +02:00
|
|
|
|
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-11-03 18:51:27 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub enum CursorMode {
|
|
|
|
|
None,
|
|
|
|
|
NotDefault,
|
|
|
|
|
All,
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2022-11-03 18:51:27 +01:00
|
|
|
mode: CursorMode,
|
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-11-03 18:51:27 +01:00
|
|
|
if mode != CursorMode::None {
|
|
|
|
|
elements.extend(
|
|
|
|
|
cursor::draw_cursor(
|
|
|
|
|
renderer,
|
|
|
|
|
seat,
|
|
|
|
|
location,
|
|
|
|
|
scale.into(),
|
|
|
|
|
&state.start_time,
|
|
|
|
|
mode != CursorMode::NotDefault,
|
|
|
|
|
)
|
|
|
|
|
.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-11-03 18:51:27 +01:00
|
|
|
pub fn render_output<R, Target, Source>(
|
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,
|
2022-11-03 18:51:27 +01:00
|
|
|
cursor_mode: CursorMode,
|
|
|
|
|
screencopy: Option<(Source, &[(ScreencopySession, BufferParams)])>,
|
2022-08-03 16:34:04 +02:00
|
|
|
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
2022-11-03 18:51:27 +01:00
|
|
|
) -> Result<(Option<Vec<Rectangle<i32, Physical>>>, RenderElementStates), RenderError<R>>
|
2022-08-05 14:28:37 +02:00
|
|
|
where
|
2022-11-03 18:51:27 +01:00
|
|
|
R: Renderer
|
|
|
|
|
+ ImportAll
|
|
|
|
|
+ ImportMem
|
|
|
|
|
+ ExportMem
|
|
|
|
|
+ Bind<Dmabuf>
|
|
|
|
|
+ Offscreen<Target>
|
|
|
|
|
+ Bind<Source>
|
|
|
|
|
+ Blit<Source>,
|
2022-08-05 14:28:37 +02:00
|
|
|
<R as Renderer>::TextureId: Clone + 'static,
|
2022-11-03 18:51:27 +01:00
|
|
|
Source: Clone,
|
2022-08-05 14:28:37 +02:00
|
|
|
{
|
2022-11-03 18:51:27 +01:00
|
|
|
let handle = state.shell.workspaces.active(output).handle;
|
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-11-03 18:51:27 +01:00
|
|
|
&handle,
|
|
|
|
|
cursor_mode,
|
|
|
|
|
screencopy,
|
2022-08-05 14:28:37 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 18:51:27 +01:00
|
|
|
pub fn render_workspace<R, Target, Source>(
|
|
|
|
|
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-11-03 18:51:27 +01:00
|
|
|
handle: &WorkspaceHandle,
|
|
|
|
|
cursor_mode: CursorMode,
|
|
|
|
|
screencopy: Option<(Source, &[(ScreencopySession, BufferParams)])>,
|
2022-08-05 14:28:37 +02:00
|
|
|
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
2022-11-03 18:51:27 +01:00
|
|
|
) -> Result<(Option<Vec<Rectangle<i32, Physical>>>, RenderElementStates), RenderError<R>>
|
2022-03-16 20:05:24 +01:00
|
|
|
where
|
2022-11-03 18:51:27 +01:00
|
|
|
R: Renderer
|
|
|
|
|
+ ImportAll
|
|
|
|
|
+ ImportMem
|
|
|
|
|
+ ExportMem
|
|
|
|
|
+ Bind<Dmabuf>
|
|
|
|
|
+ Offscreen<Target>
|
|
|
|
|
+ Bind<Source>
|
|
|
|
|
+ Blit<Source>,
|
|
|
|
|
Source: Clone,
|
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-11-03 18:51:27 +01:00
|
|
|
let workspace = state.shell.space_for_handle(&handle).ok_or(OutputNoMode)?;
|
2022-04-22 15:18:28 +02:00
|
|
|
|
2022-11-03 18:51:27 +01:00
|
|
|
let mut elements: Vec<CosmicElement<R>> = cursor_elements(renderer, state, output, cursor_mode);
|
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-11-03 18:51:27 +01:00
|
|
|
if let Some((source, buffers)) = screencopy {
|
|
|
|
|
if res.is_ok() {
|
|
|
|
|
for (session, params) in buffers {
|
2022-11-04 14:14:11 +01:00
|
|
|
let mode = output.current_mode().unwrap().size;
|
|
|
|
|
let buffer_size = buffer_dimensions(¶ms.buffer).unwrap();
|
|
|
|
|
if mode.to_logical(1).to_buffer(1, Transform::Normal) != buffer_size {
|
|
|
|
|
session.failed(FailureReason::InvalidSize);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 18:51:27 +01:00
|
|
|
match render_to_buffer(
|
|
|
|
|
gpu.cloned(),
|
|
|
|
|
renderer,
|
|
|
|
|
&session,
|
|
|
|
|
params,
|
|
|
|
|
output.current_transform(),
|
|
|
|
|
|_node, renderer, dtr, age| {
|
|
|
|
|
let res = dtr.damage_output(age, &elements, slog_scope::logger())?;
|
|
|
|
|
|
|
|
|
|
if let (Some(ref damage), _) = &res {
|
|
|
|
|
for rect in damage {
|
|
|
|
|
renderer
|
|
|
|
|
.blit_from(source.clone(), *rect, *rect, TextureFilter::Nearest)
|
|
|
|
|
.map_err(RenderError::Rendering)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(res)
|
|
|
|
|
},
|
|
|
|
|
) {
|
|
|
|
|
Ok(true) => {} // success
|
|
|
|
|
Ok(false) => state.still_pending(session.clone(), params.clone()),
|
|
|
|
|
Err(err) => {
|
|
|
|
|
slog_scope::warn!("Error rendering to screencopy session: {}", err);
|
|
|
|
|
session.failed(FailureReason::Unspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
res
|
2022-02-04 21:04:17 +01:00
|
|
|
}
|