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

Side by Side Diff: cc/layers/picture_layer.cc

Issue 222903005: cc: Let skia veto gpu rasterization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: replaced && with &= Created 6 years, 8 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 | Annotate | Revision Log
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/picture_layer.h" 5 #include "cc/layers/picture_layer.h"
6 6
7 #include "cc/layers/content_layer_client.h" 7 #include "cc/layers/content_layer_client.h"
8 #include "cc/layers/picture_layer_impl.h" 8 #include "cc/layers/picture_layer_impl.h"
9 #include "cc/trees/layer_tree_impl.h" 9 #include "cc/trees/layer_tree_impl.h"
10 #include "ui/gfx/rect_conversions.h" 10 #include "ui/gfx/rect_conversions.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { 14 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
15 return make_scoped_refptr(new PictureLayer(client)); 15 return make_scoped_refptr(new PictureLayer(client));
16 } 16 }
17 17
18 PictureLayer::PictureLayer(ContentLayerClient* client) 18 PictureLayer::PictureLayer(ContentLayerClient* client)
19 : client_(client), 19 : client_(client),
20 pile_(make_scoped_refptr(new PicturePile())), 20 pile_(make_scoped_refptr(new PicturePile())),
21 instrumentation_object_tracker_(id()), 21 instrumentation_object_tracker_(id()),
22 is_mask_(false), 22 is_mask_(false),
23 has_gpu_rasterization_hint_(false), 23 has_gpu_rasterization_hint_(TRIBOOL_UNKNOWN),
24 update_source_frame_number_(-1) {} 24 update_source_frame_number_(-1) {}
25 25
26 PictureLayer::~PictureLayer() { 26 PictureLayer::~PictureLayer() {
27 } 27 }
28 28
29 bool PictureLayer::DrawsContent() const { 29 bool PictureLayer::DrawsContent() const {
30 return Layer::DrawsContent() && client_; 30 return Layer::DrawsContent() && client_;
31 } 31 }
32 32
33 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { 33 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
34 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 34 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
35 } 35 }
36 36
37 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { 37 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
38 Layer::PushPropertiesTo(base_layer); 38 Layer::PushPropertiesTo(base_layer);
39 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 39 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
40 40
41 if (layer_impl->bounds().IsEmpty()) { 41 if (layer_impl->bounds().IsEmpty()) {
42 // Update may not get called for an empty layer, so resize here instead. 42 // Update may not get called for an empty layer, so resize here instead.
43 // Using layer_impl because either bounds() or paint_properties().bounds 43 // Using layer_impl because either bounds() or paint_properties().bounds
44 // may disagree and either one could have been pushed to layer_impl. 44 // may disagree and either one could have been pushed to layer_impl.
45 pile_->Resize(gfx::Size()); 45 pile_->Resize(gfx::Size());
46 } else if (update_source_frame_number_ == 46 } else if (update_source_frame_number_ ==
47 layer_tree_host()->source_frame_number()) { 47 layer_tree_host()->source_frame_number()) {
48 // If update called, then pile size must match bounds pushed to impl layer. 48 // If update called, then pile size must match bounds pushed to impl layer.
49 DCHECK_EQ(layer_impl->bounds().ToString(), pile_->size().ToString()); 49 DCHECK_EQ(layer_impl->bounds().ToString(), pile_->size().ToString());
50 } 50 }
51 51
52 layer_impl->SetIsMask(is_mask_); 52 layer_impl->SetIsMask(is_mask_);
53 layer_impl->SetHasGpuRasterizationHint(has_gpu_rasterization_hint_); 53 layer_impl->SetUseGpuRasterization(ShouldUseGpuRasterization());
54 54
55 // Unlike other properties, invalidation must always be set on layer_impl. 55 // Unlike other properties, invalidation must always be set on layer_impl.
56 // See PictureLayerImpl::PushPropertiesTo for more details. 56 // See PictureLayerImpl::PushPropertiesTo for more details.
57 layer_impl->invalidation_.Clear(); 57 layer_impl->invalidation_.Clear();
58 layer_impl->invalidation_.Swap(&pile_invalidation_); 58 layer_impl->invalidation_.Swap(&pile_invalidation_);
59 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); 59 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get());
60 } 60 }
61 61
62 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { 62 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
63 Layer::SetLayerTreeHost(host); 63 Layer::SetLayerTreeHost(host);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 return updated; 133 return updated;
134 } 134 }
135 135
136 void PictureLayer::SetIsMask(bool is_mask) { 136 void PictureLayer::SetIsMask(bool is_mask) {
137 is_mask_ = is_mask; 137 is_mask_ = is_mask;
138 } 138 }
139 139
140 void PictureLayer::SetHasGpuRasterizationHint(bool has_hint) { 140 void PictureLayer::SetHasGpuRasterizationHint(bool has_hint) {
141 DCHECK(IsPropertyChangeAllowed()); 141 switch (has_gpu_rasterization_hint_) {
142 if (has_gpu_rasterization_hint_ == has_hint) 142 case TRIBOOL_UNKNOWN: // Fall-through.
143 return; 143 case TRIBOOL_TRUE:
144 has_gpu_rasterization_hint_ = has_hint; 144 has_gpu_rasterization_hint_ = has_hint ? TRIBOOL_TRUE : TRIBOOL_FALSE;
enne (OOO) 2014/04/04 19:40:07 In other words, keep this function the same as bef
145 SetNeedsCommit(); 145 break;
146 case TRIBOOL_FALSE:
147 // GPU rasterization cannot be enabled once disabled.
148 // This is done to prevent frequent invalidations and visual flashing.
149 break;
150 default:
151 NOTREACHED();
152 }
153 // No need to commit immediately.
154 // This flag will be pushed with the next commit.
155 }
156
157 bool PictureLayer::ShouldUseGpuRasterization() const {
158 switch (layer_tree_host()->settings().rasterization_site) {
159 case LayerTreeSettings::CpuRasterization:
160 return false;
161 case LayerTreeSettings::HybridRasterization:
162 return has_gpu_rasterization_hint_ == TRIBOOL_TRUE &&
enne (OOO) 2014/04/04 19:40:07 ...and just say has_gpu_rasterization_hint_ && pil
alokp 2014/04/04 21:53:46 I do not think there is any redundancy. Both the f
163 pile_->is_suitable_for_gpu_rasterization();
164 case LayerTreeSettings::GpuRasterization:
165 return true;
166 }
167 NOTREACHED();
168 return false;
146 } 169 }
147 170
148 bool PictureLayer::SupportsLCDText() const { 171 bool PictureLayer::SupportsLCDText() const {
149 return true; 172 return true;
150 } 173 }
151 174
152 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { 175 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const {
153 // We could either flatten the PicturePile into a single SkPicture, 176 // We could either flatten the PicturePile into a single SkPicture,
154 // or paint a fresh one depending on what we intend to do with the 177 // or paint a fresh one depending on what we intend to do with the
155 // picture. For now we just paint a fresh one to get consistent results. 178 // picture. For now we just paint a fresh one to get consistent results.
156 if (!DrawsContent()) 179 if (!DrawsContent())
157 return skia::RefPtr<SkPicture>(); 180 return skia::RefPtr<SkPicture>();
158 181
159 int width = bounds().width(); 182 int width = bounds().width();
160 int height = bounds().height(); 183 int height = bounds().height();
161 gfx::RectF opaque; 184 gfx::RectF opaque;
162 185
163 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 186 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
164 SkCanvas* canvas = picture->beginRecording(width, height); 187 SkCanvas* canvas = picture->beginRecording(width, height);
165 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque); 188 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque);
166 picture->endRecording(); 189 picture->endRecording();
167 return picture; 190 return picture;
168 } 191 }
169 192
170 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { 193 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
171 benchmark->RunOnLayer(this); 194 benchmark->RunOnLayer(this);
172 } 195 }
173 196
174 } // namespace cc 197 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698