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

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: Compilation error fixes 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
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/shared_ui_resource.h"
13 #include "cc/resources/ui_resource_bitmap.h"
11 #include "cc/trees/layer_tree_host.h" 14 #include "cc/trees/layer_tree_host.h"
12 15
13 namespace cc { 16 namespace cc {
14 17
15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() { 18 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
16 return make_scoped_refptr(new NinePatchLayer()); 19 return make_scoped_refptr(new NinePatchLayer());
17 } 20 }
18 21
19 NinePatchLayer::NinePatchLayer() 22 NinePatchLayer::NinePatchLayer()
20 : bitmap_dirty_(false) {} 23 : fill_center_(true) {}
21 24
22 NinePatchLayer::~NinePatchLayer() {} 25 NinePatchLayer::~NinePatchLayer() {}
23 26
24 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl( 27 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl(
25 LayerTreeImpl* tree_impl) { 28 LayerTreeImpl* tree_impl) {
26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 29 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
27 } 30 }
28 31
29 void NinePatchLayer::SetTexturePriorities( 32 void NinePatchLayer::SetLayerTreeHost(LayerTreeHost* host) {
30 const PriorityCalculator& priority_calc) { 33 // When the LTH is set to null or has changed, then this layer should remove
31 if (resource_ && !resource_->texture()->resource_manager()) { 34 // all of its associated resources.
32 // Release the resource here, as it is no longer tied to a resource manager. 35 if (!host || host != layer_tree_host())
33 resource_.reset(); 36 resource_.reset();
34 if (!bitmap_.isNull())
35 CreateResource();
36 } else if (bitmap_dirty_ && DrawsContent()) {
37 CreateResource();
38 }
39 37
40 if (resource_) { 38 Layer::SetLayerTreeHost(host);
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 } 39 }
49 40
50 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) { 41 void NinePatchLayer::SetBorder(gfx::Rect border) {
51 bitmap_ = bitmap; 42 if (border == border_)
52 image_aperture_ = aperture; 43 return;
53 bitmap_dirty_ = true; 44 border_ = border;
54 SetNeedsDisplay(); 45 SetNeedsCommit();
55 } 46 }
56 47
57 bool NinePatchLayer::Update(ResourceUpdateQueue* queue, 48 void NinePatchLayer::SetBitmap(const SkBitmap& skbitmap, gfx::Rect aperture) {
58 const OcclusionTracker* occlusion) { 49 if (!layer_tree_host())
59 bool updated = Layer::Update(queue, occlusion); 50 return;
51 image_aperture_ = aperture;
52 fill_center_ = false;
53 resource_ = ScopedUIResource::Create(
54 layer_tree_host(), CreateUIResourceBitmapFromSkBitmap(skbitmap));
60 55
61 CreateUpdaterIfNeeded(); 56 SetNeedsCommit();
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 } 57 }
78 58
79 void NinePatchLayer::CreateUpdaterIfNeeded() { 59 void NinePatchLayer::SetSharedBitmap(UIResourceId resource_id,
80 if (updater_.get()) 60 gfx::Rect aperture,
81 return; 61 bool fill_center) {
62 image_aperture_ = aperture;
63 fill_center_ = fill_center;
82 64
83 updater_ = ImageLayerUpdater::Create(); 65 if (resource_id)
84 } 66 resource_ = SharedUIResource::Create(resource_id);
85 67
86 void NinePatchLayer::CreateResource() { 68 SetNeedsCommit();
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 } 69 }
96 70
97 bool NinePatchLayer::DrawsContent() const { 71 bool NinePatchLayer::DrawsContent() const {
98 bool draws = !bitmap_.isNull() && 72 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.
99 Layer::DrawsContent() &&
100 bitmap_.width() &&
101 bitmap_.height();
102 return draws;
103 } 73 }
104 74
105 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { 75 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) {
106 Layer::PushPropertiesTo(layer); 76 Layer::PushPropertiesTo(layer);
107 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); 77 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
108 78
109 if (resource_) { 79 if (!resource_) {
110 DCHECK(!bitmap_.isNull()); 80 layer_impl->set_ui_resource_id(0);
111 layer_impl->SetResourceId(resource_->texture()->resource_id()); 81 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.
112 layer_impl->SetLayout(
113 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_);
114 } 82 }
115 83
84 layer_impl->set_ui_resource_id(resource_->id());
85 DCHECK(layer_tree_host());
86 layer_impl->SetLayout(layer_tree_host()->GetUIResourceSize(resource_->id()),
87 image_aperture_,
88 border_,
89 fill_center_);
90
116 // NinePatchLayer must push properties every commit to make sure 91 // NinePatchLayer must push properties every commit to make sure
117 // NinePatchLayerImpl::resource_id_ is valid. 92 // NinePatchLayerImpl::ui_resource_id_ is valid.
118 // http://crbug.com/276482 93 // http://crbug.com/276482
119 needs_push_properties_ = true; 94 needs_push_properties_ = true;
120 } 95 }
121 96
122 } // namespace cc 97 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698