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

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: Addressed comments by danakj and aelias. Modified tests. 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..aa89d3223e24617bb2857940ef0f422867bf7c88 100644
--- a/cc/layers/nine_patch_layer.cc
+++ b/cc/layers/nine_patch_layer.cc
@@ -8,16 +8,40 @@
#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/ui_resource_bitmap.h"
#include "cc/trees/layer_tree_host.h"
namespace cc {
+scoped_ptr<NinePatchLayer::ScopedResource>
+NinePatchLayer::ScopedResource::Create(LayerTreeHost* host,
+ const SkBitmap& skbitmap) {
+ return make_scoped_ptr(new NinePatchLayer::ScopedResource(host, skbitmap));
+}
+
+UIResourceId NinePatchLayer::ScopedResource::id() { return resource_->id(); }
+
+NinePatchLayer::ScopedResource::ScopedResource(LayerTreeHost* host,
+ const SkBitmap& skbitmap) {
+ resource_ = ScopedUIResource::Create(
+ host, UIResourceBitmap::CreateFromSkBitmap(skbitmap));
+}
+
+scoped_ptr<NinePatchLayer::SharedResource>
+NinePatchLayer::SharedResource::Create(UIResourceId id) {
+ return make_scoped_ptr(new NinePatchLayer::SharedResource(id));
+}
+
+UIResourceId NinePatchLayer::SharedResource::id() { return id_; }
+
+NinePatchLayer::SharedResource::SharedResource(UIResourceId id) : id_(id) {}
+
scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
return make_scoped_refptr(new NinePatchLayer());
}
-NinePatchLayer::NinePatchLayer()
- : bitmap_dirty_(false) {}
+NinePatchLayer::NinePatchLayer() : fill_center_(true) {}
NinePatchLayer::~NinePatchLayer() {}
@@ -26,95 +50,65 @@ 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);
- }
+ Layer::SetLayerTreeHost(host);
}
-void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) {
- bitmap_ = bitmap;
- image_aperture_ = aperture;
- bitmap_dirty_ = true;
- SetNeedsDisplay();
-}
-
-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_ = ScopedResource::Create(layer_tree_host(), 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;
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.
+ fill_center_ = fill_center;
- if (!resource_) {
- resource_ = updater_->CreateResource(
- layer_tree_host()->contents_texture_manager());
- }
+ if (resource_id)
+ resource_ = SharedResource::Create(resource_id);
+
+ SetNeedsCommit();
}
bool NinePatchLayer::DrawsContent() const {
- bool draws = !bitmap_.isNull() &&
- Layer::DrawsContent() &&
- bitmap_.width() &&
- bitmap_.height();
- return draws;
+ 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.
}
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->SetUIResourceId(0);
+ } else {
+ layer_impl->SetUIResourceId(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
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
- // 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