Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/nine_patch_layer.h" | 5 #include "cc/layers/nine_patch_layer.h" |
| 6 | 6 |
| 7 #include "cc/layers/nine_patch_layer_impl.h" | 7 #include "cc/layers/nine_patch_layer_impl.h" |
| 8 #include "cc/resources/prioritized_resource.h" | 8 #include "cc/resources/prioritized_resource.h" |
| 9 #include "cc/resources/resource_update.h" | 9 #include "cc/resources/resource_update.h" |
| 10 #include "cc/resources/resource_update_queue.h" | 10 #include "cc/resources/resource_update_queue.h" |
| 11 #include "cc/resources/scoped_ui_resource.h" | |
| 12 #include "cc/resources/shared_ui_resource.h" | |
| 13 #include "cc/resources/ui_resource_bitmap.h" | |
| 11 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
| 12 | 15 |
| 13 namespace cc { | 16 namespace cc { |
| 14 | 17 |
| 15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { | 18 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { |
| 16 return make_scoped_refptr(new NinePatchLayer()); | 19 return make_scoped_refptr(new NinePatchLayer()); |
| 17 } | 20 } |
| 18 | 21 |
| 19 NinePatchLayer::NinePatchLayer() | 22 NinePatchLayer::NinePatchLayer() |
| 20 : bitmap_dirty_(false) {} | 23 : fill_center_(true) {} |
| 21 | 24 |
| 22 NinePatchLayer::~NinePatchLayer() {} | 25 NinePatchLayer::~NinePatchLayer() {} |
| 23 | 26 |
| 24 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( | 27 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( |
| 25 LayerTreeImpl* tree_impl) { | 28 LayerTreeImpl* tree_impl) { |
| 26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 29 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void NinePatchLayer::SetTexturePriorities( | 32 void NinePatchLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 30 const PriorityCalculator& priority_calc) { | 33 // When the LTH is set to null or has changed, then this layer should remove |
| 31 if (resource_ && !resource_->texture()->resource_manager()) { | 34 // all of its associated resources. |
| 32 // Release the resource here, as it is no longer tied to a resource manager. | 35 if (!host || host != layer_tree_host()) |
| 33 resource_.reset(); | 36 resource_.reset(); |
| 34 if (!bitmap_.isNull()) | |
| 35 CreateResource(); | |
| 36 } else if (bitmap_dirty_ && DrawsContent()) { | |
| 37 CreateResource(); | |
| 38 } | |
| 39 | 37 |
| 40 if (resource_) { | 38 Layer::SetLayerTreeHost(host); |
| 41 resource_->texture()->set_request_priority( | |
| 42 PriorityCalculator::UIPriority(true)); | |
| 43 GLenum texture_format = | |
| 44 layer_tree_host()->GetRendererCapabilities().best_texture_format; | |
| 45 resource_->texture()->SetDimensions( | |
| 46 gfx::Size(bitmap_.width(), bitmap_.height()), texture_format); | |
| 47 } | |
| 48 } | 39 } |
| 49 | 40 |
| 50 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) { | 41 void NinePatchLayer::SetBorder(gfx::Rect border) { |
| 51 bitmap_ = bitmap; | 42 if (border == border_) |
| 52 image_aperture_ = aperture; | 43 return; |
| 53 bitmap_dirty_ = true; | 44 border_ = border; |
| 54 SetNeedsDisplay(); | 45 SetNeedsCommit(); |
| 55 } | 46 } |
| 56 | 47 |
| 57 bool NinePatchLayer::Update(ResourceUpdateQueue* queue, | 48 void NinePatchLayer::SetBitmap(const SkBitmap& skbitmap, gfx::Rect aperture) { |
| 58 const OcclusionTracker* occlusion) { | 49 if (!layer_tree_host()) |
| 59 bool updated = Layer::Update(queue, occlusion); | 50 return; |
| 51 image_aperture_ = aperture; | |
| 52 fill_center_ = false; | |
| 60 | 53 |
| 61 CreateUpdaterIfNeeded(); | 54 resource_ = ScopedUIResource::Create( |
| 55 layer_tree_host(), | |
| 56 CreateUIResourceBitmapFromSkBitmap(skbitmap)); | |
| 62 | 57 |
| 63 if (resource_ && | 58 SetNeedsCommit(); |
| 64 (bitmap_dirty_ || resource_->texture()->resource_id() == 0)) { | |
| 65 gfx::Rect content_rect(0, 0, bitmap_.width(), bitmap_.height()); | |
| 66 ResourceUpdate upload = ResourceUpdate::Create(resource_->texture(), | |
| 67 &bitmap_, | |
| 68 content_rect, | |
| 69 content_rect, | |
| 70 gfx::Vector2d()); | |
| 71 queue->AppendFullUpload(upload); | |
| 72 bitmap_dirty_ = false; | |
| 73 updated = true; | |
| 74 } | |
| 75 return updated; | |
| 76 } | 59 } |
| 77 | 60 |
| 78 void NinePatchLayer::CreateUpdaterIfNeeded() { | 61 void NinePatchLayer::SetBitmap(UIResourceId resource_id, |
|
danakj
2013/08/20 20:03:53
Please don't use function overloading for this, us
powei
2013/08/22 17:58:47
Done.
| |
| 79 if (updater_.get()) | 62 gfx::Rect aperture, |
| 80 return; | 63 bool fill_center, |
| 64 gfx::Size size) { | |
| 65 image_aperture_ = aperture; | |
| 66 fill_center_ = fill_center; | |
| 81 | 67 |
| 82 updater_ = ImageLayerUpdater::Create(); | 68 if (resource_id) |
| 83 } | 69 resource_ = SharedUIResource::Create(resource_id, size); |
| 84 | 70 |
| 85 void NinePatchLayer::CreateResource() { | 71 SetNeedsCommit(); |
| 86 DCHECK(!bitmap_.isNull()); | |
| 87 CreateUpdaterIfNeeded(); | |
| 88 updater_->SetBitmap(bitmap_); | |
| 89 | |
| 90 if (!resource_) { | |
| 91 resource_ = updater_->CreateResource( | |
| 92 layer_tree_host()->contents_texture_manager()); | |
| 93 } | |
| 94 } | 72 } |
| 95 | 73 |
| 96 bool NinePatchLayer::DrawsContent() const { | 74 bool NinePatchLayer::DrawsContent() const { |
| 97 bool draws = !bitmap_.isNull() && | 75 return resource_.get() && resource_->id(); |
|
danakj
2013/08/20 20:03:53
&& Layer::DrawsContent()
Should/can we check the
powei
2013/08/22 17:58:47
Done (on && Layer::DrawsContent()). I put in some
danakj
2013/08/22 18:06:11
Ok, but when DrawsContent() is false we can early
powei
2013/08/23 01:37:15
I guess my assumption here is that either there is
danakj
2013/08/27 15:42:48
Ah okay, that makes sense, thanks!
| |
| 98 Layer::DrawsContent() && | |
| 99 bitmap_.width() && | |
| 100 bitmap_.height(); | |
| 101 return draws; | |
| 102 } | 76 } |
| 103 | 77 |
| 104 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { | 78 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { |
| 105 Layer::PushPropertiesTo(layer); | 79 Layer::PushPropertiesTo(layer); |
| 106 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); | 80 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); |
| 107 | 81 if (!resource_) { |
| 108 if (resource_) { | 82 layer_impl->set_ui_resource_id(0); |
| 109 DCHECK(!bitmap_.isNull()); | 83 return; |
| 110 layer_impl->SetResourceId(resource_->texture()->resource_id()); | |
| 111 layer_impl->SetLayout( | |
| 112 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_); | |
| 113 } | 84 } |
| 85 layer_impl->set_ui_resource_id(resource_->id()); | |
| 86 layer_impl->SetLayout(resource_->GetSize(), | |
| 87 image_aperture_, | |
| 88 border_, | |
| 89 fill_center_); | |
| 114 } | 90 } |
| 115 | 91 |
| 116 } // namespace cc | 92 } // namespace cc |
| OLD | NEW |