Skip to main content

incular_runtime/
devtools_inspection.rs

1//! Read-only DevTools inspection requests answered from a window's retained
2//! tree: runtime counters, semantics, compositor layers and work counts.
3//!
4//! These additions live apart from the frame pipeline; nothing here marks the
5//! tree dirty or triggers layout, paint or composition.
6
7use crate::application::Application;
8use incular_devtools_protocol::{
9    DevWindowId, ErrorCode, LayerNodeWire, RuntimeDiagnosticsWire, SemanticsNodeWire,
10    WorkCountEntry,
11};
12use incular_platform::WindowId;
13
14/// Evaluates `$read` with `$tree` bound to the window's retained tree.
15macro_rules! with_tree {
16    ($self:ident, $window:ident, |$tree:ident| $read:expr) => {{
17        let id = WindowId::from_parts(
18            $window.index().saturating_sub(1) as u32,
19            $window.generation() as u32,
20        );
21        let registry = $self.registry.borrow();
22        let record = registry.get(id).ok_or(ErrorCode::StaleId)?;
23        let $tree = record.runtime.tree();
24        Ok($read)
25    }};
26}
27
28impl Application {
29    /// Cumulative widget, text, semantics and compositor counters for one window.
30    pub fn devtools_runtime_diagnostics(
31        &self,
32        window: DevWindowId,
33    ) -> Result<RuntimeDiagnosticsWire, ErrorCode> {
34        with_tree!(self, window, |tree| tree.devtools_runtime_counters())
35    }
36
37    /// Bounded semantics tree snapshot; the flag reports truncation.
38    pub fn devtools_semantics_tree(
39        &self,
40        window: DevWindowId,
41    ) -> Result<(Vec<SemanticsNodeWire>, bool), ErrorCode> {
42        with_tree!(self, window, |tree| tree.devtools_semantics_nodes())
43    }
44
45    /// Bounded compositor layer snapshot; the flag reports truncation.
46    pub fn devtools_layer_tree(
47        &self,
48        window: DevWindowId,
49    ) -> Result<(Vec<LayerNodeWire>, bool), ErrorCode> {
50        with_tree!(self, window, |tree| tree.devtools_layer_nodes())
51    }
52
53    /// Per-element work counters ranked by build count, at most `limit`
54    /// (itself capped at 200).
55    pub fn devtools_work_counts(
56        &self,
57        window: DevWindowId,
58        limit: usize,
59    ) -> Result<Vec<WorkCountEntry>, ErrorCode> {
60        with_tree!(self, window, |tree| tree.devtools_work_counts(limit))
61    }
62}