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/strings/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, ' ');
32 layer->transform().TransformPointReverse(&mouse_location);
33 bool mouse_inside_layer_bounds = layer->bounds().Contains(mouse_location);
34 mouse_location.Offset(-layer->bounds().x(), -layer->bounds().y());
36 *out << UTF8ToWide(indent_str);
37 if (mouse_inside_layer_bounds)
42 *out << UTF8ToWide(layer->name()) << L' ' << layer;
44 switch (layer->type()) {
45 case ui::LAYER_NOT_DRAWN:
46 *out << L" not_drawn";
48 case ui::LAYER_TEXTURED:
50 if (layer->fills_bounds_opaquely())
53 case ui::LAYER_SOLID_COLOR:
58 if (!layer->visible())
61 std::string property_indent_str(indent+3, ' ');
62 *out << L'\n' << UTF8ToWide(property_indent_str);
63 *out << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y();
64 *out << L' ' << layer->bounds().width() << L'x' << layer->bounds().height();
66 if (layer->opacity() != 1.0f) {
67 *out << L'\n' << UTF8ToWide(property_indent_str);
68 *out << L"opacity: " << std::setprecision(2) << layer->opacity();
71 gfx::DecomposedTransform decomp;
72 if (!layer->transform().IsIdentity() &&
73 gfx::DecomposeTransform(&decomp, layer->transform())) {
74 *out << L'\n' << UTF8ToWide(property_indent_str);
75 *out << L"translation: " << std::fixed << decomp.translate[0];
76 *out << L", " << decomp.translate[1];
78 *out << L'\n' << UTF8ToWide(property_indent_str);
79 *out << L"rotation: ";
80 *out << std::acos(decomp.quaternion[3]) * 360.0 / M_PI;
82 *out << L'\n' << UTF8ToWide(property_indent_str);
83 *out << L"scale: " << decomp.scale[0];
84 *out << L", " << decomp.scale[1];
89 for (size_t i = 0, count = layer->children().size(); i < count; ++i) {
90 PrintLayerHierarchyImp(
91 layer->children()[i], indent + 3, mouse_location, out);
97 void PrintLayerHierarchy(const Layer* layer, gfx::Point mouse_location) {
98 std::wostringstream out;
99 out << L"Layer hierarchy:\n";
100 PrintLayerHierarchyImp(layer, 0, mouse_location, &out);
101 // Error so logs can be collected from end-users.
102 LOG(ERROR) << out.str();