blob: 8941a69f6ad94e2791ea49c8a1cd44fa20f2e2c6 [file] [log] [blame]
[email protected]918f8db42013-04-27 01:53:401// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/debug.h"
6
Xiaohui Chen7861fd02020-04-20 17:04:167#include <memory>
8#include <string>
9
10#include "ash/public/cpp/debug_utils.h"
11#include "ash/public/cpp/window_properties.h"
12#include "ash/root_window_controller.h"
[email protected]918f8db42013-04-27 01:53:4013#include "ash/shell.h"
Xiaohui Chen7861fd02020-04-20 17:04:1614#include "ash/wm/window_properties.h"
15#include "ash/wm/window_state.h"
16#include "ash/wm/window_util.h"
[email protected]2e77cdbb2013-04-29 13:59:1417#include "cc/debug/layer_tree_debug_state.h"
Julie Jeongeun Kimc0ca3f82020-05-11 10:46:5418#include "ui/accessibility/aura/aura_window_properties.h"
Xiaohui Chen7861fd02020-04-20 17:04:1619#include "ui/aura/client/aura_constants.h"
[email protected]7a60cd3a2014-03-20 20:54:5720#include "ui/aura/window_tree_host.h"
[email protected]918f8db42013-04-27 01:53:4021#include "ui/compositor/compositor.h"
Xiaohui Chen7861fd02020-04-20 17:04:1622#include "ui/compositor/debug_utils.h"
23#include "ui/views/debug_utils.h"
24#include "ui/views/widget/widget.h"
[email protected]918f8db42013-04-27 01:53:4025
26namespace ash {
27namespace debug {
28
Xiaohui Chen7861fd02020-04-20 17:04:1629void PrintLayerHierarchy(std::ostringstream* out) {
30 for (aura::Window* root : Shell::Get()->GetAllRootWindows()) {
31 ui::Layer* layer = root->layer();
32 if (layer) {
33 ui::PrintLayerHierarchy(
34 layer,
35 RootWindowController::ForWindow(root)->GetLastMouseLocationInRoot(),
36 out);
37 }
38 }
39}
40
41void PrintViewHierarchy(std::ostringstream* out) {
42 aura::Window* active_window = window_util::GetActiveWindow();
43 if (!active_window)
44 return;
45 views::Widget* widget = views::Widget::GetWidgetForNativeView(active_window);
46 if (!widget)
47 return;
48 views::PrintViewHierarchy(widget->GetRootView(), out);
49}
50
51void PrintWindowHierarchy(const aura::Window* active_window,
52 const aura::Window* focused_window,
53 aura::Window* window,
54 int indent,
Xiaohui Chene8fcaca82020-06-24 17:44:3155 bool scrub_data,
Xiaohui Chen7861fd02020-04-20 17:04:1656 std::ostringstream* out) {
57 std::string indent_str(indent, ' ');
58 std::string name(window->GetName());
59 if (name.empty())
60 name = "\"\"";
61 const gfx::Vector2dF& subpixel_position_offset =
62 window->layer()->GetSubpixelOffset();
63 *out << indent_str;
64 *out << name << " (" << window << ")"
65 << " type=" << window->type();
66 int window_id = window->id();
67 if (window_id != aura::Window::kInitialId)
68 *out << " id=" << window_id;
69 if (window->GetProperty(kWindowStateKey))
70 *out << " " << WindowState::Get(window)->GetStateType();
71 *out << ((window == active_window) ? " [active]" : "")
72 << ((window == focused_window) ? " [focused]" : "")
Mitsuru Oshimad35c6922020-04-23 05:38:3773 << (window->transparent() ? " [transparent]" : "")
74 << (window->IsVisible() ? " [visible]" : "") << " "
Xiaohui Chen7861fd02020-04-20 17:04:1675 << (window->occlusion_state() != aura::Window::OcclusionState::UNKNOWN
76 ? aura::Window::OcclusionStateToString(window->occlusion_state())
77 : "")
78 << " " << window->bounds().ToString();
79 if (!subpixel_position_offset.IsZero())
80 *out << " subpixel offset=" + subpixel_position_offset.ToString();
81 std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
82 if (tree_id)
83 *out << " ax_tree_id=" << *tree_id;
Xiaohui Chene8fcaca82020-06-24 17:44:3184
85 if (!scrub_data) {
86 base::string16 title(window->GetTitle());
87 if (!title.empty())
88 *out << " title=" << title;
89 }
90
Xiaohui Chen7861fd02020-04-20 17:04:1691 int app_type = window->GetProperty(aura::client::kAppType);
92 *out << " app_type=" << app_type;
93 std::string* pkg_name = window->GetProperty(ash::kArcPackageNameKey);
94 if (pkg_name)
95 *out << " pkg_name=" << *pkg_name;
96 *out << '\n';
97
Xiaohui Chene8fcaca82020-06-24 17:44:3198 for (aura::Window* child : window->children()) {
99 PrintWindowHierarchy(active_window, focused_window, child, indent + 3,
100 scrub_data, out);
101 }
Xiaohui Chen7861fd02020-04-20 17:04:16102}
103
Xiaohui Chene8fcaca82020-06-24 17:44:31104void PrintWindowHierarchy(std::ostringstream* out, bool scrub_data) {
Xiaohui Chen7861fd02020-04-20 17:04:16105 aura::Window* active_window = window_util::GetActiveWindow();
106 aura::Window* focused_window = window_util::GetFocusedWindow();
107 aura::Window::Windows roots = Shell::Get()->GetAllRootWindows();
108 for (size_t i = 0; i < roots.size(); ++i) {
109 *out << "RootWindow " << i << ":\n";
Xiaohui Chene8fcaca82020-06-24 17:44:31110 PrintWindowHierarchy(active_window, focused_window, roots[i], 0, scrub_data,
111 out);
Xiaohui Chen7861fd02020-04-20 17:04:16112 }
113}
114
[email protected]2e77cdbb2013-04-29 13:59:14115void ToggleShowDebugBorders() {
skycb4be5b2017-04-06 17:52:45116 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
reveman5be07ac82017-04-14 01:06:05117 std::unique_ptr<cc::DebugBorderTypes> value;
Xiaohui Chen7861fd02020-04-20 17:04:16118 for (auto* window : root_windows) {
119 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14120 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
121 if (!value.get())
reveman5be07ac82017-04-14 01:06:05122 value.reset(new cc::DebugBorderTypes(state.show_debug_borders.flip()));
[email protected]2e77cdbb2013-04-29 13:59:14123 state.show_debug_borders = *value.get();
124 compositor->SetLayerTreeDebugState(state);
125 }
126}
127
128void ToggleShowFpsCounter() {
skycb4be5b2017-04-06 17:52:45129 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
dchenga94547472016-04-08 08:41:11130 std::unique_ptr<bool> value;
Xiaohui Chen7861fd02020-04-20 17:04:16131 for (auto* window : root_windows) {
132 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14133 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
134 if (!value.get())
135 value.reset(new bool(!state.show_fps_counter));
136 state.show_fps_counter = *value.get();
137 compositor->SetLayerTreeDebugState(state);
138 }
139}
140
[email protected]918f8db42013-04-27 01:53:40141void ToggleShowPaintRects() {
skycb4be5b2017-04-06 17:52:45142 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
dchenga94547472016-04-08 08:41:11143 std::unique_ptr<bool> value;
Xiaohui Chen7861fd02020-04-20 17:04:16144 for (auto* window : root_windows) {
145 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14146 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
[email protected]918f8db42013-04-27 01:53:40147 if (!value.get())
[email protected]2e77cdbb2013-04-29 13:59:14148 value.reset(new bool(!state.show_paint_rects));
149 state.show_paint_rects = *value.get();
150 compositor->SetLayerTreeDebugState(state);
[email protected]918f8db42013-04-27 01:53:40151 }
152}
153
[email protected]24f5e242014-07-22 02:16:09154} // namespace debug
155} // namespace ash