OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NDEBUG | |
6 | |
7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
8 | 6 |
9 #include "ui/compositor/debug_utils.h" | 7 #include "ui/compositor/debug_utils.h" |
10 | 8 |
11 #include <cmath> | 9 #include <cmath> |
12 #include <iomanip> | 10 #include <iomanip> |
13 #include <iostream> | 11 #include <iostream> |
14 #include <string> | 12 #include <string> |
15 | 13 |
16 #include "base/logging.h" | 14 #include "base/logging.h" |
17 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
18 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
19 #include "ui/gfx/interpolated_transform.h" | 17 #include "ui/gfx/interpolated_transform.h" |
20 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
21 #include "ui/gfx/point_conversions.h" | 19 #include "ui/gfx/point_conversions.h" |
22 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
23 | 21 |
24 namespace ui { | 22 namespace ui { |
25 | 23 |
26 namespace { | 24 namespace { |
27 | 25 |
28 void PrintLayerHierarchyImp(const Layer* layer, int indent, | 26 void PrintLayerHierarchyImp(const Layer* layer, |
29 gfx::Point mouse_location) { | 27 int indent, |
30 std::wostringstream buf; | 28 gfx::Point mouse_location, |
| 29 std::wostringstream* out) { |
31 std::string indent_str(indent, ' '); | 30 std::string indent_str(indent, ' '); |
32 std::string content_indent_str(indent+1, ' '); | 31 std::string content_indent_str(indent+1, ' '); |
33 | 32 |
34 layer->transform().TransformPointReverse(mouse_location); | 33 layer->transform().TransformPointReverse(mouse_location); |
35 bool mouse_inside_layer_bounds = layer->bounds().Contains(mouse_location); | 34 bool mouse_inside_layer_bounds = layer->bounds().Contains(mouse_location); |
36 mouse_location.Offset(-layer->bounds().x(), -layer->bounds().y()); | 35 mouse_location.Offset(-layer->bounds().x(), -layer->bounds().y()); |
37 | 36 |
38 buf << UTF8ToWide(indent_str); | 37 *out << UTF8ToWide(indent_str); |
39 if (mouse_inside_layer_bounds) | 38 if (mouse_inside_layer_bounds) |
40 buf << L'*'; | 39 *out << L'*'; |
41 else | 40 else |
42 buf << L' '; | 41 *out << L' '; |
43 | 42 |
44 buf << UTF8ToWide(layer->name()) << L' ' << layer; | 43 *out << UTF8ToWide(layer->name()) << L' ' << layer; |
45 | 44 |
46 switch (layer->type()) { | 45 switch (layer->type()) { |
47 case ui::LAYER_NOT_DRAWN: | 46 case ui::LAYER_NOT_DRAWN: |
48 buf << L" not_drawn"; | 47 *out << L" not_drawn"; |
49 break; | 48 break; |
50 case ui::LAYER_TEXTURED: | 49 case ui::LAYER_TEXTURED: |
51 buf << L" textured"; | 50 *out << L" textured"; |
52 if (layer->fills_bounds_opaquely()) | 51 if (layer->fills_bounds_opaquely()) |
53 buf << L" opaque"; | 52 *out << L" opaque"; |
54 break; | 53 break; |
55 case ui::LAYER_SOLID_COLOR: | 54 case ui::LAYER_SOLID_COLOR: |
56 buf << L" solid"; | 55 *out << L" solid"; |
57 break; | 56 break; |
58 } | 57 } |
59 | 58 |
60 if (!layer->visible()) | 59 if (!layer->visible()) |
61 buf << L" !visible"; | 60 *out << L" !visible"; |
62 | 61 |
63 std::string property_indent_str(indent+3, ' '); | 62 std::string property_indent_str(indent+3, ' '); |
64 buf << L'\n' << UTF8ToWide(property_indent_str); | 63 *out << L'\n' << UTF8ToWide(property_indent_str); |
65 buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y(); | 64 *out << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y(); |
66 buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height(); | 65 *out << L' ' << layer->bounds().width() << L'x' << layer->bounds().height(); |
67 | 66 |
68 if (layer->opacity() != 1.0f) { | 67 if (layer->opacity() != 1.0f) { |
69 buf << L'\n' << UTF8ToWide(property_indent_str); | 68 *out << L'\n' << UTF8ToWide(property_indent_str); |
70 buf << L"opacity: " << std::setprecision(2) << layer->opacity(); | 69 *out << L"opacity: " << std::setprecision(2) << layer->opacity(); |
71 } | 70 } |
72 | 71 |
73 gfx::DecomposedTransform decomp; | 72 gfx::DecomposedTransform decomp; |
74 if (!layer->transform().IsIdentity() && | 73 if (!layer->transform().IsIdentity() && |
75 gfx::DecomposeTransform(&decomp, layer->transform())) { | 74 gfx::DecomposeTransform(&decomp, layer->transform())) { |
76 buf << L'\n' << UTF8ToWide(property_indent_str); | 75 *out << L'\n' << UTF8ToWide(property_indent_str); |
77 buf << L"translation: " << std::fixed << decomp.translate[0]; | 76 *out << L"translation: " << std::fixed << decomp.translate[0]; |
78 buf << L", " << decomp.translate[1]; | 77 *out << L", " << decomp.translate[1]; |
79 | 78 |
80 buf << L'\n' << UTF8ToWide(property_indent_str); | 79 *out << L'\n' << UTF8ToWide(property_indent_str); |
81 buf << L"rotation: "; | 80 *out << L"rotation: "; |
82 buf << std::acos(decomp.quaternion[3]) * 360.0 / M_PI; | 81 *out << std::acos(decomp.quaternion[3]) * 360.0 / M_PI; |
83 | 82 |
84 buf << L'\n' << UTF8ToWide(property_indent_str); | 83 *out << L'\n' << UTF8ToWide(property_indent_str); |
85 buf << L"scale: " << decomp.scale[0]; | 84 *out << L"scale: " << decomp.scale[0]; |
86 buf << L", " << decomp.scale[1]; | 85 *out << L", " << decomp.scale[1]; |
87 } | 86 } |
88 | 87 |
89 VLOG(1) << buf.str(); | 88 *out << L'\n'; |
90 std::cout << buf.str() << std::endl; | |
91 | 89 |
92 for (size_t i = 0, count = layer->children().size(); i < count; ++i) | 90 for (size_t i = 0, count = layer->children().size(); i < count; ++i) { |
93 PrintLayerHierarchyImp(layer->children()[i], indent + 3, mouse_location); | 91 PrintLayerHierarchyImp( |
| 92 layer->children()[i], indent + 3, mouse_location, out); |
| 93 } |
94 } | 94 } |
95 | 95 |
96 } // namespace | 96 } // namespace |
97 | 97 |
98 void PrintLayerHierarchy(const Layer* layer, gfx::Point mouse_location) { | 98 void PrintLayerHierarchy(const Layer* layer, gfx::Point mouse_location) { |
99 PrintLayerHierarchyImp(layer, 0, mouse_location); | 99 std::wostringstream out; |
| 100 out << L"Layer hierarchy:\n"; |
| 101 PrintLayerHierarchyImp(layer, 0, mouse_location, &out); |
| 102 // Error so logs can be collected from end-users. |
| 103 LOG(ERROR) << out.str(); |
100 } | 104 } |
101 | 105 |
102 } // namespace ui | 106 } // namespace ui |
103 | |
104 #endif // NDEBUG | |
OLD | NEW |