| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "cc/layers/content_layer_client.h" | 8 #include "cc/layers/content_layer_client.h" |
| 9 #include "cc/layers/picture_layer_impl.h" | 9 #include "cc/layers/picture_layer_impl.h" |
| 10 #include "cc/resources/picture_pile.h" |
| 10 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
| 11 #include "third_party/skia/include/core/SkPictureRecorder.h" | 12 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 12 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 | 16 |
| 16 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 17 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
| 17 return make_scoped_refptr(new PictureLayer(client)); | 18 return make_scoped_refptr(new PictureLayer(client)); |
| 18 } | 19 } |
| 19 | 20 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 36 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
| 36 Layer::PushPropertiesTo(base_layer); | 37 Layer::PushPropertiesTo(base_layer); |
| 37 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 38 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 38 | 39 |
| 39 int source_frame_number = layer_tree_host()->source_frame_number(); | 40 int source_frame_number = layer_tree_host()->source_frame_number(); |
| 40 gfx::Size impl_bounds = layer_impl->bounds(); | 41 gfx::Size impl_bounds = layer_impl->bounds(); |
| 41 gfx::Size recording_source_bounds = recording_source_->GetSize(); | 42 gfx::Size recording_source_bounds = recording_source_->GetSize(); |
| 42 | 43 |
| 43 // If update called, then pile size must match bounds pushed to impl layer. | 44 // If update called, then recording source size must match bounds pushed to |
| 45 // impl layer. |
| 44 DCHECK_IMPLIES(update_source_frame_number_ == source_frame_number, | 46 DCHECK_IMPLIES(update_source_frame_number_ == source_frame_number, |
| 45 impl_bounds == recording_source_bounds) | 47 impl_bounds == recording_source_bounds) |
| 46 << " bounds " << impl_bounds.ToString() << " pile " | 48 << " bounds " << impl_bounds.ToString() << " recording source " |
| 47 << recording_source_bounds.ToString(); | 49 << recording_source_bounds.ToString(); |
| 48 | 50 |
| 49 if (update_source_frame_number_ != source_frame_number && | 51 if (update_source_frame_number_ != source_frame_number && |
| 50 recording_source_bounds != impl_bounds) { | 52 recording_source_bounds != impl_bounds) { |
| 51 // Update may not get called for the layer (if it's not in the viewport | 53 // Update may not get called for the layer (if it's not in the viewport |
| 52 // for example, even though it has resized making the pile no longer | 54 // for example, even though it has resized making the recording source no |
| 53 // valid. In this case just destroy the pile. | 55 // longer valid. In this case just destroy the recording source. |
| 54 recording_source_->SetEmptyBounds(); | 56 recording_source_->SetEmptyBounds(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 // Unlike other properties, invalidation must always be set on layer_impl. | 59 // Unlike other properties, invalidation must always be set on layer_impl. |
| 58 // See PictureLayerImpl::PushPropertiesTo for more details. | 60 // See PictureLayerImpl::PushPropertiesTo for more details. |
| 59 layer_impl->invalidation_.Clear(); | 61 layer_impl->invalidation_.Clear(); |
| 60 layer_impl->invalidation_.Swap(&recording_invalidation_); | 62 layer_impl->invalidation_.Swap(&recording_invalidation_); |
| 61 layer_impl->UpdateRasterSource(recording_source_->CreateRasterSource()); | 63 layer_impl->UpdateRasterSource(recording_source_->CreateRasterSource()); |
| 62 } | 64 } |
| 63 | 65 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 updated |= recording_source_->UpdateAndExpandInvalidation( | 131 updated |= recording_source_->UpdateAndExpandInvalidation( |
| 130 client_, &recording_invalidation_, SafeOpaqueBackgroundColor(), | 132 client_, &recording_invalidation_, SafeOpaqueBackgroundColor(), |
| 131 contents_opaque(), client_->FillsBoundsCompletely(), layer_size, | 133 contents_opaque(), client_->FillsBoundsCompletely(), layer_size, |
| 132 visible_layer_rect, update_source_frame_number_, | 134 visible_layer_rect, update_source_frame_number_, |
| 133 Picture::RECORD_NORMALLY); | 135 Picture::RECORD_NORMALLY); |
| 134 last_updated_visible_content_rect_ = visible_content_rect(); | 136 last_updated_visible_content_rect_ = visible_content_rect(); |
| 135 | 137 |
| 136 if (updated) { | 138 if (updated) { |
| 137 SetNeedsPushProperties(); | 139 SetNeedsPushProperties(); |
| 138 } else { | 140 } else { |
| 139 // If this invalidation did not affect the pile, then it can be cleared as | 141 // If this invalidation did not affect the recording source, then it can be |
| 140 // an optimization. | 142 // cleared as an optimization. |
| 141 recording_invalidation_.Clear(); | 143 recording_invalidation_.Clear(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 return updated; | 146 return updated; |
| 145 } | 147 } |
| 146 | 148 |
| 147 void PictureLayer::SetIsMask(bool is_mask) { | 149 void PictureLayer::SetIsMask(bool is_mask) { |
| 148 recording_source_->SetIsMask(is_mask); | 150 recording_source_->SetIsMask(is_mask); |
| 149 } | 151 } |
| 150 | 152 |
| 151 bool PictureLayer::SupportsLCDText() const { | 153 bool PictureLayer::SupportsLCDText() const { |
| 152 return true; | 154 return true; |
| 153 } | 155 } |
| 154 | 156 |
| 155 void PictureLayer::UpdateCanUseLCDText() { | 157 void PictureLayer::UpdateCanUseLCDText() { |
| 156 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 158 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
| 157 return; | 159 return; |
| 158 | 160 |
| 159 can_use_lcd_text_last_frame_ = can_use_lcd_text(); | 161 can_use_lcd_text_last_frame_ = can_use_lcd_text(); |
| 160 if (client_) | 162 if (client_) |
| 161 client_->DidChangeLayerCanUseLCDText(); | 163 client_->DidChangeLayerCanUseLCDText(); |
| 162 } | 164 } |
| 163 | 165 |
| 164 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { | 166 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { |
| 165 // We could either flatten the PicturePile into a single SkPicture, | 167 // We could either flatten the RecordingSource into a single SkPicture, |
| 166 // or paint a fresh one depending on what we intend to do with the | 168 // or paint a fresh one depending on what we intend to do with the |
| 167 // picture. For now we just paint a fresh one to get consistent results. | 169 // picture. For now we just paint a fresh one to get consistent results. |
| 168 if (!DrawsContent()) | 170 if (!DrawsContent()) |
| 169 return skia::RefPtr<SkPicture>(); | 171 return skia::RefPtr<SkPicture>(); |
| 170 | 172 |
| 171 int width = bounds().width(); | 173 int width = bounds().width(); |
| 172 int height = bounds().height(); | 174 int height = bounds().height(); |
| 173 | 175 |
| 174 SkPictureRecorder recorder; | 176 SkPictureRecorder recorder; |
| 175 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); | 177 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 191 | 193 |
| 192 bool PictureLayer::HasDrawableContent() const { | 194 bool PictureLayer::HasDrawableContent() const { |
| 193 return client_ && Layer::HasDrawableContent(); | 195 return client_ && Layer::HasDrawableContent(); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 198 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 197 benchmark->RunOnLayer(this); | 199 benchmark->RunOnLayer(this); |
| 198 } | 200 } |
| 199 | 201 |
| 200 } // namespace cc | 202 } // namespace cc |
| OLD | NEW |