| 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/nine_patch_layer.h" | 5 #include "cc/nine_patch_layer.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host.h" | 7 #include "cc/layer_tree_host.h" |
| 8 #include "cc/nine_patch_layer_impl.h" | 8 #include "cc/nine_patch_layer_impl.h" |
| 9 #include "cc/prioritized_resource.h" | 9 #include "cc/prioritized_resource.h" |
| 10 #include "cc/resource_update.h" | 10 #include "cc/resource_update.h" |
| 11 #include "cc/resource_update_queue.h" | 11 #include "cc/resource_update_queue.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { | 15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { |
| 16 return make_scoped_refptr(new NinePatchLayer()); | 16 return make_scoped_refptr(new NinePatchLayer()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 NinePatchLayer::NinePatchLayer() | 19 NinePatchLayer::NinePatchLayer() |
| 20 : bitmap_dirty_(false) {} | 20 : bitmap_dirty_(false) {} |
| 21 | 21 |
| 22 NinePatchLayer::~NinePatchLayer() {} | 22 NinePatchLayer::~NinePatchLayer() {} |
| 23 | 23 |
| 24 scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl( | 24 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( |
| 25 LayerTreeImpl* tree_impl) { | 25 LayerTreeImpl* tree_impl) { |
| 26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void NinePatchLayer::setTexturePriorities( | 29 void NinePatchLayer::SetTexturePriorities( |
| 30 const PriorityCalculator& priority_calc) { | 30 const PriorityCalculator& priority_calc) { |
| 31 if (resource_ && !resource_->texture()->resourceManager()) { | 31 if (resource_ && !resource_->texture()->resourceManager()) { |
| 32 // Release the resource here, as it is no longer tied to a resource manager. | 32 // Release the resource here, as it is no longer tied to a resource manager. |
| 33 resource_.reset(); | 33 resource_.reset(); |
| 34 if (!bitmap_.isNull()) | 34 if (!bitmap_.isNull()) |
| 35 CreateResource(); | 35 CreateResource(); |
| 36 } else if (m_needsDisplay && bitmap_dirty_ && drawsContent()) { | 36 } else if (needs_display_ && bitmap_dirty_ && DrawsContent()) { |
| 37 CreateResource(); | 37 CreateResource(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 if (resource_) { | 40 if (resource_) { |
| 41 resource_->texture()->setRequestPriority( | 41 resource_->texture()->setRequestPriority( |
| 42 PriorityCalculator::uiPriority(true)); | 42 PriorityCalculator::uiPriority(true)); |
| 43 // FIXME: Need to support swizzle in the shader for | 43 // FIXME: Need to support swizzle in the shader for |
| 44 // !PlatformColor::sameComponentOrder(texture_format) | 44 // !PlatformColor::sameComponentOrder(texture_format) |
| 45 GLenum texture_format = | 45 GLenum texture_format = |
| 46 layerTreeHost()->rendererCapabilities().bestTextureFormat; | 46 layer_tree_host()->rendererCapabilities().bestTextureFormat; |
| 47 resource_->texture()->setDimensions( | 47 resource_->texture()->setDimensions( |
| 48 gfx::Size(bitmap_.width(), bitmap_.height()), texture_format); | 48 gfx::Size(bitmap_.width(), bitmap_.height()), texture_format); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) { | 52 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) { |
| 53 bitmap_ = bitmap; | 53 bitmap_ = bitmap; |
| 54 image_aperture_ = aperture; | 54 image_aperture_ = aperture; |
| 55 bitmap_dirty_ = true; | 55 bitmap_dirty_ = true; |
| 56 setNeedsDisplay(); | 56 SetNeedsDisplay(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void NinePatchLayer::update(ResourceUpdateQueue& queue, | 59 void NinePatchLayer::Update(ResourceUpdateQueue* queue, |
| 60 const OcclusionTracker* occlusion, | 60 const OcclusionTracker* occlusion, |
| 61 RenderingStats* stats) { | 61 RenderingStats* stats) { |
| 62 CreateUpdaterIfNeeded(); | 62 CreateUpdaterIfNeeded(); |
| 63 | 63 |
| 64 if (resource_ && (bitmap_dirty_ || resource_->texture()->resourceId() == 0)) { | 64 if (resource_ && (bitmap_dirty_ || resource_->texture()->resourceId() == 0)) { |
| 65 gfx::Rect contentRect(gfx::Point(), | 65 gfx::Rect contentRect(gfx::Point(), |
| 66 gfx::Size(bitmap_.width(), bitmap_.height())); | 66 gfx::Size(bitmap_.width(), bitmap_.height())); |
| 67 ResourceUpdate upload = ResourceUpdate::Create(resource_->texture(), | 67 ResourceUpdate upload = ResourceUpdate::Create(resource_->texture(), |
| 68 &bitmap_, | 68 &bitmap_, |
| 69 contentRect, | 69 contentRect, |
| 70 contentRect, | 70 contentRect, |
| 71 gfx::Vector2d()); | 71 gfx::Vector2d()); |
| 72 queue.appendFullUpload(upload); | 72 queue->appendFullUpload(upload); |
| 73 bitmap_dirty_ = false; | 73 bitmap_dirty_ = false; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void NinePatchLayer::CreateUpdaterIfNeeded() { | 77 void NinePatchLayer::CreateUpdaterIfNeeded() { |
| 78 if (updater_) | 78 if (updater_) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 updater_ = ImageLayerUpdater::create(); | 81 updater_ = ImageLayerUpdater::create(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void NinePatchLayer::CreateResource() { | 84 void NinePatchLayer::CreateResource() { |
| 85 DCHECK(!bitmap_.isNull()); | 85 DCHECK(!bitmap_.isNull()); |
| 86 CreateUpdaterIfNeeded(); | 86 CreateUpdaterIfNeeded(); |
| 87 updater_->setBitmap(bitmap_); | 87 updater_->setBitmap(bitmap_); |
| 88 m_needsDisplay = false; | 88 needs_display_ = false; |
| 89 | 89 |
| 90 if (!resource_) { | 90 if (!resource_) { |
| 91 resource_ = updater_->createResource( | 91 resource_ = updater_->createResource( |
| 92 layerTreeHost()->contentsTextureManager()); | 92 layer_tree_host()->contentsTextureManager()); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool NinePatchLayer::drawsContent() const { | 96 bool NinePatchLayer::DrawsContent() const { |
| 97 bool draws = !bitmap_.isNull() && | 97 bool draws = !bitmap_.isNull() && |
| 98 Layer::drawsContent() && | 98 Layer::DrawsContent() && |
| 99 bitmap_.width() && | 99 bitmap_.width() && |
| 100 bitmap_.height(); | 100 bitmap_.height(); |
| 101 return draws; | 101 return draws; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void NinePatchLayer::pushPropertiesTo(LayerImpl* layer) { | 104 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { |
| 105 Layer::pushPropertiesTo(layer); | 105 Layer::PushPropertiesTo(layer); |
| 106 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); | 106 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); |
| 107 | 107 |
| 108 if (resource_) { | 108 if (resource_) { |
| 109 DCHECK(!bitmap_.isNull()); | 109 DCHECK(!bitmap_.isNull()); |
| 110 layer_impl->SetResourceId(resource_->texture()->resourceId()); | 110 layer_impl->SetResourceId(resource_->texture()->resourceId()); |
| 111 layer_impl->SetLayout( | 111 layer_impl->SetLayout( |
| 112 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_); | 112 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 } | 116 } |
| OLD | NEW |