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