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/ui_resource_bitmap.h" | |
| 11 #include "cc/trees/layer_tree_host.h" | 13 #include "cc/trees/layer_tree_host.h" |
| 12 | 14 |
| 13 namespace cc { | 15 namespace cc { |
| 14 | 16 |
| 17 scoped_ptr<NinePatchLayer::ScopedResource> | |
| 18 NinePatchLayer::ScopedResource::Create(LayerTreeHost* host, | |
| 19 const SkBitmap& skbitmap) { | |
| 20 return make_scoped_ptr(new NinePatchLayer::ScopedResource(host, skbitmap)); | |
| 21 } | |
| 22 | |
| 23 UIResourceId NinePatchLayer::ScopedResource::id() { return resource_->id(); } | |
| 24 | |
| 25 NinePatchLayer::ScopedResource::ScopedResource(LayerTreeHost* host, | |
| 26 const SkBitmap& skbitmap) { | |
| 27 resource_ = ScopedUIResource::Create( | |
| 28 host, UIResourceBitmap::CreateFromSkBitmap(skbitmap)); | |
| 29 } | |
| 30 | |
| 31 scoped_ptr<NinePatchLayer::SharedResource> | |
| 32 NinePatchLayer::SharedResource::Create(UIResourceId id) { | |
| 33 return make_scoped_ptr(new NinePatchLayer::SharedResource(id)); | |
| 34 } | |
| 35 | |
| 36 UIResourceId NinePatchLayer::SharedResource::id() { return id_; } | |
| 37 | |
| 38 NinePatchLayer::SharedResource::SharedResource(UIResourceId id) : id_(id) {} | |
| 39 | |
| 15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { | 40 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { |
| 16 return make_scoped_refptr(new NinePatchLayer()); | 41 return make_scoped_refptr(new NinePatchLayer()); |
| 17 } | 42 } |
| 18 | 43 |
| 19 NinePatchLayer::NinePatchLayer() | 44 NinePatchLayer::NinePatchLayer() : fill_center_(true) {} |
| 20 : bitmap_dirty_(false) {} | |
| 21 | 45 |
| 22 NinePatchLayer::~NinePatchLayer() {} | 46 NinePatchLayer::~NinePatchLayer() {} |
| 23 | 47 |
| 24 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( | 48 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( |
| 25 LayerTreeImpl* tree_impl) { | 49 LayerTreeImpl* tree_impl) { |
| 26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 50 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 27 } | 51 } |
| 28 | 52 |
| 29 void NinePatchLayer::SetTexturePriorities( | 53 void NinePatchLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 30 const PriorityCalculator& priority_calc) { | 54 // When the LTH is set to null or has changed, then this layer should remove |
| 31 if (resource_ && !resource_->texture()->resource_manager()) { | 55 // all of its associated resources. |
| 32 // Release the resource here, as it is no longer tied to a resource manager. | 56 if (!host || host != layer_tree_host()) |
| 33 resource_.reset(); | 57 resource_.reset(); |
| 34 if (!bitmap_.isNull()) | |
| 35 CreateResource(); | |
| 36 } else if (bitmap_dirty_ && DrawsContent()) { | |
| 37 CreateResource(); | |
| 38 } | |
| 39 | 58 |
| 40 if (resource_) { | 59 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 } | 60 } |
| 49 | 61 |
| 50 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) { | 62 void NinePatchLayer::SetBorder(gfx::Rect border) { |
| 51 bitmap_ = bitmap; | 63 if (border == border_) |
| 52 image_aperture_ = aperture; | 64 return; |
| 53 bitmap_dirty_ = true; | 65 border_ = border; |
| 54 SetNeedsDisplay(); | 66 SetNeedsCommit(); |
| 55 } | 67 } |
| 56 | 68 |
| 57 bool NinePatchLayer::Update(ResourceUpdateQueue* queue, | 69 void NinePatchLayer::SetBitmap(const SkBitmap& skbitmap, gfx::Rect aperture) { |
| 58 const OcclusionTracker* occlusion) { | 70 if (!layer_tree_host()) |
| 59 bool updated = Layer::Update(queue, occlusion); | 71 return; |
| 72 image_aperture_ = aperture; | |
| 73 fill_center_ = false; | |
| 74 resource_ = ScopedResource::Create(layer_tree_host(), skbitmap); | |
| 60 | 75 |
| 61 CreateUpdaterIfNeeded(); | 76 SetNeedsCommit(); |
| 62 | |
| 63 if (resource_ && | |
| 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 | |
| 76 return updated; | |
| 77 } | 77 } |
| 78 | 78 |
| 79 void NinePatchLayer::CreateUpdaterIfNeeded() { | 79 void NinePatchLayer::SetSharedBitmap(UIResourceId resource_id, |
| 80 if (updater_.get()) | 80 gfx::Rect aperture, |
| 81 return; | 81 bool fill_center) { |
| 82 image_aperture_ = aperture; | |
|
aelias_OOO_until_Jul13
2013/08/28 22:28:29
Please add an early return if all three of the arg
powei
2013/08/30 05:17:15
Done.
| |
| 83 fill_center_ = fill_center; | |
| 82 | 84 |
| 83 updater_ = ImageLayerUpdater::Create(); | 85 if (resource_id) |
| 84 } | 86 resource_ = SharedResource::Create(resource_id); |
| 85 | 87 |
| 86 void NinePatchLayer::CreateResource() { | 88 SetNeedsCommit(); |
| 87 DCHECK(!bitmap_.isNull()); | |
| 88 CreateUpdaterIfNeeded(); | |
| 89 updater_->SetBitmap(bitmap_); | |
| 90 | |
| 91 if (!resource_) { | |
| 92 resource_ = updater_->CreateResource( | |
| 93 layer_tree_host()->contents_texture_manager()); | |
| 94 } | |
| 95 } | 89 } |
| 96 | 90 |
| 97 bool NinePatchLayer::DrawsContent() const { | 91 bool NinePatchLayer::DrawsContent() const { |
| 98 bool draws = !bitmap_.isNull() && | 92 return resource_&& resource_->id() && Layer::DrawsContent(); |
|
aelias_OOO_until_Jul13
2013/08/28 22:28:29
nit: space between resource_&&
powei
2013/08/30 05:17:15
Done.
| |
| 99 Layer::DrawsContent() && | |
| 100 bitmap_.width() && | |
| 101 bitmap_.height(); | |
| 102 return draws; | |
| 103 } | 93 } |
| 104 | 94 |
| 105 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { | 95 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { |
| 106 Layer::PushPropertiesTo(layer); | 96 Layer::PushPropertiesTo(layer); |
| 107 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); | 97 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); |
| 108 | 98 |
| 109 if (resource_) { | 99 if (!resource_) { |
| 110 DCHECK(!bitmap_.isNull()); | 100 layer_impl->SetUIResourceId(0); |
| 111 layer_impl->SetResourceId(resource_->texture()->resource_id()); | 101 } else { |
| 112 layer_impl->SetLayout( | 102 layer_impl->SetUIResourceId(resource_->id()); |
| 113 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_); | 103 DCHECK(layer_tree_host()); |
| 104 layer_impl->SetLayout(layer_tree_host()->GetUIResourceSize(resource_->id()), | |
| 105 image_aperture_, | |
| 106 border_, | |
| 107 fill_center_); | |
| 114 } | 108 } |
| 115 | 109 |
| 116 // NinePatchLayer must push properties every commit to make sure | 110 // NinePatchLayer must push properties every commit to make sure |
|
aelias_OOO_until_Jul13
2013/08/28 22:28:29
Can you fix this problem as part of this patch?
powei
2013/08/30 05:17:15
Not 100% on this, but I assume needs_push_properti
aelias_OOO_until_Jul13
2013/08/30 06:20:41
Looks good. I think just some ResourceProvider su
| |
| 117 // NinePatchLayerImpl::resource_id_ is valid. | 111 // NinePatchLayerImpl::ui_resource_id_ is valid. |
| 118 // http://crbug.com/276482 | 112 // http://crbug.com/276482 |
| 119 needs_push_properties_ = true; | 113 needs_push_properties_ = true; |
| 120 } | 114 } |
| 121 | 115 |
| 122 } // namespace cc | 116 } // namespace cc |
| OLD | NEW |