nine_patch_layer.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.h"
  5. #include "base/trace_event/trace_event.h"
  6. #include "cc/layers/nine_patch_layer_impl.h"
  7. #include "cc/resources/scoped_ui_resource.h"
  8. #include "cc/resources/ui_resource_bitmap.h"
  9. #include "cc/trees/layer_tree_host.h"
  10. namespace cc {
  11. scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
  12. return base::WrapRefCounted(new NinePatchLayer());
  13. }
  14. NinePatchLayer::NinePatchLayer()
  15. : UIResourceLayer(), fill_center_(false), nearest_neighbor_(false) {}
  16. NinePatchLayer::~NinePatchLayer() = default;
  17. std::unique_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl(
  18. LayerTreeImpl* tree_impl) const {
  19. return NinePatchLayerImpl::Create(tree_impl, id());
  20. }
  21. void NinePatchLayer::SetBorder(const gfx::Rect& border) {
  22. if (border == border_.Read(*this))
  23. return;
  24. border_.Write(*this) = border;
  25. SetNeedsCommit();
  26. }
  27. void NinePatchLayer::SetAperture(const gfx::Rect& aperture) {
  28. if (image_aperture_.Read(*this) == aperture)
  29. return;
  30. image_aperture_.Write(*this) = aperture;
  31. SetNeedsCommit();
  32. }
  33. void NinePatchLayer::SetFillCenter(bool fill_center) {
  34. if (fill_center_.Read(*this) == fill_center)
  35. return;
  36. fill_center_.Write(*this) = fill_center;
  37. SetNeedsCommit();
  38. }
  39. void NinePatchLayer::SetNearestNeighbor(bool nearest_neighbor) {
  40. if (nearest_neighbor_.Read(*this) == nearest_neighbor)
  41. return;
  42. nearest_neighbor_.Write(*this) = nearest_neighbor;
  43. SetNeedsCommit();
  44. }
  45. void NinePatchLayer::SetLayerOcclusion(const gfx::Rect& occlusion) {
  46. if (layer_occlusion_.Read(*this) == occlusion)
  47. return;
  48. layer_occlusion_.Write(*this) = occlusion;
  49. SetNeedsCommit();
  50. }
  51. void NinePatchLayer::PushPropertiesTo(
  52. LayerImpl* layer,
  53. const CommitState& commit_state,
  54. const ThreadUnsafeCommitState& unsafe_state) {
  55. UIResourceLayer::PushPropertiesTo(layer, commit_state, unsafe_state);
  56. TRACE_EVENT0("cc", "NinePatchLayer::PushPropertiesTo");
  57. NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
  58. if (resource_id()) {
  59. DCHECK(IsAttached());
  60. layer_impl->SetLayout(image_aperture_.Read(*this), border_.Read(*this),
  61. layer_occlusion_.Read(*this),
  62. fill_center_.Read(*this),
  63. nearest_neighbor_.Read(*this));
  64. }
  65. }
  66. } // namespace cc