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()15scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { 16 return base::WrapRefCounted(new NinePatchLayer()); 17 } 18 NinePatchLayer()19NinePatchLayer::NinePatchLayer() 20 : UIResourceLayer(), fill_center_(false), nearest_neighbor_(false) {} 21 22 NinePatchLayer::~NinePatchLayer() = default; 23 CreateLayerImpl(LayerTreeImpl * tree_impl)24std::unique_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( 25 LayerTreeImpl* tree_impl) { 26 return NinePatchLayerImpl::Create(tree_impl, id()); 27 } 28 SetBorder(const gfx::Rect & border)29void NinePatchLayer::SetBorder(const gfx::Rect& border) { 30 if (border == border_) 31 return; 32 border_ = border; 33 SetNeedsCommit(); 34 } 35 SetAperture(const gfx::Rect & aperture)36void 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)44void 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)52void 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)60void 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)68void 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