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
3 // found in the LICENSE file.
5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
7 #include "ui/compositor/debug_utils.h"
14 #include "base/logging.h"
15 #include "base/utf_string_conversions.h"
16 #include "ui/compositor/layer.h"
17 #include "ui/gfx/interpolated_transform.h"
18 #include "ui/gfx/point.h"
19 #include "ui/gfx/point_conversions.h"
20 #include "ui/gfx/transform.h"
26 void PrintLayerHierarchyImp(const Layer
* layer
,
28 gfx::Point mouse_location
,
29 std::wostringstream
* out
) {
30 std::string
indent_str(indent
, ' ');
31 std::string
content_indent_str(indent
+1, ' ');
33 layer
->transform().TransformPointReverse(mouse_location
);
34 bool mouse_inside_layer_bounds
= layer
->bounds().Contains(mouse_location
);
35 mouse_location
.Offset(-layer
->bounds().x(), -layer
->bounds().y());
37 *out
<< UTF8ToWide(indent_str
);
38 if (mouse_inside_layer_bounds
)
43 *out
<< UTF8ToWide(layer
->name()) << L
' ' << layer
;
45 switch (layer
->type()) {
46 case ui::LAYER_NOT_DRAWN
:
47 *out
<< L
" not_drawn";
49 case ui::LAYER_TEXTURED
:
51 if (layer
->fills_bounds_opaquely())
54 case ui::LAYER_SOLID_COLOR
:
59 if (!layer
->visible())
62 std::string
property_indent_str(indent
+3, ' ');
63 *out
<< L
'\n' << UTF8ToWide(property_indent_str
);
64 *out
<< L
"bounds: " << layer
->bounds().x() << L
',' << layer
->bounds().y();
65 *out
<< L
' ' << layer
->bounds().width() << L
'x' << layer
->bounds().height();
67 if (layer
->opacity() != 1.0f
) {
68 *out
<< L
'\n' << UTF8ToWide(property_indent_str
);
69 *out
<< L
"opacity: " << std::setprecision(2) << layer
->opacity();
72 gfx::DecomposedTransform decomp
;
73 if (!layer
->transform().IsIdentity() &&
74 gfx::DecomposeTransform(&decomp
, layer
->transform())) {
75 *out
<< L
'\n' << UTF8ToWide(property_indent_str
);
76 *out
<< L
"translation: " << std::fixed
<< decomp
.translate
[0];
77 *out
<< L
", " << decomp
.translate
[1];
79 *out
<< L
'\n' << UTF8ToWide(property_indent_str
);
80 *out
<< L
"rotation: ";
81 *out
<< std::acos(decomp
.quaternion
[3]) * 360.0 / M_PI
;
83 *out
<< L
'\n' << UTF8ToWide(property_indent_str
);
84 *out
<< L
"scale: " << decomp
.scale
[0];
85 *out
<< L
", " << decomp
.scale
[1];
90 for (size_t i
= 0, count
= layer
->children().size(); i
< count
; ++i
) {
91 PrintLayerHierarchyImp(
92 layer
->children()[i
], indent
+ 3, mouse_location
, out
);
98 void PrintLayerHierarchy(const Layer
* layer
, gfx::Point 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();