debug_utils.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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. 4 5#define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 6 7#include "ui/compositor/debug_utils.h" 8 9#include <cmath> 10#include <iomanip> 11#include <ostream> 12#include <string> 13 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" 21 22using base::UTF8ToWide; 23 24namespace ui { 25 26namespace { 27 28void PrintLayerHierarchyImp(const Layer* layer, 29 int indent, 30 gfx::Point mouse_location, 31 std::wostringstream* out) { 32 std::string indent_str(indent, ' '); 33 34 layer->transform().TransformPointReverse(&mouse_location); 35 bool mouse_inside_layer_bounds = layer->bounds().Contains(mouse_location); 36 mouse_location.Offset(-layer->bounds().x(), -layer->bounds().y()); 37 38 *out << UTF8ToWide(indent_str); 39 if (mouse_inside_layer_bounds) 40 *out << L'*'; 41 else 42 *out << L' '; 43 44 *out << UTF8ToWide(layer->name()) << L' ' << layer; 45 46 switch (layer->type()) { 47 case ui::LAYER_NOT_DRAWN: 48 *out << L" not_drawn"; 49 break; 50 case ui::LAYER_TEXTURED: 51 *out << L" textured"; 52 if (layer->fills_bounds_opaquely()) 53 *out << L" opaque"; 54 break; 55 case ui::LAYER_SOLID_COLOR: 56 *out << L" solid"; 57 break; 58 } 59 60 if (!layer->visible()) 61 *out << L" !visible"; 62 63 std::string property_indent_str(indent+3, ' '); 64 *out << L'\n' << UTF8ToWide(property_indent_str); 65 *out << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y(); 66 *out << L' ' << layer->bounds().width() << L'x' << layer->bounds().height(); 67 68 if (layer->opacity() != 1.0f) { 69 *out << L'\n' << UTF8ToWide(property_indent_str); 70 *out << L"opacity: " << std::setprecision(2) << layer->opacity(); 71 } 72 73 gfx::DecomposedTransform decomp; 74 if (!layer->transform().IsIdentity() && 75 gfx::DecomposeTransform(&decomp, layer->transform())) { 76 *out << L'\n' << UTF8ToWide(property_indent_str); 77 *out << L"translation: " << std::fixed << decomp.translate[0]; 78 *out << L", " << decomp.translate[1]; 79 80 *out << L'\n' << UTF8ToWide(property_indent_str); 81 *out << L"rotation: "; 82 *out << std::acos(decomp.quaternion[3]) * 360.0 / M_PI; 83 84 *out << L'\n' << UTF8ToWide(property_indent_str); 85 *out << L"scale: " << decomp.scale[0]; 86 *out << L", " << decomp.scale[1]; 87 } 88 89 *out << L'\n'; 90 91 for (size_t i = 0, count = layer->children().size(); i < count; ++i) { 92 PrintLayerHierarchyImp( 93 layer->children()[i], indent + 3, mouse_location, out); 94 } 95} 96 97} // namespace 98 99void PrintLayerHierarchy(const Layer* layer, gfx::Point mouse_location) { 100 std::wostringstream out; 101 out << L"Layer hierarchy:\n"; 102 PrintLayerHierarchyImp(layer, 0, mouse_location, &out); 103 // Error so logs can be collected from end-users. 104 LOG(ERROR) << out.str(); 105} 106 107} // namespace ui 108