From 26743d6bdcdb26b7cc00f77014dfa0d343566169 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 6 Mar 2023 18:48:52 +0100 Subject: [PATCH] debug: Add profiler view --- src/backend/render/mod.rs | 22 ++++++++-- src/debug.rs | 25 ++++++++++++ src/input/mod.rs | 86 +++++++++++++++++++++++++++++++++++++++ src/state.rs | 11 ++++- 4 files changed, 140 insertions(+), 4 deletions(-) diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index 52c7b5a5..bfc378b0 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -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(::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() diff --git a/src/debug.rs b/src/debug.rs index 317729e1..c2b27cda 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -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, + scale: f64, +) -> Result>, 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, diff --git a/src/input/mod.rs b/src/input/mod.rs index a5eaac4d..3108f68d 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -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::() + .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::().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::>().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::().unwrap(); if devices.has_device(&device) { diff --git a/src/state.rs b/src/state.rs index f8645453..02187149 100644 --- a/src/state.rs +++ b/src/state.rs @@ -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 {