debug_utils.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "ui/compositor/debug_utils.h"
  5. #include <stddef.h>
  6. #include <iomanip>
  7. #include <ostream>
  8. #include <string>
  9. #include "base/logging.h"
  10. #include "base/numerics/math_constants.h"
  11. #include "cc/trees/layer_tree_host.h"
  12. #include "ui/compositor/layer.h"
  13. #include "ui/gfx/geometry/point.h"
  14. #include "ui/gfx/geometry/point_conversions.h"
  15. #include "ui/gfx/geometry/transform.h"
  16. #include "ui/gfx/interpolated_transform.h"
  17. namespace ui {
  18. namespace {
  19. void PrintLayerHierarchyImp(const Layer* layer,
  20. int indent,
  21. gfx::Point mouse_location,
  22. std::ostringstream* out) {
  23. std::string indent_str(indent, ' ');
  24. layer->transform().TransformPointReverse(&mouse_location);
  25. bool mouse_inside_layer_bounds = layer->bounds().Contains(mouse_location);
  26. mouse_location.Offset(-layer->bounds().x(), -layer->bounds().y());
  27. *out << indent_str;
  28. if (mouse_inside_layer_bounds)
  29. *out << '*';
  30. else
  31. *out << ' ';
  32. *out << layer->name() << ' ' << layer;
  33. switch (layer->type()) {
  34. case ui::LAYER_NOT_DRAWN:
  35. *out << " not_drawn";
  36. break;
  37. case ui::LAYER_TEXTURED:
  38. *out << " textured";
  39. if (layer->fills_bounds_opaquely())
  40. *out << " opaque";
  41. break;
  42. case ui::LAYER_SOLID_COLOR:
  43. *out << " solid";
  44. break;
  45. case ui::LAYER_NINE_PATCH:
  46. *out << " nine_patch";
  47. break;
  48. }
  49. if (!layer->visible())
  50. *out << " !visible";
  51. std::string property_indent_str(indent+3, ' ');
  52. *out << '\n' << property_indent_str;
  53. *out << "bounds: " << layer->bounds().x() << ',' << layer->bounds().y();
  54. *out << ' ' << layer->bounds().width() << 'x' << layer->bounds().height();
  55. if (!layer->GetSubpixelOffset().IsZero())
  56. *out << " " << layer->GetSubpixelOffset().ToString();
  57. const cc::Layer* cc_layer = layer->cc_layer_for_testing();
  58. if (cc_layer) {
  59. // Property trees must be updated in order to get valid render surface
  60. // reasons.
  61. if (cc_layer->layer_tree_host() &&
  62. !cc_layer->layer_tree_host()->property_trees()->needs_rebuild()) {
  63. cc::RenderSurfaceReason render_surface =
  64. cc_layer->GetRenderSurfaceReason();
  65. if (render_surface != cc::RenderSurfaceReason::kNone) {
  66. *out << " render-surface-reason: "
  67. << cc::RenderSurfaceReasonToString(render_surface);
  68. }
  69. }
  70. }
  71. const ui::Layer* mask = const_cast<ui::Layer*>(layer)->layer_mask_layer();
  72. if (mask) {
  73. *out << '\n' << property_indent_str;
  74. *out << "mask layer: " << std::setprecision(2) << mask->bounds().ToString()
  75. << mask->GetSubpixelOffset().ToString();
  76. }
  77. if (layer->opacity() != 1.0f) {
  78. *out << '\n' << property_indent_str;
  79. *out << "opacity: " << std::setprecision(2) << layer->opacity();
  80. }
  81. gfx::DecomposedTransform decomp;
  82. if (!layer->transform().IsIdentity() &&
  83. gfx::DecomposeTransform(&decomp, layer->transform())) {
  84. *out << '\n' << property_indent_str;
  85. *out << "translation: " << std::fixed << decomp.translate[0];
  86. *out << ", " << decomp.translate[1];
  87. *out << '\n' << property_indent_str;
  88. *out << "rotation: ";
  89. *out << std::acos(decomp.quaternion.w()) * 360.0 / base::kPiDouble;
  90. *out << '\n' << property_indent_str;
  91. *out << "scale: " << decomp.scale[0];
  92. *out << ", " << decomp.scale[1];
  93. }
  94. *out << '\n';
  95. for (size_t i = 0, count = layer->children().size(); i < count; ++i) {
  96. PrintLayerHierarchyImp(
  97. layer->children()[i], indent + 3, mouse_location, out);
  98. }
  99. }
  100. } // namespace
  101. void PrintLayerHierarchy(const Layer* layer, const gfx::Point& mouse_location) {
  102. std::ostringstream out;
  103. PrintLayerHierarchy(layer, mouse_location, &out);
  104. // Error so logs can be collected from end-users.
  105. LOG(ERROR) << out.str();
  106. }
  107. void PrintLayerHierarchy(const Layer* layer,
  108. const gfx::Point& mouse_location,
  109. std::ostringstream* out) {
  110. *out << "Layer hierarchy:\n";
  111. PrintLayerHierarchyImp(layer, 0, mouse_location, out);
  112. }
  113. } // namespace ui