nine_patch_layer_impl.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 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 "cc/layers/nine_patch_layer_impl.h"
  5. #include <memory>
  6. #include <vector>
  7. #include "base/trace_event/traced_value.h"
  8. #include "cc/base/math_util.h"
  9. #include "cc/trees/layer_tree_impl.h"
  10. #include "cc/trees/occlusion.h"
  11. #include "components/viz/common/quads/texture_draw_quad.h"
  12. #include "ui/gfx/geometry/rect_conversions.h"
  13. #include "ui/gfx/geometry/rect_f.h"
  14. namespace cc {
  15. NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id)
  16. : UIResourceLayerImpl(tree_impl, id) {}
  17. NinePatchLayerImpl::~NinePatchLayerImpl() = default;
  18. std::unique_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl(
  19. LayerTreeImpl* tree_impl) const {
  20. return NinePatchLayerImpl::Create(tree_impl, id());
  21. }
  22. void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) {
  23. UIResourceLayerImpl::PushPropertiesTo(layer);
  24. NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
  25. layer_impl->quad_generator_ = this->quad_generator_;
  26. }
  27. void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture,
  28. const gfx::Rect& border,
  29. const gfx::Rect& layer_occlusion,
  30. bool fill_center,
  31. bool nearest_neighbor) {
  32. // This check imposes an ordering on the call sequence. An UIResource must
  33. // exist before SetLayout can be called.
  34. DCHECK(ui_resource_id_);
  35. if (!quad_generator_.SetLayout(image_bounds_, bounds(), aperture, border,
  36. layer_occlusion, fill_center,
  37. nearest_neighbor))
  38. return;
  39. NoteLayerPropertyChanged();
  40. }
  41. void NinePatchLayerImpl::AppendQuads(viz::CompositorRenderPass* render_pass,
  42. AppendQuadsData* append_quads_data) {
  43. DCHECK(!bounds().IsEmpty());
  44. quad_generator_.CheckGeometryLimitations();
  45. viz::SharedQuadState* shared_quad_state =
  46. render_pass->CreateAndAppendSharedQuadState();
  47. bool is_resource =
  48. ui_resource_id_ &&
  49. layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
  50. bool are_contents_opaque =
  51. is_resource ? layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) ||
  52. contents_opaque()
  53. : false;
  54. PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
  55. AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
  56. append_quads_data);
  57. if (!is_resource)
  58. return;
  59. std::vector<NinePatchGenerator::Patch> patches =
  60. quad_generator_.GeneratePatches();
  61. for (auto& patch : patches)
  62. patch.output_rect =
  63. gfx::RectF(gfx::ToFlooredRectDeprecated(patch.output_rect));
  64. quad_generator_.AppendQuads(this, ui_resource_id_, render_pass,
  65. shared_quad_state, patches);
  66. }
  67. const char* NinePatchLayerImpl::LayerTypeAsString() const {
  68. return "cc::NinePatchLayerImpl";
  69. }
  70. void NinePatchLayerImpl::AsValueInto(
  71. base::trace_event::TracedValue* state) const {
  72. LayerImpl::AsValueInto(state);
  73. quad_generator_.AsValueInto(state);
  74. }
  75. } // namespace cc