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

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: Rebasing and addressing previous comments 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 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;
60 53
61 CreateUpdaterIfNeeded(); 54 resource_ = ScopedUIResource::Create(
55 layer_tree_host(),
56 CreateUIResourceBitmapFromSkBitmap(skbitmap));
62 57
63 if (resource_ && 58 SetNeedsCommit();
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 } 59 }
78 60
79 void NinePatchLayer::CreateUpdaterIfNeeded() { 61 void NinePatchLayer::SetSharedBitmap(UIResourceId resource_id,
80 if (updater_.get()) 62 gfx::Rect aperture,
81 return; 63 bool fill_center,
64 gfx::Size size) {
65 image_aperture_ = aperture;
66 fill_center_ = fill_center;
82 67
83 updater_ = ImageLayerUpdater::Create(); 68 if (resource_id)
84 } 69 resource_ = SharedUIResource::Create(resource_id, size);
85 70
86 void NinePatchLayer::CreateResource() { 71 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 } 72 }
96 73
97 bool NinePatchLayer::DrawsContent() const { 74 bool NinePatchLayer::DrawsContent() const {
98 bool draws = !bitmap_.isNull() && 75 return resource_.get() && resource_->id() && Layer::DrawsContent();
99 Layer::DrawsContent() &&
100 bitmap_.width() &&
101 bitmap_.height();
102 return draws;
103 } 76 }
104 77
105 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { 78 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) {
106 Layer::PushPropertiesTo(layer); 79 Layer::PushPropertiesTo(layer);
107 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); 80 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
108 81 if (!resource_) {
109 if (resource_) { 82 layer_impl->set_ui_resource_id(0);
110 DCHECK(!bitmap_.isNull()); 83 return;
111 layer_impl->SetResourceId(resource_->texture()->resource_id());
112 layer_impl->SetLayout(
113 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_);
114 } 84 }
115 85
116 // NinePatchLayer must push properties every commit to make sure 86 // NinePatchLayer must push properties every commit to make sure
117 // NinePatchLayerImpl::resource_id_ is valid. 87 // NinePatchLayerImpl::resource_id_ is valid.
118 // http://crbug.com/276482 88 // http://crbug.com/276482
119 needs_push_properties_ = true; 89 needs_push_properties_ = true;
90
91 layer_impl->set_ui_resource_id(resource_->id());
92 layer_impl->SetLayout(resource_->GetSize(),
93 image_aperture_,
94 border_,
95 fill_center_);
120 } 96 }
121 97
122 } // namespace cc 98 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698