1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
10 #include "ash/public/cpp/debug_utils.h"
11 #include "ash/public/cpp/window_properties.h"
12 #include "ash/root_window_controller.h"
13 #include "ash/shell.h"
14 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_util.h"
17 #include "cc/debug/layer_tree_debug_state.h"
18 #include "ui/accessibility/aura/aura_window_properties.h"
19 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/window_tree_host.h"
21 #include "ui/compositor/compositor.h"
22 #include "ui/compositor/debug_utils.h"
23 #include "ui/compositor/layer.h"
24 #include "ui/views/debug_utils.h"
25 #include "ui/views/widget/widget.h"
30 void PrintLayerHierarchy(std::ostringstream* out) {
31 for (aura::Window* root : Shell::Get()->GetAllRootWindows()) {
32 ui::Layer* layer = root->layer();
34 ui::PrintLayerHierarchy(
36 RootWindowController::ForWindow(root)->GetLastMouseLocationInRoot(),
42 void PrintViewHierarchy(std::ostringstream* out) {
43 aura::Window* active_window = window_util::GetActiveWindow();
46 views::Widget* widget = views::Widget::GetWidgetForNativeView(active_window);
50 *out << "Host widget:\n";
51 views::PrintWidgetInformation(*widget, /*detailed*/ true, out);
52 views::PrintViewHierarchy(widget->GetRootView(), out);
55 void PrintWindowHierarchy(const aura::Window* active_window,
56 const aura::Window* focused_window,
57 const aura::Window* capture_window,
61 std::vector<std::string>* out_window_titles,
62 std::ostringstream* out) {
63 std::string indent_str(indent, ' ');
64 std::string name(window->GetName());
67 const gfx::Vector2dF& subpixel_position_offset =
68 window->layer()->GetSubpixelOffset();
71 *out << " " << name << " (" << window << ")"
72 << " type=" << window->GetType();
73 int window_id = window->GetId();
74 if (window_id != aura::Window::kInitialId)
75 *out << " id=" << window_id;
76 if (window->GetProperty(kWindowStateKey))
77 *out << " " << WindowState::Get(window)->GetStateType();
78 *out << ((window == active_window) ? " [active]" : "")
79 << ((window == focused_window) ? " [focused]" : "")
80 << ((window == capture_window) ? " [capture]" : "")
81 << (window->GetTransparent() ? " [transparent]" : "")
82 << (window->IsVisible() ? " [visible]" : "") << " "
83 << (window->GetOcclusionState() != aura::Window::OcclusionState::UNKNOWN
84 ? base::UTF16ToUTF8(aura::Window::OcclusionStateToString(
85 window->GetOcclusionState()))
88 << " " << window->bounds().ToString();
89 if (!subpixel_position_offset.IsZero())
90 *out << " subpixel offset=" + subpixel_position_offset.ToString();
91 std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
93 *out << " ax_tree_id=" << *tree_id;
95 std::u16string title(window->GetTitle());
97 out_window_titles->push_back(base::UTF16ToUTF8(title));
99 *out << " title=" << title;
103 int app_type = window->GetProperty(aura::client::kAppType);
104 *out << " app_type=" << app_type;
105 std::string* pkg_name = window->GetProperty(ash::kArcPackageNameKey);
107 *out << " pkg_name=" << *pkg_name;
110 views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
112 *out << std::string(indent + 3, ' ');
114 views::PrintWidgetInformation(*widget, /*detailed*/ false, out);
117 for (aura::Window* child : window->children()) {
118 PrintWindowHierarchy(active_window, focused_window, capture_window, child,
119 indent + 3, scrub_data, out_window_titles, out);
123 std::vector<std::string> PrintWindowHierarchy(std::ostringstream* out,
125 aura::Window* active_window = window_util::GetActiveWindow();
126 aura::Window* focused_window = window_util::GetFocusedWindow();
127 aura::Window* capture_window = window_util::GetCaptureWindow();
128 aura::Window::Windows roots = Shell::Get()->GetAllRootWindows();
129 std::vector<std::string> window_titles;
130 for (size_t i = 0; i < roots.size(); ++i) {
131 *out << "RootWindow " << i << ":\n";
132 PrintWindowHierarchy(active_window, focused_window, capture_window,
133 roots[i], 0, scrub_data, &window_titles, out);
135 return window_titles;
138 void ToggleShowDebugBorders() {
139 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
140 std::unique_ptr<cc::DebugBorderTypes> value;
141 for (auto* window : root_windows) {
142 ui::Compositor* compositor = window->GetHost()->compositor();
143 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
145 value = std::make_unique<cc::DebugBorderTypes>(
146 state.show_debug_borders.flip());
147 state.show_debug_borders = *value.get();
148 compositor->SetLayerTreeDebugState(state);
152 void ToggleShowFpsCounter() {
153 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
154 std::unique_ptr<bool> value;
155 for (auto* window : root_windows) {
156 ui::Compositor* compositor = window->GetHost()->compositor();
157 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
159 value = std::make_unique<bool>(!state.show_fps_counter);
160 state.show_fps_counter = *value.get();
161 compositor->SetLayerTreeDebugState(state);
165 void ToggleShowPaintRects() {
166 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
167 std::unique_ptr<bool> value;
168 for (auto* window : root_windows) {
169 ui::Compositor* compositor = window->GetHost()->compositor();
170 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
172 value = std::make_unique<bool>(!state.show_paint_rects);
173 state.show_paint_rects = *value.get();
174 compositor->SetLayerTreeDebugState(state);