| 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 update_source_frame_number_(-1) { | 23 has_gpu_rasterization_hint_(false), |
| 24 } | 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 pile_->UpdateRecordedRegion(); | 46 pile_->UpdateRecordedRegion(); |
| 47 } else if (update_source_frame_number_ == | 47 } else if (update_source_frame_number_ == |
| 48 layer_tree_host()->source_frame_number()) { | 48 layer_tree_host()->source_frame_number()) { |
| 49 // If update called, then pile size must match bounds pushed to impl layer. | 49 // If update called, then pile size must match bounds pushed to impl layer. |
| 50 DCHECK_EQ(layer_impl->bounds().ToString(), pile_->size().ToString()); | 50 DCHECK_EQ(layer_impl->bounds().ToString(), pile_->size().ToString()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 layer_impl->SetIsMask(is_mask_); | 53 layer_impl->SetIsMask(is_mask_); |
| 54 layer_impl->SetHasGpuRasterizationHint(has_gpu_rasterization_hint_); |
| 55 |
| 54 // Unlike other properties, invalidation must always be set on layer_impl. | 56 // Unlike other properties, invalidation must always be set on layer_impl. |
| 55 // See PictureLayerImpl::PushPropertiesTo for more details. | 57 // See PictureLayerImpl::PushPropertiesTo for more details. |
| 56 layer_impl->invalidation_.Clear(); | 58 layer_impl->invalidation_.Clear(); |
| 57 layer_impl->invalidation_.Swap(&pile_invalidation_); | 59 layer_impl->invalidation_.Swap(&pile_invalidation_); |
| 58 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); | 60 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 63 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 62 Layer::SetLayerTreeHost(host); | 64 Layer::SetLayerTreeHost(host); |
| 63 if (host) { | 65 if (host) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 pile_invalidation_.Clear(); | 129 pile_invalidation_.Clear(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 return updated; | 132 return updated; |
| 131 } | 133 } |
| 132 | 134 |
| 133 void PictureLayer::SetIsMask(bool is_mask) { | 135 void PictureLayer::SetIsMask(bool is_mask) { |
| 134 is_mask_ = is_mask; | 136 is_mask_ = is_mask; |
| 135 } | 137 } |
| 136 | 138 |
| 139 void PictureLayer::SetHasGpuRasterizationHint(bool has_hint) { |
| 140 DCHECK(IsPropertyChangeAllowed()); |
| 141 if (has_gpu_rasterization_hint_ == has_hint) |
| 142 return; |
| 143 has_gpu_rasterization_hint_ = has_hint; |
| 144 SetNeedsCommit(); |
| 145 } |
| 146 |
| 137 bool PictureLayer::SupportsLCDText() const { | 147 bool PictureLayer::SupportsLCDText() const { |
| 138 return true; | 148 return true; |
| 139 } | 149 } |
| 140 | 150 |
| 141 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { | 151 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { |
| 142 // We could either flatten the PicturePile into a single SkPicture, | 152 // We could either flatten the PicturePile into a single SkPicture, |
| 143 // or paint a fresh one depending on what we intend to do with the | 153 // or paint a fresh one depending on what we intend to do with the |
| 144 // picture. For now we just paint a fresh one to get consistent results. | 154 // picture. For now we just paint a fresh one to get consistent results. |
| 145 if (!DrawsContent()) | 155 if (!DrawsContent()) |
| 146 return skia::RefPtr<SkPicture>(); | 156 return skia::RefPtr<SkPicture>(); |
| 147 | 157 |
| 148 int width = bounds().width(); | 158 int width = bounds().width(); |
| 149 int height = bounds().height(); | 159 int height = bounds().height(); |
| 150 gfx::RectF opaque; | 160 gfx::RectF opaque; |
| 151 | 161 |
| 152 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); | 162 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); |
| 153 SkCanvas* canvas = picture->beginRecording(width, height); | 163 SkCanvas* canvas = picture->beginRecording(width, height); |
| 154 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque); | 164 client_->PaintContents(canvas, gfx::Rect(width, height), &opaque); |
| 155 picture->endRecording(); | 165 picture->endRecording(); |
| 156 return picture; | 166 return picture; |
| 157 } | 167 } |
| 158 | 168 |
| 159 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 169 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 160 benchmark->RunOnLayer(this); | 170 benchmark->RunOnLayer(this); |
| 161 } | 171 } |
| 162 | 172 |
| 163 } // namespace cc | 173 } // namespace cc |
| OLD | NEW |