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

Side by Side 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: updated dchecks in ui_resource_bitmap Created 7 years, 3 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 unified diff | Download patch
« no previous file with comments | « cc/layers/nine_patch_layer.h ('k') | cc/layers/nine_patch_layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
18 namespace {
19
20 class ScopedUIResourceHolder : public NinePatchLayer::UIResourceHolder {
21 public:
22 static scoped_ptr<ScopedUIResourceHolder> Create(LayerTreeHost* host,
23 const SkBitmap& skbitmap) {
24 return make_scoped_ptr(new ScopedUIResourceHolder(host, skbitmap));
25 }
26 virtual UIResourceId id() OVERRIDE { return resource_->id(); }
27
28 private:
29 ScopedUIResourceHolder(LayerTreeHost* host, const SkBitmap& skbitmap) {
30 resource_ = ScopedUIResource::Create(host, UIResourceBitmap(skbitmap));
31 }
32
33 scoped_ptr<ScopedUIResource> resource_;
34 };
35
36 class SharedUIResourceHolder : public NinePatchLayer::UIResourceHolder {
37 public:
38 static scoped_ptr<SharedUIResourceHolder> Create(UIResourceId id) {
39 return make_scoped_ptr(new SharedUIResourceHolder(id));
40 }
41
42 virtual UIResourceId id() OVERRIDE { return id_; }
43
44 private:
45 explicit SharedUIResourceHolder(UIResourceId id) : id_(id) {}
46
47 UIResourceId id_;
48 };
49
50 } // anonymous namespace
51
52
53 NinePatchLayer::UIResourceHolder::~UIResourceHolder() {}
54
15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { 55 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
16 return make_scoped_refptr(new NinePatchLayer()); 56 return make_scoped_refptr(new NinePatchLayer());
17 } 57 }
18 58
19 NinePatchLayer::NinePatchLayer() 59 NinePatchLayer::NinePatchLayer() : fill_center_(false) {}
20 : bitmap_dirty_(false) {}
21 60
22 NinePatchLayer::~NinePatchLayer() {} 61 NinePatchLayer::~NinePatchLayer() {}
23 62
24 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( 63 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl(
25 LayerTreeImpl* tree_impl) { 64 LayerTreeImpl* tree_impl) {
26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 65 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
27 } 66 }
28 67
29 void NinePatchLayer::SetTexturePriorities( 68 void NinePatchLayer::SetLayerTreeHost(LayerTreeHost* host) {
30 const PriorityCalculator& priority_calc) { 69 // When the LTH is set to null or has changed, then this layer should remove
31 if (resource_ && !resource_->texture()->resource_manager()) { 70 // all of its associated resources.
32 // Release the resource here, as it is no longer tied to a resource manager. 71 if (!host || host != layer_tree_host())
33 resource_.reset(); 72 ui_resource_holder_.reset();
34 if (!bitmap_.isNull()) 73
35 CreateResource(); 74 Layer::SetLayerTreeHost(host);
36 } else if (bitmap_dirty_ && DrawsContent()) { 75 }
37 CreateResource(); 76
77 void NinePatchLayer::SetBorder(gfx::Rect border) {
78 if (border == border_)
79 return;
80 border_ = border;
81 SetNeedsCommit();
82 }
83
84 void NinePatchLayer::SetBitmap(const SkBitmap& skbitmap, gfx::Rect aperture) {
85 if (!layer_tree_host())
86 return;
ccameron 2013/09/10 21:18:30 This (and not setting the border) are causing the
87 image_aperture_ = aperture;
88 ui_resource_holder_ =
89 ScopedUIResourceHolder::Create(layer_tree_host(), skbitmap);
90
91 SetNeedsCommit();
92 }
93
94 void NinePatchLayer::SetUIResourceId(UIResourceId resource_id,
95 gfx::Rect aperture) {
96 if (ui_resource_holder_ && ui_resource_holder_->id() == resource_id &&
97 image_aperture_ == aperture)
98 return;
99
100 image_aperture_ = aperture;
101 if (resource_id) {
102 ui_resource_holder_ = SharedUIResourceHolder::Create(resource_id);
103 } else {
104 ui_resource_holder_.reset();
38 } 105 }
39 106
40 if (resource_) { 107 SetNeedsCommit();
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 } 108 }
49 109
50 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) { 110 void NinePatchLayer::SetFillCenter(bool fill_center) {
51 bitmap_ = bitmap; 111 if (fill_center_ == fill_center)
52 image_aperture_ = aperture;
53 bitmap_dirty_ = true;
54 SetNeedsDisplay();
55 }
56
57 bool NinePatchLayer::Update(ResourceUpdateQueue* queue,
58 const OcclusionTracker* occlusion) {
59 bool updated = Layer::Update(queue, occlusion);
60
61 CreateUpdaterIfNeeded();
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 }
78
79 void NinePatchLayer::CreateUpdaterIfNeeded() {
80 if (updater_.get())
81 return; 112 return;
82 113
83 updater_ = ImageLayerUpdater::Create(); 114 fill_center_ = fill_center;
84 } 115 SetNeedsCommit();
85
86 void NinePatchLayer::CreateResource() {
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 } 116 }
96 117
97 bool NinePatchLayer::DrawsContent() const { 118 bool NinePatchLayer::DrawsContent() const {
98 bool draws = !bitmap_.isNull() && 119 return ui_resource_holder_ && ui_resource_holder_->id() &&
99 Layer::DrawsContent() && 120 Layer::DrawsContent();
100 bitmap_.width() &&
101 bitmap_.height();
102 return draws;
103 } 121 }
104 122
105 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { 123 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) {
106 Layer::PushPropertiesTo(layer); 124 Layer::PushPropertiesTo(layer);
107 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); 125 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
108 126
109 if (resource_) { 127 if (!ui_resource_holder_) {
110 DCHECK(!bitmap_.isNull()); 128 layer_impl->SetUIResourceId(0);
111 layer_impl->SetResourceId(resource_->texture()->resource_id()); 129 } else {
112 layer_impl->SetLayout( 130 DCHECK(layer_tree_host());
113 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_); 131
132 gfx::Size image_size =
133 layer_tree_host()->GetUIResourceSize(ui_resource_holder_->id());
134 layer_impl->SetUIResourceId(ui_resource_holder_->id());
135 layer_impl->SetLayout(image_size, image_aperture_, border_, fill_center_);
114 } 136 }
115
116 // NinePatchLayer must push properties every commit to make sure
117 // NinePatchLayerImpl::resource_id_ is valid.
118 // http://crbug.com/276482
119 needs_push_properties_ = true;
120 } 137 }
121 138
122 } // namespace cc 139 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/nine_patch_layer.h ('k') | cc/layers/nine_patch_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698