Chromium Code Reviews| 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" |
| 11 #include "cc/playback/recording_source.h" | 11 #include "cc/playback/recording_source.h" |
| 12 #include "cc/proto/cc_conversions.h" | 12 #include "cc/proto/cc_conversions.h" |
| 13 #include "cc/proto/gfx_conversions.h" | 13 #include "cc/proto/gfx_conversions.h" |
| 14 #include "cc/proto/layer.pb.h" | 14 #include "cc/proto/layer.pb.h" |
| 15 #include "cc/trees/layer_tree_host.h" | 15 #include "cc/trees/layer_tree_host.h" |
| 16 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
| 17 #include "third_party/skia/include/core/SkPictureRecorder.h" | 17 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 18 #include "ui/gfx/geometry/rect_conversions.h" | 18 #include "ui/gfx/geometry/rect_conversions.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 | 21 |
| 22 PictureLayer::Inputs::Inputs() = default; | |
| 23 | |
| 24 PictureLayer::Inputs::~Inputs() = default; | |
| 25 | |
| 22 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 26 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
| 23 return make_scoped_refptr(new PictureLayer(client)); | 27 return make_scoped_refptr(new PictureLayer(client)); |
| 24 } | 28 } |
| 25 | 29 |
| 26 PictureLayer::PictureLayer(ContentLayerClient* client) | 30 PictureLayer::PictureLayer(ContentLayerClient* client) |
| 27 : instrumentation_object_tracker_(id()), | 31 : instrumentation_object_tracker_(id()), |
| 28 update_source_frame_number_(-1), | 32 update_source_frame_number_(-1), |
| 29 is_mask_(false) { | 33 is_mask_(false) { |
| 30 inputs_.client = client; | 34 inputs_.client = client; |
| 31 } | 35 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 "source_frame_number", | 106 "source_frame_number", |
| 103 layer_tree_host()->source_frame_number()); | 107 layer_tree_host()->source_frame_number()); |
| 104 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 108 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
| 105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 109 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
| 106 | 110 |
| 107 // UpdateAndExpandInvalidation will give us an invalidation that covers | 111 // UpdateAndExpandInvalidation will give us an invalidation that covers |
| 108 // anything not explicitly recorded in this frame. We give this region | 112 // anything not explicitly recorded in this frame. We give this region |
| 109 // to the impl side so that it drops tiles that may not have a recording | 113 // to the impl side so that it drops tiles that may not have a recording |
| 110 // for them. | 114 // for them. |
| 111 DCHECK(inputs_.client); | 115 DCHECK(inputs_.client); |
| 116 | |
| 117 inputs_.recorded_viewport = inputs_.client->PaintableRegion(); | |
| 118 inputs_.display_list = inputs_.client->PaintContentsToDisplayList( | |
| 119 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | |
| 120 inputs_.painter_reported_memory_usage = | |
| 121 inputs_.client->GetApproximateUnsharedMemoryUsage(); | |
| 122 | |
| 112 updated |= recording_source_->UpdateAndExpandInvalidation( | 123 updated |= recording_source_->UpdateAndExpandInvalidation( |
| 113 inputs_.client, &last_updated_invalidation_, layer_size, | 124 inputs_.client, &last_updated_invalidation_, layer_size, |
| 114 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); | 125 inputs_.recorded_viewport, inputs_.display_list, |
| 126 inputs_.painter_reported_memory_usage); | |
| 115 | 127 |
| 116 if (updated) { | 128 if (updated) { |
| 117 SetNeedsPushProperties(); | 129 SetNeedsPushProperties(); |
| 118 } else { | 130 } else { |
| 119 // If this invalidation did not affect the recording source, then it can be | 131 // If this invalidation did not affect the recording source, then it can be |
| 120 // cleared as an optimization. | 132 // cleared as an optimization. |
| 121 last_updated_invalidation_.Clear(); | 133 last_updated_invalidation_.Clear(); |
| 122 } | 134 } |
| 123 | 135 |
| 124 return updated; | 136 return updated; |
| 125 } | 137 } |
| 126 | 138 |
| 127 void PictureLayer::SetIsMask(bool is_mask) { | 139 void PictureLayer::SetIsMask(bool is_mask) { |
| 128 is_mask_ = is_mask; | 140 is_mask_ = is_mask; |
| 129 } | 141 } |
| 130 | 142 |
| 131 sk_sp<SkPicture> PictureLayer::GetPicture() const { | 143 sk_sp<SkPicture> PictureLayer::GetPicture() const { |
| 132 // We could either flatten the RecordingSource into a single | 144 // We could either flatten the RecordingSource into a single |
| 133 // SkPicture, or paint a fresh one depending on what we intend to do with the | 145 // SkPicture, or paint a fresh one depending on what we intend to do with the |
| 134 // picture. For now we just paint a fresh one to get consistent results. | 146 // picture. For now we just paint a fresh one to get consistent results. |
| 135 if (!DrawsContent()) | 147 if (!DrawsContent()) |
| 136 return nullptr; | 148 return nullptr; |
| 137 | 149 |
| 138 gfx::Size layer_size = bounds(); | 150 gfx::Size layer_size = bounds(); |
| 139 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); | 151 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); |
|
vmpstr
2016/07/25 22:03:26
While here, we can change this to be on the stack
Menglin
2016/07/26 17:49:41
Done.
| |
| 140 Region recording_invalidation; | 152 Region recording_invalidation; |
| 153 | |
| 154 gfx::Rect new_recorded_viewport = inputs_.client->PaintableRegion(); | |
| 155 scoped_refptr<DisplayItemList> display_list = | |
| 156 inputs_.client->PaintContentsToDisplayList( | |
| 157 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | |
| 158 size_t painter_reported_memory_usage = | |
| 159 inputs_.client->GetApproximateUnsharedMemoryUsage(); | |
| 160 | |
| 141 recording_source->UpdateAndExpandInvalidation( | 161 recording_source->UpdateAndExpandInvalidation( |
| 142 inputs_.client, &recording_invalidation, layer_size, | 162 inputs_.client, &recording_invalidation, layer_size, |
| 143 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); | 163 new_recorded_viewport, display_list, painter_reported_memory_usage); |
| 144 | 164 |
| 145 scoped_refptr<RasterSource> raster_source = | 165 scoped_refptr<RasterSource> raster_source = |
| 146 recording_source->CreateRasterSource(false); | 166 recording_source->CreateRasterSource(false); |
| 147 | 167 |
| 148 return raster_source->GetFlattenedPicture(); | 168 return raster_source->GetFlattenedPicture(); |
| 149 } | 169 } |
| 150 | 170 |
| 151 bool PictureLayer::IsSuitableForGpuRasterization() const { | 171 bool PictureLayer::IsSuitableForGpuRasterization() const { |
| 152 return recording_source_->IsSuitableForGpuRasterization(); | 172 // The display list needs to be created (see: UpdateAndExpandInvalidation) |
| 173 // before checking for suitability. There are cases where an update will not | |
| 174 // create a display list (e.g., if the size is empty). We return true in these | |
| 175 // cases because the gpu suitability bit sticks false. | |
| 176 return !inputs_.display_list || | |
| 177 inputs_.display_list->IsSuitableForGpuRasterization(); | |
| 153 } | 178 } |
| 154 | 179 |
| 155 void PictureLayer::ClearClient() { | 180 void PictureLayer::ClearClient() { |
| 156 inputs_.client = nullptr; | 181 inputs_.client = nullptr; |
| 157 UpdateDrawsContent(HasDrawableContent()); | 182 UpdateDrawsContent(HasDrawableContent()); |
| 158 } | 183 } |
| 159 | 184 |
| 160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { | 185 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { |
| 161 if (inputs_.nearest_neighbor == nearest_neighbor) | 186 if (inputs_.nearest_neighbor == nearest_neighbor) |
| 162 return; | 187 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 174 } | 199 } |
| 175 | 200 |
| 176 void PictureLayer::LayerSpecificPropertiesToProto( | 201 void PictureLayer::LayerSpecificPropertiesToProto( |
| 177 proto::LayerProperties* proto) { | 202 proto::LayerProperties* proto) { |
| 178 Layer::LayerSpecificPropertiesToProto(proto); | 203 Layer::LayerSpecificPropertiesToProto(proto); |
| 179 DropRecordingSourceContentIfInvalid(); | 204 DropRecordingSourceContentIfInvalid(); |
| 180 | 205 |
| 181 proto::PictureLayerProperties* picture = proto->mutable_picture(); | 206 proto::PictureLayerProperties* picture = proto->mutable_picture(); |
| 182 recording_source_->ToProtobuf(picture->mutable_recording_source()); | 207 recording_source_->ToProtobuf(picture->mutable_recording_source()); |
| 183 | 208 |
| 184 // Add all SkPicture items to the picture cache. | 209 RectToProto(inputs_.recorded_viewport, picture->mutable_recorded_viewport()); |
| 185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); | 210 if (inputs_.display_list) { |
| 186 if (display_list) { | 211 inputs_.display_list->ToProtobuf(picture->mutable_display_list()); |
| 187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { | 212 for (auto it = inputs_.display_list->begin(); |
| 213 it != inputs_.display_list->end(); ++it) { | |
| 188 sk_sp<const SkPicture> picture = it->GetPicture(); | 214 sk_sp<const SkPicture> picture = it->GetPicture(); |
| 189 // Only DrawingDisplayItems have SkPictures. | 215 // Only DrawingDisplayItems have SkPictures. |
| 190 if (!picture) | 216 if (!picture) |
| 191 continue; | 217 continue; |
| 192 | 218 |
| 193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); | 219 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); |
| 194 } | 220 } |
| 195 } | 221 } |
| 196 | 222 |
| 197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); | 223 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); |
| 198 picture->set_is_mask(is_mask_); | 224 picture->set_is_mask(is_mask_); |
| 199 picture->set_nearest_neighbor(inputs_.nearest_neighbor); | 225 picture->set_nearest_neighbor(inputs_.nearest_neighbor); |
| 200 | 226 |
| 201 picture->set_update_source_frame_number(update_source_frame_number_); | 227 picture->set_update_source_frame_number(update_source_frame_number_); |
| 202 | 228 |
| 203 last_updated_invalidation_.Clear(); | 229 last_updated_invalidation_.Clear(); |
| 204 } | 230 } |
| 205 | 231 |
| 206 void PictureLayer::FromLayerSpecificPropertiesProto( | 232 void PictureLayer::FromLayerSpecificPropertiesProto( |
| 207 const proto::LayerProperties& proto) { | 233 const proto::LayerProperties& proto) { |
| 208 Layer::FromLayerSpecificPropertiesProto(proto); | 234 Layer::FromLayerSpecificPropertiesProto(proto); |
| 209 const proto::PictureLayerProperties& picture = proto.picture(); | 235 const proto::PictureLayerProperties& picture = proto.picture(); |
| 210 // If this is a new layer, ensure it has a recording source. During layer | 236 // If this is a new layer, ensure it has a recording source. During layer |
| 211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but | 237 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but |
| 212 // instead the member is set directly, so it needs to be set here explicitly. | 238 // instead the member is set directly, so it needs to be set here explicitly. |
| 213 if (!recording_source_) | 239 if (!recording_source_) |
| 214 recording_source_.reset(new RecordingSource); | 240 recording_source_.reset(new RecordingSource); |
| 215 | 241 |
| 216 std::vector<uint32_t> used_engine_picture_ids; | 242 std::vector<uint32_t> used_engine_picture_ids; |
| 243 | |
| 244 inputs_.recorded_viewport = ProtoToRect(picture.recorded_viewport()); | |
| 245 | |
| 246 ClientPictureCache* client_picture_cache = | |
| 247 layer_tree_host()->client_picture_cache(); | |
| 248 DCHECK(client_picture_cache); | |
| 249 // This might not exist if the |input_.display_list| of the serialized | |
| 250 // RecordingSource was null, which can happen if |Clear()| is | |
| 251 // called. | |
| 252 if (picture.has_display_list()) { | |
| 253 inputs_.display_list = DisplayItemList::CreateFromProto( | |
| 254 picture.display_list(), client_picture_cache, &used_engine_picture_ids); | |
| 255 } else { | |
| 256 inputs_.display_list = nullptr; | |
| 257 } | |
| 258 | |
| 217 recording_source_->FromProtobuf(picture.recording_source(), | 259 recording_source_->FromProtobuf(picture.recording_source(), |
| 218 layer_tree_host()->client_picture_cache(), | 260 inputs_.display_list); |
| 219 &used_engine_picture_ids); | |
| 220 | 261 |
| 221 // Inform picture cache about which SkPictures are now in use. | 262 // Inform picture cache about which SkPictures are now in use. |
| 222 for (uint32_t engine_picture_id : used_engine_picture_ids) | 263 for (uint32_t engine_picture_id : used_engine_picture_ids) |
| 223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); | 264 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); |
| 224 | 265 |
| 225 Region new_invalidation = RegionFromProto(picture.invalidation()); | 266 Region new_invalidation = RegionFromProto(picture.invalidation()); |
| 226 last_updated_invalidation_.Swap(&new_invalidation); | 267 last_updated_invalidation_.Swap(&new_invalidation); |
| 227 is_mask_ = picture.is_mask(); | 268 is_mask_ = picture.is_mask(); |
| 228 inputs_.nearest_neighbor = picture.nearest_neighbor(); | 269 inputs_.nearest_neighbor = picture.nearest_neighbor(); |
| 229 | 270 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 248 layer_bounds == recording_source_bounds) | 289 layer_bounds == recording_source_bounds) |
| 249 << " bounds " << layer_bounds.ToString() << " recording source " | 290 << " bounds " << layer_bounds.ToString() << " recording source " |
| 250 << recording_source_bounds.ToString(); | 291 << recording_source_bounds.ToString(); |
| 251 | 292 |
| 252 if (update_source_frame_number_ != source_frame_number && | 293 if (update_source_frame_number_ != source_frame_number && |
| 253 recording_source_bounds != layer_bounds) { | 294 recording_source_bounds != layer_bounds) { |
| 254 // Update may not get called for the layer (if it's not in the viewport | 295 // Update may not get called for the layer (if it's not in the viewport |
| 255 // for example), even though it has resized making the recording source no | 296 // for example), even though it has resized making the recording source no |
| 256 // longer valid. In this case just destroy the recording source. | 297 // longer valid. In this case just destroy the recording source. |
| 257 recording_source_->SetEmptyBounds(); | 298 recording_source_->SetEmptyBounds(); |
| 299 inputs_.recorded_viewport = gfx::Rect(); | |
| 300 inputs_.display_list = nullptr; | |
| 301 inputs_.painter_reported_memory_usage = 0; | |
| 258 } | 302 } |
| 259 } | 303 } |
| 260 | 304 |
| 261 } // namespace cc | 305 } // namespace cc |
| OLD | NEW |