blob: 49fbc78db0de0903eac1cd13ba8a2d73134a0acf [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"
Xiaohui Chen7861fd02020-04-20 17:04:1618#include "ui/accessibility/platform/aura_window_properties.h"
19#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,
55 std::ostringstream* out) {
56 std::string indent_str(indent, ' ');
57 std::string name(window->GetName());
58 if (name.empty())
59 name = "\"\"";
60 const gfx::Vector2dF& subpixel_position_offset =
61 window->layer()->GetSubpixelOffset();
62 *out << indent_str;
63 *out << name << " (" << window << ")"
64 << " type=" << window->type();
65 int window_id = window->id();
66 if (window_id != aura::Window::kInitialId)
67 *out << " id=" << window_id;
68 if (window->GetProperty(kWindowStateKey))
69 *out << " " << WindowState::Get(window)->GetStateType();
70 *out << ((window == active_window) ? " [active]" : "")
71 << ((window == focused_window) ? " [focused]" : "")
Mitsuru Oshimad35c6922020-04-23 05:38:3772 << (window->transparent() ? " [transparent]" : "")
73 << (window->IsVisible() ? " [visible]" : "") << " "
Xiaohui Chen7861fd02020-04-20 17:04:1674 << (window->occlusion_state() != aura::Window::OcclusionState::UNKNOWN
75 ? aura::Window::OcclusionStateToString(window->occlusion_state())
76 : "")
77 << " " << window->bounds().ToString();
78 if (!subpixel_position_offset.IsZero())
79 *out << " subpixel offset=" + subpixel_position_offset.ToString();
80 std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
81 if (tree_id)
82 *out << " ax_tree_id=" << *tree_id;
83 base::string16 title(window->GetTitle());
84 if (!title.empty())
85 *out << " title=" << title;
86 int app_type = window->GetProperty(aura::client::kAppType);
87 *out << " app_type=" << app_type;
88 std::string* pkg_name = window->GetProperty(ash::kArcPackageNameKey);
89 if (pkg_name)
90 *out << " pkg_name=" << *pkg_name;
91 *out << '\n';
92
93 for (aura::Window* child : window->children())
94 PrintWindowHierarchy(active_window, focused_window, child, indent + 3, out);
95}
96
97void PrintWindowHierarchy(std::ostringstream* out) {
98 aura::Window* active_window = window_util::GetActiveWindow();
99 aura::Window* focused_window = window_util::GetFocusedWindow();
100 aura::Window::Windows roots = Shell::Get()->GetAllRootWindows();
101 for (size_t i = 0; i < roots.size(); ++i) {
102 *out << "RootWindow " << i << ":\n";
103 PrintWindowHierarchy(active_window, focused_window, roots[i], 0, out);
104 }
105}
106
[email protected]2e77cdbb2013-04-29 13:59:14107void ToggleShowDebugBorders() {
skycb4be5b2017-04-06 17:52:45108 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
reveman5be07ac82017-04-14 01:06:05109 std::unique_ptr<cc::DebugBorderTypes> value;
Xiaohui Chen7861fd02020-04-20 17:04:16110 for (auto* window : root_windows) {
111 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14112 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
113 if (!value.get())
reveman5be07ac82017-04-14 01:06:05114 value.reset(new cc::DebugBorderTypes(state.show_debug_borders.flip()));
[email protected]2e77cdbb2013-04-29 13:59:14115 state.show_debug_borders = *value.get();
116 compositor->SetLayerTreeDebugState(state);
117 }
118}
119
120void ToggleShowFpsCounter() {
skycb4be5b2017-04-06 17:52:45121 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
dchenga94547472016-04-08 08:41:11122 std::unique_ptr<bool> value;
Xiaohui Chen7861fd02020-04-20 17:04:16123 for (auto* window : root_windows) {
124 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14125 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
126 if (!value.get())
127 value.reset(new bool(!state.show_fps_counter));
128 state.show_fps_counter = *value.get();
129 compositor->SetLayerTreeDebugState(state);
130 }
131}
132
[email protected]918f8db42013-04-27 01:53:40133void ToggleShowPaintRects() {
skycb4be5b2017-04-06 17:52:45134 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
dchenga94547472016-04-08 08:41:11135 std::unique_ptr<bool> value;
Xiaohui Chen7861fd02020-04-20 17:04:16136 for (auto* window : root_windows) {
137 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14138 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
[email protected]918f8db42013-04-27 01:53:40139 if (!value.get())
[email protected]2e77cdbb2013-04-29 13:59:14140 value.reset(new bool(!state.show_paint_rects));
141 state.show_paint_rects = *value.get();
142 compositor->SetLayerTreeDebugState(state);
[email protected]918f8db42013-04-27 01:53:40143 }
144}
145
[email protected]24f5e242014-07-22 02:16:09146} // namespace debug
147} // namespace ash