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

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: Compilation error fixes 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 517b49b68fc50ad69e0da9d722a8ccd59de88bb2..d5ac888b981d9dffe8c32d81f987de31a265f572 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,95 +29,67 @@ 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;
+ resource_ = ScopedUIResource::Create(
+ layer_tree_host(), CreateUIResourceBitmapFromSkBitmap(skbitmap));
- updater_ = ImageLayerUpdater::Create();
+ SetNeedsCommit();
}
-void NinePatchLayer::CreateResource() {
- DCHECK(!bitmap_.isNull());
- CreateUpdaterIfNeeded();
- updater_->SetBitmap(bitmap_);
+void NinePatchLayer::SetSharedBitmap(UIResourceId resource_id,
+ gfx::Rect aperture,
+ bool fill_center) {
+ 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);
+
+ SetNeedsCommit();
}
bool NinePatchLayer::DrawsContent() const {
- bool draws = !bitmap_.isNull() &&
- Layer::DrawsContent() &&
- bitmap_.width() &&
- bitmap_.height();
- return draws;
+ return resource_.get() && resource_->id() && Layer::DrawsContent();
danakj 2013/08/27 15:42:48 nit: no .get() needed for scoped_ptr as bool
powei 2013/08/27 19:04:57 Done.
}
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;
danakj 2013/08/27 15:42:48 You can't early out, since we needs_push_propertie
powei 2013/08/27 19:04:57 Done.
}
+ layer_impl->set_ui_resource_id(resource_->id());
+ DCHECK(layer_tree_host());
+ layer_impl->SetLayout(layer_tree_host()->GetUIResourceSize(resource_->id()),
+ image_aperture_,
+ border_,
+ fill_center_);
+
// NinePatchLayer must push properties every commit to make sure
- // NinePatchLayerImpl::resource_id_ is valid.
+ // NinePatchLayerImpl::ui_resource_id_ is valid.
// http://crbug.com/276482
needs_push_properties_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698