Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2919)

Unified Diff: cc/layers/nine_patch_layer.cc

Issue 22870016: Update the nine patch layer to use UI resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor format change and changed initial value for fill_center_ in nine patch layer Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/layers/nine_patch_layer.cc
diff --git a/cc/layers/nine_patch_layer.cc b/cc/layers/nine_patch_layer.cc
index e32f6e0b125230633449e3141994ee2c81d82bed..7d6ffcd0cfabc57c8f61c5aaf1d859646ecf2a10 100644
--- a/cc/layers/nine_patch_layer.cc
+++ b/cc/layers/nine_patch_layer.cc
@@ -8,6 +8,9 @@
#include "cc/resources/prioritized_resource.h"
#include "cc/resources/resource_update.h"
#include "cc/resources/resource_update_queue.h"
+#include "cc/resources/scoped_ui_resource.h"
+#include "cc/resources/shared_ui_resource.h"
+#include "cc/resources/ui_resource_bitmap.h"
#include "cc/trees/layer_tree_host.h"
namespace cc {
@@ -17,7 +20,7 @@ scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
}
NinePatchLayer::NinePatchLayer()
- : bitmap_dirty_(false) {}
+ : fill_center_(true) {}
NinePatchLayer::~NinePatchLayer() {}
@@ -26,91 +29,64 @@ scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl(
return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-void NinePatchLayer::SetTexturePriorities(
- const PriorityCalculator& priority_calc) {
- if (resource_ && !resource_->texture()->resource_manager()) {
- // Release the resource here, as it is no longer tied to a resource manager.
+void NinePatchLayer::SetLayerTreeHost(LayerTreeHost* host) {
+ // When the LTH is set to null or has changed, then this layer should remove
+ // all of its associated resources.
+ if (!host || host != layer_tree_host())
resource_.reset();
- if (!bitmap_.isNull())
- CreateResource();
- } else if (bitmap_dirty_ && DrawsContent()) {
- CreateResource();
- }
-
- if (resource_) {
- resource_->texture()->set_request_priority(
- PriorityCalculator::UIPriority(true));
- GLenum texture_format =
- layer_tree_host()->GetRendererCapabilities().best_texture_format;
- resource_->texture()->SetDimensions(
- gfx::Size(bitmap_.width(), bitmap_.height()), texture_format);
- }
-}
-void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) {
- bitmap_ = bitmap;
- image_aperture_ = aperture;
- bitmap_dirty_ = true;
- SetNeedsDisplay();
+ Layer::SetLayerTreeHost(host);
}
-bool NinePatchLayer::Update(ResourceUpdateQueue* queue,
- const OcclusionTracker* occlusion) {
- bool updated = Layer::Update(queue, occlusion);
-
- CreateUpdaterIfNeeded();
-
- if (resource_ &&
- (bitmap_dirty_ || resource_->texture()->resource_id() == 0)) {
- gfx::Rect content_rect(0, 0, bitmap_.width(), bitmap_.height());
- ResourceUpdate upload = ResourceUpdate::Create(resource_->texture(),
- &bitmap_,
- content_rect,
- content_rect,
- gfx::Vector2d());
- queue->AppendFullUpload(upload);
- bitmap_dirty_ = false;
- updated = true;
- }
- return updated;
+void NinePatchLayer::SetBorder(gfx::Rect border) {
+ if (border == border_)
+ return;
+ border_ = border;
+ SetNeedsCommit();
}
-void NinePatchLayer::CreateUpdaterIfNeeded() {
- if (updater_.get())
+void NinePatchLayer::SetBitmap(const SkBitmap& skbitmap, gfx::Rect aperture) {
+ if (!layer_tree_host())
return;
+ image_aperture_ = aperture;
+ fill_center_ = false;
- updater_ = ImageLayerUpdater::Create();
+ resource_ = ScopedUIResource::Create(
+ layer_tree_host(),
+ CreateUIResourceBitmapFromSkBitmap(skbitmap));
+
+ SetNeedsCommit();
}
-void NinePatchLayer::CreateResource() {
- DCHECK(!bitmap_.isNull());
- CreateUpdaterIfNeeded();
- updater_->SetBitmap(bitmap_);
+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.
+ gfx::Rect aperture,
+ bool fill_center,
+ gfx::Size size) {
+ image_aperture_ = aperture;
+ fill_center_ = fill_center;
- if (!resource_) {
- resource_ = updater_->CreateResource(
- layer_tree_host()->contents_texture_manager());
- }
+ if (resource_id)
+ resource_ = SharedUIResource::Create(resource_id, size);
+
+ SetNeedsCommit();
}
bool NinePatchLayer::DrawsContent() const {
- bool draws = !bitmap_.isNull() &&
- Layer::DrawsContent() &&
- bitmap_.width() &&
- bitmap_.height();
- return draws;
+ 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!
}
void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) {
Layer::PushPropertiesTo(layer);
NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
-
- if (resource_) {
- DCHECK(!bitmap_.isNull());
- layer_impl->SetResourceId(resource_->texture()->resource_id());
- layer_impl->SetLayout(
- gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_);
+ if (!resource_) {
+ layer_impl->set_ui_resource_id(0);
+ return;
}
+ layer_impl->set_ui_resource_id(resource_->id());
+ layer_impl->SetLayout(resource_->GetSize(),
+ image_aperture_,
+ border_,
+ fill_center_);
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698