[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" |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 18 | #include "ui/accessibility/platform/aura_window_properties.h" |
| 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, |
| 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 | |
| 96 | void 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] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 106 | void ToggleShowDebugBorders() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 107 | aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
reveman | 5be07ac8 | 2017-04-14 01:06:05 | [diff] [blame] | 108 | std::unique_ptr<cc::DebugBorderTypes> value; |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 109 | for (auto* window : root_windows) { |
| 110 | ui::Compositor* compositor = window->GetHost()->compositor(); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 111 | cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState(); |
| 112 | if (!value.get()) |
reveman | 5be07ac8 | 2017-04-14 01:06:05 | [diff] [blame] | 113 | value.reset(new cc::DebugBorderTypes(state.show_debug_borders.flip())); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 114 | state.show_debug_borders = *value.get(); |
| 115 | compositor->SetLayerTreeDebugState(state); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void ToggleShowFpsCounter() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 120 | aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 121 | std::unique_ptr<bool> value; |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 122 | for (auto* window : root_windows) { |
| 123 | ui::Compositor* compositor = window->GetHost()->compositor(); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 124 | 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] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 132 | void ToggleShowPaintRects() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 133 | aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 134 | std::unique_ptr<bool> value; |
Xiaohui Chen | 7861fd0 | 2020-04-20 17:04:16 | [diff] [blame] | 135 | for (auto* window : root_windows) { |
| 136 | ui::Compositor* compositor = window->GetHost()->compositor(); |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 137 | cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState(); |
[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 138 | if (!value.get()) |
[email protected] | 2e77cdbb | 2013-04-29 13:59:14 | [diff] [blame] | 139 | value.reset(new bool(!state.show_paint_rects)); |
| 140 | state.show_paint_rects = *value.get(); |
| 141 | compositor->SetLayerTreeDebugState(state); |
[email protected] | 918f8db4 | 2013-04-27 01:53:40 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
[email protected] | 24f5e24 | 2014-07-22 02:16:09 | [diff] [blame] | 145 | } // namespace debug |
| 146 | } // namespace ash |