debug: Add profiler view

This commit is contained in:
Victoria Brekenfeld 2023-03-06 18:48:52 +01:00
parent d2b049332c
commit 26743d6bdc
4 changed files with 140 additions and 4 deletions

View file

@ -6,7 +6,10 @@ use std::{
};
#[cfg(feature = "debug")]
use crate::{debug::fps_ui, utils::prelude::*};
use crate::{
debug::{fps_ui, profiler_ui},
utils::prelude::*,
};
use crate::{
shell::{layout::floating::SeatMoveGrabState, CosmicMappedRenderElement},
state::{Common, Fps},
@ -301,8 +304,6 @@ where
}
}
let workspace = state.shell.space_for_handle(&handle).ok_or(OutputNoMode)?;
let screencopy_contains_embedded = screencopy.as_ref().map_or(false, |(_, sessions)| {
sessions
.iter()
@ -341,8 +342,23 @@ where
.map_err(RenderError::Rendering)?;
elements.push(fps_overlay.into());
}
if state.shell.outputs.first() == Some(output) {
if let Some(profiler_overlay) = profiler_ui(
state,
renderer.glow_renderer_mut(),
Rectangle::from_loc_and_size((0, 0), output_geo.size),
scale,
)
.map_err(<R as Renderer>::Error::from)
.map_err(RenderError::Rendering)?
{
elements.push(profiler_overlay.into());
}
}
}
let workspace = state.shell.space_for_handle(&handle).ok_or(OutputNoMode)?;
let last_active_seat = state.last_active_seat().clone();
let move_active = last_active_seat
.user_data()

View file

@ -29,6 +29,31 @@ pub const RENDER_COLOR: Color32 = Color32::from_rgb(29, 114, 58);
pub const SCREENCOPY_COLOR: Color32 = Color32::from_rgb(253, 178, 39);
pub const DISPLAY_COLOR: Color32 = Color32::from_rgb(41, 184, 209);
pub fn profiler_ui(
state: &mut Common,
renderer: &mut GlowRenderer,
area: Rectangle<i32, Logical>,
scale: f64,
) -> Result<Option<TextureRenderElement<Gles2Texture>>, Gles2Error> {
if !state.egui.active {
return Ok(None);
}
state
.egui
.state
.render(
|ctx| {
puffin_egui::profiler_window(ctx);
},
renderer,
area,
scale,
0.8,
)
.map(Some)
}
pub fn fps_ui(
gpu: Option<&DrmNode>,
state: &Common,

View file

@ -167,6 +167,10 @@ impl State {
_ => {}
}
}
#[cfg(feature = "debug")]
{
self.common.egui.state.handle_device_added(&device);
}
}
InputEvent::DeviceRemoved { device } => {
for seat in &mut self.common.seats() {
@ -182,6 +186,10 @@ impl State {
break;
}
}
#[cfg(feature = "debug")]
{
self.common.egui.state.handle_device_removed(&device);
}
}
InputEvent::Keyboard { event, .. } => {
use smithay::backend::input::KeyboardKeyEvent;
@ -227,6 +235,26 @@ impl State {
return FilterResult::Intercept(None);
}
#[cfg(feature = "debug")]
{
if data.common.seats().position(|x| x == seat).unwrap() == 0
&& data.common.egui.active
{
if data.common.egui.state.wants_keyboard() {
data.common.egui.state.handle_keyboard(
&handle,
state == KeyState::Pressed,
modifiers.clone(),
);
userdata
.get::<SupressedKeys>()
.unwrap()
.add(&handle);
return FilterResult::Intercept(None);
}
}
}
if state == KeyState::Pressed
&& (keysyms::KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12)
.contains(&handle.modified_sym())
@ -356,6 +384,18 @@ impl State {
utime: event.time(),
},
);
#[cfg(feature = "debug")]
if self.common.seats().position(|x| x == seat).unwrap() == 0 {
let location = if let Some(output) = self.common.shell.outputs.first() {
self.common
.shell
.map_global_to_space(position, output)
.to_i32_round()
} else {
position.to_i32_round()
};
self.common.egui.state.handle_pointer_motion(location);
}
break;
}
}
@ -406,6 +446,18 @@ impl State {
time: event.time_msec(),
},
);
#[cfg(feature = "debug")]
if self.common.seats().position(|x| x == seat).unwrap() == 0 {
let location = if let Some(output) = self.common.shell.outputs.first() {
self.common
.shell
.map_global_to_space(position, output)
.to_i32_round()
} else {
position.to_i32_round()
};
self.common.egui.state.handle_pointer_motion(location);
}
break;
}
@ -419,6 +471,21 @@ impl State {
let userdata = seat.user_data();
let devices = userdata.get::<Devices>().unwrap();
if devices.has_device(&device) {
#[cfg(feature = "debug")]
if self.common.seats().position(|x| x == seat).unwrap() == 0
&& self.common.egui.active
{
if self.common.egui.state.wants_pointer() {
if let Some(button) = event.button() {
self.common.egui.state.handle_pointer_button(
button,
event.state() == ButtonState::Pressed,
);
}
break;
}
}
let serial = SERIAL_COUNTER.next_serial();
let button = event.button_code();
if event.state() == ButtonState::Pressed {
@ -512,6 +579,25 @@ impl State {
InputEvent::PointerAxis { event, .. } => {
let device = event.device();
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
#[cfg(feature = "debug")]
if self.common.seats().position(|x| x == seat).unwrap() == 0
&& self.common.egui.active
{
if self.common.egui.state.wants_pointer() {
self.common.egui.state.handle_pointer_axis(
event
.amount_discrete(Axis::Horizontal)
.or_else(|| event.amount(Axis::Horizontal).map(|x| x * 3.0))
.unwrap_or(0.0),
event
.amount_discrete(Axis::Vertical)
.or_else(|| event.amount(Axis::Vertical).map(|x| x * 3.0))
.unwrap_or(0.0),
);
break;
}
}
let userdata = seat.user_data();
let devices = userdata.get::<Devices>().unwrap();
if devices.has_device(&device) {

View file

@ -14,6 +14,8 @@ use crate::{
xwayland::XWaylandState,
};
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_manager_v1::CursorMode;
#[cfg(feature = "debug")]
use smithay::utils::Rectangle;
use smithay::{
backend::{
drm::DrmNode,
@ -264,7 +266,13 @@ impl State {
should_stop: false,
#[cfg(feature = "debug")]
egui: Egui { active: false },
egui: Egui {
active: false,
state: smithay_egui::EguiState::new(Rectangle::from_loc_and_size(
(0, 0),
(800, 600),
)),
},
compositor_state,
data_device_state,
@ -517,6 +525,7 @@ impl Common {
#[cfg(feature = "debug")]
pub struct Egui {
pub active: bool,
pub state: smithay_egui::EguiState,
}
pub struct Fps {