Add debug-toggle-opaque-regions
Browse files at this commitc6d64dae7aae12379d25b2e90630d19aeef5444bParent: 5dddc856 changed files +81 -0
- niri-config/src/lib.rs +2 -0
- niri-ipc/src/lib.rs +2 -0
- src/input.rs +4 -0
- src/niri.rs +14 -0
- src/render_helpers/debug.rs +58 -0
- src/render_helpers/mod.rs +1 -0
niri-config/src/lib.rsmodified+2 -0
| @@ -846,6 +846,7 @@ pub enum Action { | |||
| 846 | Suspend, | 846 | Suspend, |
| 847 | PowerOffMonitors, | 847 | PowerOffMonitors, |
| 848 | ToggleDebugTint, | 848 | ToggleDebugTint, |
| 849 | + DebugToggleOpaqueRegions, | ||
| 849 | Spawn(#[knuffel(arguments)] Vec<String>), | 850 | Spawn(#[knuffel(arguments)] Vec<String>), |
| 850 | #[knuffel(skip)] | 851 | #[knuffel(skip)] |
| 851 | ConfirmScreenshot, | 852 | ConfirmScreenshot, |
| @@ -982,6 +983,7 @@ impl From<niri_ipc::Action> for Action { | |||
| 982 | niri_ipc::Action::MoveWorkspaceToMonitorDown => Self::MoveWorkspaceToMonitorDown, | 983 | niri_ipc::Action::MoveWorkspaceToMonitorDown => Self::MoveWorkspaceToMonitorDown, |
| 983 | niri_ipc::Action::MoveWorkspaceToMonitorUp => Self::MoveWorkspaceToMonitorUp, | 984 | niri_ipc::Action::MoveWorkspaceToMonitorUp => Self::MoveWorkspaceToMonitorUp, |
| 984 | niri_ipc::Action::ToggleDebugTint => Self::ToggleDebugTint, | 985 | niri_ipc::Action::ToggleDebugTint => Self::ToggleDebugTint, |
| 986 | + niri_ipc::Action::DebugToggleOpaqueRegions => Self::DebugToggleOpaqueRegions, | ||
| 985 | } | 987 | } |
| 986 | } | 988 | } |
| 987 | } | 989 | } |
niri-ipc/src/lib.rsmodified+2 -0
| @@ -217,6 +217,8 @@ pub enum Action { | |||
| 217 | MoveWorkspaceToMonitorUp, | 217 | MoveWorkspaceToMonitorUp, |
| 218 | /// Toggle a debug tint on windows. | 218 | /// Toggle a debug tint on windows. |
| 219 | ToggleDebugTint, | 219 | ToggleDebugTint, |
| 220 | + /// Toggle visualization of render element opaque regions. | ||
| 221 | + DebugToggleOpaqueRegions, | ||
| 220 | } | 222 | } |
| 221 | 223 | ||
| 222 | /// Change in window or column size. | 224 | /// Change in window or column size. |
src/input.rsmodified+4 -0
| @@ -368,6 +368,10 @@ impl State { | |||
| 368 | self.backend.toggle_debug_tint(); | 368 | self.backend.toggle_debug_tint(); |
| 369 | self.niri.queue_redraw_all(); | 369 | self.niri.queue_redraw_all(); |
| 370 | } | 370 | } |
| 371 | + Action::DebugToggleOpaqueRegions => { | ||
| 372 | + self.niri.debug_draw_opaque_regions = !self.niri.debug_draw_opaque_regions; | ||
| 373 | + self.niri.queue_redraw_all(); | ||
| 374 | + } | ||
| 371 | Action::Spawn(command) => { | 375 | Action::Spawn(command) => { |
| 372 | spawn(command); | 376 | spawn(command); |
| 373 | } | 377 | } |
src/niri.rsmodified+14 -0
| @@ -107,6 +107,7 @@ use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState}; | |||
| 107 | use crate::protocols::gamma_control::GammaControlManagerState; | 107 | use crate::protocols::gamma_control::GammaControlManagerState; |
| 108 | use crate::protocols::screencopy::{Screencopy, ScreencopyManagerState}; | 108 | use crate::protocols::screencopy::{Screencopy, ScreencopyManagerState}; |
| 109 | use crate::pw_utils::{Cast, PipeWire}; | 109 | use crate::pw_utils::{Cast, PipeWire}; |
| 110 | +use crate::render_helpers::debug::draw_opaque_regions; | ||
| 110 | use crate::render_helpers::renderer::NiriRenderer; | 111 | use crate::render_helpers::renderer::NiriRenderer; |
| 111 | use crate::render_helpers::{ | 112 | use crate::render_helpers::{ |
| 112 | render_to_shm, render_to_texture, render_to_vec, shaders, RenderTarget, | 113 | render_to_shm, render_to_texture, render_to_vec, shaders, RenderTarget, |
| @@ -236,6 +237,8 @@ pub struct Niri { | |||
| 236 | pub hotkey_overlay: HotkeyOverlay, | 237 | pub hotkey_overlay: HotkeyOverlay, |
| 237 | pub exit_confirm_dialog: Option<ExitConfirmDialog>, | 238 | pub exit_confirm_dialog: Option<ExitConfirmDialog>, |
| 238 | 239 | ||
| 240 | + pub debug_draw_opaque_regions: bool, | ||
| 241 | + | ||
| 239 | #[cfg(feature = "dbus")] | 242 | #[cfg(feature = "dbus")] |
| 240 | pub dbus: Option<crate::dbus::DBusServers>, | 243 | pub dbus: Option<crate::dbus::DBusServers>, |
| 241 | #[cfg(feature = "dbus")] | 244 | #[cfg(feature = "dbus")] |
| @@ -1422,6 +1425,8 @@ impl Niri { | |||
| 1422 | hotkey_overlay, | 1425 | hotkey_overlay, |
| 1423 | exit_confirm_dialog, | 1426 | exit_confirm_dialog, |
| 1424 | 1427 | ||
| 1428 | + debug_draw_opaque_regions: false, | ||
| 1429 | + | ||
| 1425 | #[cfg(feature = "dbus")] | 1430 | #[cfg(feature = "dbus")] |
| 1426 | dbus: None, | 1431 | dbus: None, |
| 1427 | #[cfg(feature = "dbus")] | 1432 | #[cfg(feature = "dbus")] |
| @@ -2382,6 +2387,9 @@ impl Niri { | |||
| 2382 | .into(), | 2387 | .into(), |
| 2383 | ); | 2388 | ); |
| 2384 | 2389 | ||
| 2390 | + if self.debug_draw_opaque_regions { | ||
| 2391 | + draw_opaque_regions(&mut elements, output_scale); | ||
| 2392 | + } | ||
| 2385 | return elements; | 2393 | return elements; |
| 2386 | } | 2394 | } |
| 2387 | 2395 | ||
| @@ -2408,6 +2416,9 @@ impl Niri { | |||
| 2408 | // Add the background for outputs that were connected while the screenshot UI was open. | 2416 | // Add the background for outputs that were connected while the screenshot UI was open. |
| 2409 | elements.push(background); | 2417 | elements.push(background); |
| 2410 | 2418 | ||
| 2419 | + if self.debug_draw_opaque_regions { | ||
| 2420 | + draw_opaque_regions(&mut elements, output_scale); | ||
| 2421 | + } | ||
| 2411 | return elements; | 2422 | return elements; |
| 2412 | } | 2423 | } |
| 2413 | 2424 | ||
| @@ -2463,6 +2474,9 @@ impl Niri { | |||
| 2463 | // Then the background. | 2474 | // Then the background. |
| 2464 | elements.push(background); | 2475 | elements.push(background); |
| 2465 | 2476 | ||
| 2477 | + if self.debug_draw_opaque_regions { | ||
| 2478 | + draw_opaque_regions(&mut elements, output_scale); | ||
| 2479 | + } | ||
| 2466 | elements | 2480 | elements |
| 2467 | } | 2481 | } |
| 2468 | 2482 | ||
src/render_helpers/debug.rsadded+58 -0
| @@ -0,0 +1,58 @@ | |||
| 1 | +use smithay::backend::renderer::element::solid::SolidColorRenderElement; | ||
| 2 | +use smithay::backend::renderer::element::{Element, Id, Kind}; | ||
| 3 | +use smithay::backend::renderer::utils::CommitCounter; | ||
| 4 | +use smithay::utils::Scale; | ||
| 5 | + | ||
| 6 | +use super::renderer::NiriRenderer; | ||
| 7 | +use crate::niri::OutputRenderElements; | ||
| 8 | + | ||
| 9 | +pub fn draw_opaque_regions<R: NiriRenderer>( | ||
| 10 | + elements: &mut Vec<OutputRenderElements<R>>, | ||
| 11 | + scale: Scale<f64>, | ||
| 12 | +) { | ||
| 13 | + let _span = tracy_client::span!("draw_opaque_regions"); | ||
| 14 | + | ||
| 15 | + let mut i = 0; | ||
| 16 | + while i < elements.len() { | ||
| 17 | + let elem = &elements[i]; | ||
| 18 | + i += 1; | ||
| 19 | + | ||
| 20 | + // HACK | ||
| 21 | + if format!("{elem:?}").contains("ExtraDamage") { | ||
| 22 | + continue; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + let geo = elem.geometry(scale); | ||
| 26 | + let mut opaque = elem.opaque_regions(scale); | ||
| 27 | + | ||
| 28 | + for rect in &mut opaque { | ||
| 29 | + rect.loc += geo.loc; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + let semitransparent = geo.subtract_rects(opaque.iter().copied()); | ||
| 33 | + | ||
| 34 | + for rect in opaque { | ||
| 35 | + let color = SolidColorRenderElement::new( | ||
| 36 | + Id::new(), | ||
| 37 | + rect, | ||
| 38 | + CommitCounter::default(), | ||
| 39 | + [0., 0., 0.2, 0.2], | ||
| 40 | + Kind::Unspecified, | ||
| 41 | + ); | ||
| 42 | + elements.insert(i - 1, OutputRenderElements::SolidColor(color)); | ||
| 43 | + i += 1; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + for rect in semitransparent { | ||
| 47 | + let color = SolidColorRenderElement::new( | ||
| 48 | + Id::new(), | ||
| 49 | + rect, | ||
| 50 | + CommitCounter::default(), | ||
| 51 | + [0.3, 0., 0., 0.3], | ||
| 52 | + Kind::Unspecified, | ||
| 53 | + ); | ||
| 54 | + elements.insert(i - 1, OutputRenderElements::SolidColor(color)); | ||
| 55 | + i += 1; | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | +} | ||
src/render_helpers/mod.rsmodified+1 -0
| @@ -19,6 +19,7 @@ use self::primary_gpu_texture::PrimaryGpuTextureRenderElement; | |||
| 19 | pub mod border; | 19 | pub mod border; |
| 20 | pub mod clipped_surface; | 20 | pub mod clipped_surface; |
| 21 | pub mod damage; | 21 | pub mod damage; |
| 22 | +pub mod debug; | ||
| 22 | pub mod offscreen; | 23 | pub mod offscreen; |
| 23 | pub mod primary_gpu_texture; | 24 | pub mod primary_gpu_texture; |
| 24 | pub mod render_elements; | 25 | pub mod render_elements; |