blob: 3b4c540e9fc7b3b93b5ce2b5d4010052392a6a3f [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]" : "")
72 << (window->IsVisible() ? " visible" : "") << " "
73 << (window->occlusion_state() != aura::Window::OcclusionState::UNKNOWN
74 ? aura::Window::OcclusionStateToString(window->occlusion_state())
75 : "")
76 << " " << window->bounds().ToString();
77 if (!subpixel_position_offset.IsZero())
78 *out << " subpixel offset=" + subpixel_position_offset.ToString();
79 std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
80 if (tree_id)
81 *out << " ax_tree_id=" << *tree_id;
82 base::string16 title(window->GetTitle());
83 if (!title.empty())
84 *out << " title=" << title;
85 int app_type = window->GetProperty(aura::client::kAppType);
86 *out << " app_type=" << app_type;
87 std::string* pkg_name = window->GetProperty(ash::kArcPackageNameKey);
88 if (pkg_name)
89 *out << " pkg_name=" << *pkg_name;
90 *out << '\n';
91
92 for (aura::Window* child : window->children())
93 PrintWindowHierarchy(active_window, focused_window, child, indent + 3, out);
94}
95
96void PrintWindowHierarchy(std::ostringstream* out) {
97 aura::Window* active_window = window_util::GetActiveWindow();
98 aura::Window* focused_window = window_util::GetFocusedWindow();
99 aura::Window::Windows roots = Shell::Get()->GetAllRootWindows();
100 for (size_t i = 0; i < roots.size(); ++i) {
101 *out << "RootWindow " << i << ":\n";
102 PrintWindowHierarchy(active_window, focused_window, roots[i], 0, out);
103 }
104}
105
[email protected]2e77cdbb2013-04-29 13:59:14106void ToggleShowDebugBorders() {
skycb4be5b2017-04-06 17:52:45107 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
reveman5be07ac82017-04-14 01:06:05108 std::unique_ptr<cc::DebugBorderTypes> value;
Xiaohui Chen7861fd02020-04-20 17:04:16109 for (auto* window : root_windows) {
110 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14111 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
112 if (!value.get())
reveman5be07ac82017-04-14 01:06:05113 value.reset(new cc::DebugBorderTypes(state.show_debug_borders.flip()));
[email protected]2e77cdbb2013-04-29 13:59:14114 state.show_debug_borders = *value.get();
115 compositor->SetLayerTreeDebugState(state);
116 }
117}
118
119void ToggleShowFpsCounter() {
skycb4be5b2017-04-06 17:52:45120 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
dchenga94547472016-04-08 08:41:11121 std::unique_ptr<bool> value;
Xiaohui Chen7861fd02020-04-20 17:04:16122 for (auto* window : root_windows) {
123 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14124 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
125 if (!value.get())
126 value.reset(new bool(!state.show_fps_counter));
127 state.show_fps_counter = *value.get();
128 compositor->SetLayerTreeDebugState(state);
129 }
130}
131
[email protected]918f8db42013-04-27 01:53:40132void ToggleShowPaintRects() {
skycb4be5b2017-04-06 17:52:45133 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
dchenga94547472016-04-08 08:41:11134 std::unique_ptr<bool> value;
Xiaohui Chen7861fd02020-04-20 17:04:16135 for (auto* window : root_windows) {
136 ui::Compositor* compositor = window->GetHost()->compositor();
[email protected]2e77cdbb2013-04-29 13:59:14137 cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
[email protected]918f8db42013-04-27 01:53:40138 if (!value.get())
[email protected]2e77cdbb2013-04-29 13:59:14139 value.reset(new bool(!state.show_paint_rects));
140 state.show_paint_rects = *value.get();
141 compositor->SetLayerTreeDebugState(state);
[email protected]918f8db42013-04-27 01:53:40142 }
143}
144
[email protected]24f5e242014-07-22 02:16:09145} // namespace debug
146} // namespace ash