OLD | NEW |
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 Loading... |
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; |
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 set needs commit or push-properties. |
| 154 // If only the hint changes and the layer is still valid, there is no need |
| 155 // to invalidate the rasterization for the whole layer. If there is an |
| 156 // invalidation (current or future) we will re-raster everything so that it |
| 157 // is consistent across the layer. |
| 158 } |
| 159 |
| 160 bool PictureLayer::ShouldUseGpuRasterization() const { |
| 161 switch (layer_tree_host()->settings().rasterization_site) { |
| 162 case LayerTreeSettings::CpuRasterization: |
| 163 return false; |
| 164 case LayerTreeSettings::HybridRasterization: |
| 165 return has_gpu_rasterization_hint_ == TRIBOOL_TRUE && |
| 166 pile_->is_suitable_for_gpu_rasterization(); |
| 167 case LayerTreeSettings::GpuRasterization: |
| 168 return true; |
| 169 } |
| 170 NOTREACHED(); |
| 171 return false; |
146 } | 172 } |
147 | 173 |
148 bool PictureLayer::SupportsLCDText() const { | 174 bool PictureLayer::SupportsLCDText() const { |
149 return true; | 175 return true; |
150 } | 176 } |
151 | 177 |
152 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { | 178 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { |
153 // We could either flatten the PicturePile into a single SkPicture, | 179 // 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 | 180 // 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. | 181 // picture. For now we just paint a fresh one to get consistent results. |
156 if (!DrawsContent()) | 182 if (!DrawsContent()) |
157 return skia::RefPtr<SkPicture>(); | 183 return skia::RefPtr<SkPicture>(); |
158 | 184 |
159 int width = bounds().width(); | 185 int width = bounds().width(); |
160 int height = bounds().height(); | 186 int height = bounds().height(); |
161 gfx::RectF opaque; | 187 gfx::RectF opaque; |
162 | 188 |
163 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); | 189 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); |
164 SkCanvas* canvas = picture->beginRecording(width, height); | 190 SkCanvas* canvas = picture->beginRecording(width, height); |
165 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque); | 191 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque); |
166 picture->endRecording(); | 192 picture->endRecording(); |
167 return picture; | 193 return picture; |
168 } | 194 } |
169 | 195 |
170 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 196 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
171 benchmark->RunOnLayer(this); | 197 benchmark->RunOnLayer(this); |
172 } | 198 } |
173 | 199 |
174 } // namespace cc | 200 } // namespace cc |
OLD | NEW |