| 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 "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "cc/blimp/client_picture_cache.h" | 9 #include "cc/blimp/client_picture_cache.h" |
| 10 #include "cc/blimp/engine_picture_cache.h" | 10 #include "cc/blimp/engine_picture_cache.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool PictureLayer::HasDrawableContent() const { | 201 bool PictureLayer::HasDrawableContent() const { |
| 202 return picture_layer_inputs_.client && Layer::HasDrawableContent(); | 202 return picture_layer_inputs_.client && Layer::HasDrawableContent(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | 205 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { |
| 206 proto->set_type(proto::LayerNode::PICTURE_LAYER); | 206 proto->set_type(proto::LayerNode::PICTURE_LAYER); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void PictureLayer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto, | 209 void PictureLayer::ToLayerPropertiesProto(proto::LayerProperties* proto) { |
| 210 bool inputs_only) { | |
| 211 DCHECK(GetLayerTree()); | 210 DCHECK(GetLayerTree()); |
| 212 DCHECK(GetLayerTree()->engine_picture_cache()); | 211 DCHECK(GetLayerTree()->engine_picture_cache()); |
| 213 | 212 |
| 214 Layer::LayerSpecificPropertiesToProto(proto, inputs_only); | 213 Layer::ToLayerPropertiesProto(proto); |
| 215 DropRecordingSourceContentIfInvalid(); | 214 DropRecordingSourceContentIfInvalid(); |
| 216 proto::PictureLayerProperties* picture = proto->mutable_picture(); | 215 proto::PictureLayerProperties* picture = proto->mutable_picture(); |
| 217 | 216 |
| 218 picture->set_nearest_neighbor(picture_layer_inputs_.nearest_neighbor); | 217 picture->set_nearest_neighbor(picture_layer_inputs_.nearest_neighbor); |
| 219 RectToProto(picture_layer_inputs_.recorded_viewport, | 218 RectToProto(picture_layer_inputs_.recorded_viewport, |
| 220 picture->mutable_recorded_viewport()); | 219 picture->mutable_recorded_viewport()); |
| 221 if (picture_layer_inputs_.display_list) { | 220 if (picture_layer_inputs_.display_list) { |
| 222 picture_layer_inputs_.display_list->ToProtobuf( | 221 picture_layer_inputs_.display_list->ToProtobuf( |
| 223 picture->mutable_display_list()); | 222 picture->mutable_display_list()); |
| 224 for (const auto& item : *picture_layer_inputs_.display_list) { | 223 for (const auto& item : *picture_layer_inputs_.display_list) { |
| 225 sk_sp<const SkPicture> picture = item.GetPicture(); | 224 sk_sp<const SkPicture> picture = item.GetPicture(); |
| 226 // Only DrawingDisplayItems have SkPictures. | 225 // Only DrawingDisplayItems have SkPictures. |
| 227 if (!picture) | 226 if (!picture) |
| 228 continue; | 227 continue; |
| 229 | 228 |
| 230 GetLayerTree()->engine_picture_cache()->MarkUsed(picture.get()); | 229 GetLayerTree()->engine_picture_cache()->MarkUsed(picture.get()); |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 | |
| 234 if (inputs_only) | |
| 235 return; | |
| 236 | |
| 237 recording_source_->ToProtobuf(picture->mutable_recording_source()); | |
| 238 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); | |
| 239 picture->set_is_mask(is_mask_); | |
| 240 picture->set_update_source_frame_number(update_source_frame_number_); | |
| 241 last_updated_invalidation_.Clear(); | |
| 242 } | |
| 243 | |
| 244 void PictureLayer::FromLayerSpecificPropertiesProto( | |
| 245 const proto::LayerProperties& proto) { | |
| 246 Layer::FromLayerSpecificPropertiesProto(proto); | |
| 247 const proto::PictureLayerProperties& picture = proto.picture(); | |
| 248 // If this is a new layer, ensure it has a recording source. During layer | |
| 249 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but | |
| 250 // instead the member is set directly, so it needs to be set here explicitly. | |
| 251 if (!recording_source_) | |
| 252 recording_source_.reset(new RecordingSource); | |
| 253 | |
| 254 std::vector<uint32_t> used_engine_picture_ids; | |
| 255 | |
| 256 picture_layer_inputs_.recorded_viewport = | |
| 257 ProtoToRect(picture.recorded_viewport()); | |
| 258 | |
| 259 ClientPictureCache* client_picture_cache = | |
| 260 GetLayerTree()->client_picture_cache(); | |
| 261 DCHECK(client_picture_cache); | |
| 262 // This might not exist if the |input_.display_list| of the serialized | |
| 263 // RecordingSource was null, which can happen if |Clear()| is | |
| 264 // called. | |
| 265 if (picture.has_display_list()) { | |
| 266 picture_layer_inputs_.display_list = DisplayItemList::CreateFromProto( | |
| 267 picture.display_list(), client_picture_cache, &used_engine_picture_ids); | |
| 268 } else { | |
| 269 picture_layer_inputs_.display_list = nullptr; | |
| 270 } | |
| 271 | |
| 272 recording_source_->FromProtobuf(picture.recording_source(), | |
| 273 picture_layer_inputs_.display_list, | |
| 274 picture_layer_inputs_.recorded_viewport); | |
| 275 | |
| 276 // Inform picture cache about which SkPictures are now in use. | |
| 277 for (uint32_t engine_picture_id : used_engine_picture_ids) | |
| 278 GetLayerTree()->client_picture_cache()->MarkUsed(engine_picture_id); | |
| 279 | |
| 280 Region new_invalidation = RegionFromProto(picture.invalidation()); | |
| 281 last_updated_invalidation_.Swap(&new_invalidation); | |
| 282 is_mask_ = picture.is_mask(); | |
| 283 picture_layer_inputs_.nearest_neighbor = picture.nearest_neighbor(); | |
| 284 | |
| 285 update_source_frame_number_ = picture.update_source_frame_number(); | |
| 286 } | 232 } |
| 287 | 233 |
| 288 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 234 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 289 benchmark->RunOnLayer(this); | 235 benchmark->RunOnLayer(this); |
| 290 } | 236 } |
| 291 | 237 |
| 292 void PictureLayer::DropRecordingSourceContentIfInvalid() { | 238 void PictureLayer::DropRecordingSourceContentIfInvalid() { |
| 293 int source_frame_number = layer_tree_host()->SourceFrameNumber(); | 239 int source_frame_number = layer_tree_host()->SourceFrameNumber(); |
| 294 gfx::Size recording_source_bounds = recording_source_->GetSize(); | 240 gfx::Size recording_source_bounds = recording_source_->GetSize(); |
| 295 | 241 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 314 picture_layer_inputs_.display_list = nullptr; | 260 picture_layer_inputs_.display_list = nullptr; |
| 315 picture_layer_inputs_.painter_reported_memory_usage = 0; | 261 picture_layer_inputs_.painter_reported_memory_usage = 0; |
| 316 } | 262 } |
| 317 } | 263 } |
| 318 | 264 |
| 319 const DisplayItemList* PictureLayer::GetDisplayItemList() { | 265 const DisplayItemList* PictureLayer::GetDisplayItemList() { |
| 320 return picture_layer_inputs_.display_list.get(); | 266 return picture_layer_inputs_.display_list.get(); |
| 321 } | 267 } |
| 322 | 268 |
| 323 } // namespace cc | 269 } // namespace cc |
| OLD | NEW |