element_utility.cc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2019 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 "components/ui_devtools/views/element_utility.h"
  5. #include "base/strings/string_number_conversions.h"
  6. #include "base/strings/stringprintf.h"
  7. #include "cc/trees/layer_tree_host.h"
  8. #include "third_party/skia/include/core/SkColor.h"
  9. #include "ui/compositor/layer.h"
  10. #include "ui/compositor/layer_owner.h"
  11. namespace ui_devtools {
  12. void AppendLayerPropertiesMatchedStyle(
  13. const ui::Layer* layer,
  14. std::vector<UIElement::UIProperty>* ret) {
  15. ret->emplace_back("layer-type",
  16. std::string(LayerTypeToString(layer->type())));
  17. ret->emplace_back("has-layer-mask",
  18. layer->layer_mask_layer() ? "true" : "false");
  19. ret->emplace_back("layer-is-drawn", layer->IsDrawn() ? "true" : "false");
  20. ret->emplace_back("layer-opacity", base::NumberToString((layer->opacity())));
  21. ret->emplace_back("layer-combined-opacity",
  22. base::NumberToString(layer->GetCombinedOpacity()));
  23. ret->emplace_back("background-blur",
  24. base::NumberToString(layer->background_blur()));
  25. ret->emplace_back("layer-blur", base::NumberToString(layer->layer_blur()));
  26. ret->emplace_back("layer-saturation",
  27. base::NumberToString(layer->layer_saturation()));
  28. ret->emplace_back("layer-brightness",
  29. base::NumberToString(layer->layer_brightness()));
  30. ret->emplace_back("layer-grayscale",
  31. base::NumberToString(layer->layer_grayscale()));
  32. ret->emplace_back("layer-fills-bounds-opaquely",
  33. layer->fills_bounds_opaquely() ? "true" : "false");
  34. if (layer->type() == ui::LAYER_SOLID_COLOR) {
  35. ret->emplace_back("layer-color",
  36. base::StringPrintf("%X", layer->GetTargetColor()));
  37. }
  38. const auto offset = layer->GetSubpixelOffset();
  39. if (!offset.IsZero())
  40. ret->emplace_back("layer-subpixel-offset", offset.ToString());
  41. const auto& rounded_corners = layer->rounded_corner_radii();
  42. if (!rounded_corners.IsEmpty())
  43. ret->emplace_back("layer-rounded-corners", rounded_corners.ToString());
  44. const ui::Layer::ShapeRects* alpha_shape_bounds = layer->alpha_shape();
  45. if (alpha_shape_bounds && alpha_shape_bounds->size()) {
  46. gfx::Rect bounding_box;
  47. for (auto& shape_bound : *alpha_shape_bounds)
  48. bounding_box.Union(shape_bound);
  49. ret->emplace_back("alpha-shape-bounding-box", bounding_box.ToString());
  50. }
  51. const cc::Layer* cc_layer = layer->cc_layer_for_testing();
  52. if (cc_layer) {
  53. // Property trees must be updated in order to get valid render surface
  54. // reasons.
  55. if (!cc_layer->layer_tree_host() ||
  56. cc_layer->layer_tree_host()->property_trees()->needs_rebuild())
  57. return;
  58. cc::RenderSurfaceReason render_surface = cc_layer->GetRenderSurfaceReason();
  59. if (render_surface != cc::RenderSurfaceReason::kNone) {
  60. ret->emplace_back("render-surface-reason",
  61. cc::RenderSurfaceReasonToString(render_surface));
  62. }
  63. }
  64. }
  65. } // namespace ui_devtools