1use std::collections::BTreeMap;
2
3use sui_core::{DirtyRegion, Size, WindowId};
4use sui_platform::AccessibilitySnapshot;
5use sui_runtime::{FocusState, WidgetGraphSnapshot};
6use sui_scene::{SceneCommand, SceneFrame};
7
8#[derive(Debug, Clone, PartialEq)]
9pub struct SceneSummary {
10 pub viewport: Size,
11 pub dirty_regions: Vec<DirtyRegion>,
12 pub command_count: usize,
13 pub command_breakdown: Vec<(String, usize)>,
14}
15
16impl SceneSummary {
17 pub(crate) fn from_frame(frame: &SceneFrame) -> Self {
18 let mut command_breakdown = BTreeMap::<String, usize>::new();
19 let mut command_count = 0usize;
20 frame.scene.visit_commands(&mut |command| {
21 command_count += 1;
22 *command_breakdown
23 .entry(command_kind(command).to_string())
24 .or_default() += 1;
25 });
26
27 Self {
28 viewport: frame.viewport,
29 dirty_regions: frame.dirty_regions.clone(),
30 command_count,
31 command_breakdown: command_breakdown.into_iter().collect(),
32 }
33 }
34}
35
36#[derive(Debug, Clone, PartialEq)]
37pub struct WindowSnapshot {
38 pub window_id: WindowId,
39 pub title: String,
40 pub accessibility: AccessibilitySnapshot,
41 pub widget_graph: WidgetGraphSnapshot,
42 pub focus_state: FocusState,
43 pub scene_summary: Option<SceneSummary>,
44}
45
46fn command_kind(command: &SceneCommand) -> &'static str {
47 match command {
48 SceneCommand::Clear(_) => "Clear",
49 SceneCommand::FillRect { .. } => "FillRect",
50 SceneCommand::StrokeRect { .. } => "StrokeRect",
51 SceneCommand::FillPath { .. } => "FillPath",
52 SceneCommand::StrokePath { .. } => "StrokePath",
53 SceneCommand::DrawText(_) => "DrawText",
54 SceneCommand::DrawShapedText(_) => "DrawShapedText",
55 SceneCommand::DrawShapedTextWindow(_) => "DrawShapedTextWindow",
56 SceneCommand::DrawImage { .. } | SceneCommand::DrawImageQuad { .. } => "DrawImage",
57 SceneCommand::DrawShaderRect { .. } => "DrawShaderRect",
58 SceneCommand::PushClip { .. } => "PushClip",
59 SceneCommand::PushClipPath { .. } => "PushClipPath",
60 SceneCommand::PopClip => "PopClip",
61 SceneCommand::PushTransform { .. } => "PushTransform",
62 SceneCommand::PopTransform => "PopTransform",
63 SceneCommand::PushTextRenderPolicy { .. } => "PushTextRenderPolicy",
64 SceneCommand::PopTextRenderPolicy => "PopTextRenderPolicy",
65 SceneCommand::Layer(_) => "Layer",
66 SceneCommand::FillRoundedRect { .. } => "FillRoundedRect",
67 SceneCommand::Label { .. } => "Label",
68 }
69}