| 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/layers/content_layer_client.h" | 9 #include "cc/layers/content_layer_client.h" |
| 10 #include "cc/layers/picture_layer_impl.h" | 10 #include "cc/layers/picture_layer_impl.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | 172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { |
| 173 proto->set_type(proto::LayerNode::PICTURE_LAYER); | 173 proto->set_type(proto::LayerNode::PICTURE_LAYER); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void PictureLayer::LayerSpecificPropertiesToProto( | 176 void PictureLayer::LayerSpecificPropertiesToProto( |
| 177 proto::LayerProperties* proto) { | 177 proto::LayerProperties* proto) { |
| 178 Layer::LayerSpecificPropertiesToProto(proto); | 178 Layer::LayerSpecificPropertiesToProto(proto); |
| 179 DropRecordingSourceContentIfInvalid(); | 179 DropRecordingSourceContentIfInvalid(); |
| 180 | 180 |
| 181 proto::PictureLayerProperties* picture = proto->mutable_picture(); | 181 proto::PictureLayerProperties* picture = proto->mutable_picture(); |
| 182 recording_source_->ToProtobuf( | 182 recording_source_->ToProtobuf(picture->mutable_recording_source()); |
| 183 picture->mutable_recording_source(), | 183 |
| 184 layer_tree_host()->image_serialization_processor()); | 184 // Add all SkPicture items to the picture cache. |
| 185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); |
| 186 if (display_list) { |
| 187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { |
| 188 sk_sp<const SkPicture> picture = it->GetPicture(); |
| 189 // Only DrawingDisplayItems have SkPictures. |
| 190 if (!picture) |
| 191 continue; |
| 192 |
| 193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); |
| 194 } |
| 195 } |
| 196 |
| 185 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); | 197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); |
| 186 picture->set_is_mask(is_mask_); | 198 picture->set_is_mask(is_mask_); |
| 187 picture->set_nearest_neighbor(nearest_neighbor_); | 199 picture->set_nearest_neighbor(nearest_neighbor_); |
| 188 | 200 |
| 189 picture->set_update_source_frame_number(update_source_frame_number_); | 201 picture->set_update_source_frame_number(update_source_frame_number_); |
| 190 | 202 |
| 191 last_updated_invalidation_.Clear(); | 203 last_updated_invalidation_.Clear(); |
| 192 } | 204 } |
| 193 | 205 |
| 194 void PictureLayer::FromLayerSpecificPropertiesProto( | 206 void PictureLayer::FromLayerSpecificPropertiesProto( |
| 195 const proto::LayerProperties& proto) { | 207 const proto::LayerProperties& proto) { |
| 196 Layer::FromLayerSpecificPropertiesProto(proto); | 208 Layer::FromLayerSpecificPropertiesProto(proto); |
| 197 const proto::PictureLayerProperties& picture = proto.picture(); | 209 const proto::PictureLayerProperties& picture = proto.picture(); |
| 198 // If this is a new layer, ensure it has a recording source. During layer | 210 // If this is a new layer, ensure it has a recording source. During layer |
| 199 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but | 211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but |
| 200 // instead the member is set directly, so it needs to be set here explicitly. | 212 // instead the member is set directly, so it needs to be set here explicitly. |
| 201 if (!recording_source_) | 213 if (!recording_source_) |
| 202 recording_source_.reset(new RecordingSource); | 214 recording_source_.reset(new RecordingSource); |
| 203 | 215 |
| 204 recording_source_->FromProtobuf( | 216 std::vector<uint32_t> used_engine_picture_ids; |
| 205 picture.recording_source(), | 217 recording_source_->FromProtobuf(picture.recording_source(), |
| 206 layer_tree_host()->image_serialization_processor()); | 218 layer_tree_host()->client_picture_cache(), |
| 219 &used_engine_picture_ids); |
| 220 |
| 221 // Inform picture cache about which SkPictures are now in use. |
| 222 for (uint32_t engine_picture_id : used_engine_picture_ids) |
| 223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); |
| 207 | 224 |
| 208 Region new_invalidation = RegionFromProto(picture.invalidation()); | 225 Region new_invalidation = RegionFromProto(picture.invalidation()); |
| 209 last_updated_invalidation_.Swap(&new_invalidation); | 226 last_updated_invalidation_.Swap(&new_invalidation); |
| 210 is_mask_ = picture.is_mask(); | 227 is_mask_ = picture.is_mask(); |
| 211 nearest_neighbor_ = picture.nearest_neighbor(); | 228 nearest_neighbor_ = picture.nearest_neighbor(); |
| 212 | 229 |
| 213 update_source_frame_number_ = picture.update_source_frame_number(); | 230 update_source_frame_number_ = picture.update_source_frame_number(); |
| 214 } | 231 } |
| 215 | 232 |
| 216 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 233 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 235 if (update_source_frame_number_ != source_frame_number && | 252 if (update_source_frame_number_ != source_frame_number && |
| 236 recording_source_bounds != layer_bounds) { | 253 recording_source_bounds != layer_bounds) { |
| 237 // Update may not get called for the layer (if it's not in the viewport | 254 // Update may not get called for the layer (if it's not in the viewport |
| 238 // for example), even though it has resized making the recording source no | 255 // for example), even though it has resized making the recording source no |
| 239 // longer valid. In this case just destroy the recording source. | 256 // longer valid. In this case just destroy the recording source. |
| 240 recording_source_->SetEmptyBounds(); | 257 recording_source_->SetEmptyBounds(); |
| 241 } | 258 } |
| 242 } | 259 } |
| 243 | 260 |
| 244 } // namespace cc | 261 } // namespace cc |
| OLD | NEW |