| OLD | NEW |
| (Empty) |
| 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 #ifndef NDEBUG | |
| 6 | |
| 7 #include "ui/gfx/compositor/debug_utils.h" | |
| 8 | |
| 9 #include <iomanip> | |
| 10 #include <iostream> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/logging.h" | |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "ui/gfx/compositor/layer.h" | |
| 16 #include "ui/gfx/interpolated_transform.h" | |
| 17 #include "ui/gfx/point.h" | |
| 18 #include "ui/gfx/transform.h" | |
| 19 | |
| 20 namespace ui { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 void PrintLayerHierarchyImp(const Layer* layer, int indent, | |
| 25 gfx::Point mouse_location) { | |
| 26 if (!layer->visible()) | |
| 27 return; | |
| 28 | |
| 29 std::wostringstream buf; | |
| 30 std::string indent_str(indent, ' '); | |
| 31 std::string content_indent_str(indent+1, ' '); | |
| 32 | |
| 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()); | |
| 36 | |
| 37 buf << UTF8ToWide(indent_str); | |
| 38 if (mouse_inside_layer_bounds) | |
| 39 buf << L'*'; | |
| 40 else | |
| 41 buf << L' '; | |
| 42 | |
| 43 buf << UTF8ToWide(layer->name()) << L' ' << layer; | |
| 44 | |
| 45 switch (layer->type()) { | |
| 46 case ui::LAYER_NOT_DRAWN: | |
| 47 buf << L" not_drawn"; | |
| 48 break; | |
| 49 case ui::LAYER_TEXTURED: | |
| 50 buf << L" textured"; | |
| 51 if (layer->fills_bounds_opaquely()) | |
| 52 buf << L" opaque"; | |
| 53 break; | |
| 54 case ui::LAYER_SOLID_COLOR: | |
| 55 buf << L" solid"; | |
| 56 break; | |
| 57 } | |
| 58 | |
| 59 buf << L'\n' << UTF8ToWide(content_indent_str); | |
| 60 buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y(); | |
| 61 buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height(); | |
| 62 | |
| 63 if (layer->opacity() != 1.0f) { | |
| 64 buf << L'\n' << UTF8ToWide(content_indent_str); | |
| 65 buf << L"opacity: " << std::setprecision(2) << layer->opacity(); | |
| 66 } | |
| 67 | |
| 68 if (layer->transform().HasChange()) { | |
| 69 gfx::Point translation; | |
| 70 float rotation; | |
| 71 gfx::Point3f scale; | |
| 72 if (ui::InterpolatedTransform::FactorTRS(layer->transform(), | |
| 73 &translation, | |
| 74 &rotation, | |
| 75 &scale)) { | |
| 76 if (translation != gfx::Point()) { | |
| 77 buf << L'\n' << UTF8ToWide(content_indent_str); | |
| 78 buf << L"translation: " << translation.x() << L", " << translation.y(); | |
| 79 } | |
| 80 | |
| 81 if (fabs(rotation) > 1e-5) { | |
| 82 buf << L'\n' << UTF8ToWide(content_indent_str); | |
| 83 buf << L"rotation: " << std::setprecision(4) << rotation; | |
| 84 } | |
| 85 | |
| 86 if (scale.AsPoint() != gfx::Point()) { | |
| 87 buf << L'\n' << UTF8ToWide(content_indent_str); | |
| 88 buf << std::setprecision(4); | |
| 89 buf << L"scale: " << scale.x() << L", " << scale.y(); | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 VLOG(1) << buf.str(); | |
| 95 std::cout << buf.str() << std::endl; | |
| 96 | |
| 97 for (size_t i = 0, count = layer->children().size(); i < count; ++i) | |
| 98 PrintLayerHierarchyImp(layer->children()[i], indent + 3, mouse_location); | |
| 99 } | |
| 100 | |
| 101 } // namespace | |
| 102 | |
| 103 void PrintLayerHierarchy(const Layer* layer, gfx::Point mouse_location) { | |
| 104 PrintLayerHierarchyImp(layer, 0, mouse_location); | |
| 105 } | |
| 106 | |
| 107 } // namespace ui | |
| 108 | |
| 109 #endif // NDEBUG | |
| OLD | NEW |