[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 1 | // 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 Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 7 | #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] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 13 | #include "ash/shell.h" |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 14 | #include "ash/wm/window_properties.h" |
| 15 | #include "ash/wm/window_state.h" |
| 16 | #include "ash/wm/window_util.h" |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 17 | #include "cc/debug/layer_tree_debug_state.h" |
Julie Jeongeun Kim | c0ca3f8 | 2020-05-11 10:46:54 | [diff] [blame] | 18 | #include "ui/accessibility/aura/aura_window_properties.h" |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 19 | #include "ui/aura/client/aura_constants.h" |
[email protected] | 7a60cd3a | 2014-03-20 20:54:57 | [diff] [blame] | 20 | #include "ui/aura/window_tree_host.h" |
[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 21 | #include "ui/compositor/compositor.h" |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 22 | #include "ui/compositor/debug_utils.h" |
| 23 | #include "ui/views/debug_utils.h" |
| 24 | #include "ui/views/widget/widget.h" |
[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 25 | |
| 26 | namespace ash { |
| 27 | namespace debug { |
| 28 | |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 29 | void 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 | |
| 41 | void 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 | |
| 51 | void PrintWindowHierarchy(const aura::Window* active_window, |
| 52 | const aura::Window* focused_window, |
| 53 | aura::Window* window, |
| 54 | int indent, |
Xiaohui Chen | e8fcaca8 | 2020-06-24 17:44:31 | [diff] [blame] | 55 | bool scrub_data, |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 56 | 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 Oshima | d35c692 | 2020-04-23 05:38:37 | [diff] [blame] | 73 | << (window->transparent() ? " [transparent]" : "") |
| 74 | << (window->IsVisible() ? " [visible]" : "") << " " |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 75 | << (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 Chen | e8fcaca8 | 2020-06-24 17:44:31 | [diff] [blame] | 84 | |
| 85 | if (!scrub_data) { |
| 86 | base::string16 title(window->GetTitle()); |
| 87 | if (!title.empty()) |
| 88 | *out << " title=" << title; |
| 89 | } |
| 90 | |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 91 | 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 Chen | e8fcaca8 | 2020-06-24 17:44:31 | [diff] [blame] | 98 | for (aura::Window* child : window->children()) { |
| 99 | PrintWindowHierarchy(active_window, focused_window, child, indent + 3, |
| 100 | scrub_data, out); |
| 101 | } |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 102 | } |
| 103 | |
Xiaohui Chen | e8fcaca8 | 2020-06-24 17:44:31 | [diff] [blame] | 104 | void PrintWindowHierarchy(std::ostringstream* out, bool scrub_data) { |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 105 | 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 Chen | e8fcaca8 | 2020-06-24 17:44:31 | [diff] [blame] | 110 | PrintWindowHierarchy(active_window, focused_window, roots[i], 0, scrub_data, |
| 111 | out); |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 115 | void ToggleShowDebugBorders() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 116 | aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
reveman | 5be07ac8 | 2017-04-14 01:06:05 | [diff] [blame] | 117 | std::unique_ptr<cc::DebugBorderTypes> value; |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 118 | for (auto* window : root_windows) { |
| 119 | ui::Compositor* compositor = window->GetHost()->compositor(); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 120 | cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState(); |
| 121 | if (!value.get()) |
reveman | 5be07ac8 | 2017-04-14 01:06:05 | [diff] [blame] | 122 | value.reset(new cc::DebugBorderTypes(state.show_debug_borders.flip())); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 123 | state.show_debug_borders = *value.get(); |
| 124 | compositor->SetLayerTreeDebugState(state); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void ToggleShowFpsCounter() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 129 | aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 130 | std::unique_ptr<bool> value; |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 131 | for (auto* window : root_windows) { |
| 132 | ui::Compositor* compositor = window->GetHost()->compositor(); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 133 | 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] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 141 | void ToggleShowPaintRects() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 142 | aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 143 | std::unique_ptr<bool> value; |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 144 | for (auto* window : root_windows) { |
| 145 | ui::Compositor* compositor = window->GetHost()->compositor(); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 146 | cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState(); |
[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 147 | if (!value.get()) |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 148 | value.reset(new bool(!state.show_paint_rects)); |
| 149 | state.show_paint_rects = *value.get(); |
| 150 | compositor->SetLayerTreeDebugState(state); |
[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
[email protected] | 24f5e24 | 2014-07-22 02:16:09 | [diff] [blame] | 154 | } // namespace debug |
| 155 | } // namespace ash |