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 18 matching lines...) Expand all Loading... | |
| 50 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 54 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 51 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. | 55 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. |
| 52 DCHECK_EQ(layer_impl->is_mask(), is_mask_); | 56 DCHECK_EQ(layer_impl->is_mask(), is_mask_); |
| 53 DropRecordingSourceContentIfInvalid(); | 57 DropRecordingSourceContentIfInvalid(); |
| 54 | 58 |
| 55 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor); | 59 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor); |
| 56 | 60 |
| 57 // Preserve lcd text settings from the current raster source. | 61 // Preserve lcd text settings from the current raster source. |
| 58 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); | 62 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); |
| 59 scoped_refptr<RasterSource> raster_source = | 63 scoped_refptr<RasterSource> raster_source = |
| 60 recording_source_->CreateRasterSource(can_use_lcd_text); | 64 recording_source_->CreateRasterSource( |
| 65 can_use_lcd_text, inputs_.recorded_viewport, inputs_.display_list, | |
| 66 inputs_.painter_reported_memory_usage); | |
| 61 layer_impl->set_gpu_raster_max_texture_size( | 67 layer_impl->set_gpu_raster_max_texture_size( |
| 62 layer_tree_host()->device_viewport_size()); | 68 layer_tree_host()->device_viewport_size()); |
| 63 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, | 69 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, |
| 64 nullptr); | 70 nullptr); |
| 65 DCHECK(last_updated_invalidation_.IsEmpty()); | 71 DCHECK(last_updated_invalidation_.IsEmpty()); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 74 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 69 Layer::SetLayerTreeHost(host); | 75 Layer::SetLayerTreeHost(host); |
| 70 if (!host) | 76 if (!host) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 "source_frame_number", | 108 "source_frame_number", |
| 103 layer_tree_host()->source_frame_number()); | 109 layer_tree_host()->source_frame_number()); |
| 104 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 110 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
| 105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 111 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
| 106 | 112 |
| 107 // UpdateAndExpandInvalidation will give us an invalidation that covers | 113 // UpdateAndExpandInvalidation will give us an invalidation that covers |
| 108 // anything not explicitly recorded in this frame. We give this region | 114 // 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 | 115 // to the impl side so that it drops tiles that may not have a recording |
| 110 // for them. | 116 // for them. |
| 111 DCHECK(inputs_.client); | 117 DCHECK(inputs_.client); |
| 118 | |
| 119 gfx::Rect old_recorded_viewport = inputs_.recorded_viewport; | |
| 120 inputs_.recorded_viewport = inputs_.client->PaintableRegion(); | |
| 121 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able | |
| 122 // to slow down recording. | |
| 123 inputs_.display_list = inputs_.client->PaintContentsToDisplayList( | |
| 124 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | |
| 125 inputs_.painter_reported_memory_usage = | |
| 126 inputs_.client->GetApproximateUnsharedMemoryUsage(); | |
| 127 | |
| 112 updated |= recording_source_->UpdateAndExpandInvalidation( | 128 updated |= recording_source_->UpdateAndExpandInvalidation( |
| 113 inputs_.client, &last_updated_invalidation_, layer_size, | 129 inputs_.client, &last_updated_invalidation_, layer_size, |
| 114 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); | 130 old_recorded_viewport, inputs_.recorded_viewport, inputs_.display_list); |
|
vmpstr
2016/07/25 20:29:14
We're passing some more inputs in here, which is f
Menglin
2016/07/25 20:41:08
So RecordingSource still has all its current membe
| |
| 115 | 131 |
| 116 if (updated) { | 132 if (updated) { |
| 117 SetNeedsPushProperties(); | 133 SetNeedsPushProperties(); |
| 118 } else { | 134 } else { |
| 119 // If this invalidation did not affect the recording source, then it can be | 135 // If this invalidation did not affect the recording source, then it can be |
| 120 // cleared as an optimization. | 136 // cleared as an optimization. |
| 121 last_updated_invalidation_.Clear(); | 137 last_updated_invalidation_.Clear(); |
| 122 } | 138 } |
| 123 | 139 |
| 124 return updated; | 140 return updated; |
| 125 } | 141 } |
| 126 | 142 |
| 127 void PictureLayer::SetIsMask(bool is_mask) { | 143 void PictureLayer::SetIsMask(bool is_mask) { |
| 128 is_mask_ = is_mask; | 144 is_mask_ = is_mask; |
| 129 } | 145 } |
| 130 | 146 |
| 131 sk_sp<SkPicture> PictureLayer::GetPicture() const { | 147 sk_sp<SkPicture> PictureLayer::GetPicture() const { |
| 132 // We could either flatten the RecordingSource into a single | 148 // 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 | 149 // 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. | 150 // picture. For now we just paint a fresh one to get consistent results. |
| 135 if (!DrawsContent()) | 151 if (!DrawsContent()) |
| 136 return nullptr; | 152 return nullptr; |
| 137 | 153 |
| 138 gfx::Size layer_size = bounds(); | 154 gfx::Size layer_size = bounds(); |
| 139 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); | 155 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); |
| 140 Region recording_invalidation; | 156 Region recording_invalidation; |
| 157 | |
| 158 gfx::Rect old_recorded_viewport; | |
| 159 gfx::Rect new_recorded_viewport = inputs_.client->PaintableRegion(); | |
| 160 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able | |
|
vmpstr
2016/07/25 20:29:14
This todo doesn't need to be here.
Menglin
2016/07/25 21:58:52
Done.
| |
| 161 // to slow down recording. | |
| 162 scoped_refptr<DisplayItemList> display_list = | |
| 163 inputs_.client->PaintContentsToDisplayList( | |
| 164 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | |
| 165 size_t painter_reported_memory_usage = | |
| 166 inputs_.client->GetApproximateUnsharedMemoryUsage(); | |
| 167 | |
| 141 recording_source->UpdateAndExpandInvalidation( | 168 recording_source->UpdateAndExpandInvalidation( |
| 142 inputs_.client, &recording_invalidation, layer_size, | 169 inputs_.client, &recording_invalidation, layer_size, |
| 143 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); | 170 old_recorded_viewport, new_recorded_viewport, display_list); |
| 144 | 171 |
| 145 scoped_refptr<RasterSource> raster_source = | 172 scoped_refptr<RasterSource> raster_source = |
| 146 recording_source->CreateRasterSource(false); | 173 recording_source->CreateRasterSource(false, new_recorded_viewport, |
| 174 display_list, | |
| 175 painter_reported_memory_usage); | |
| 147 | 176 |
| 148 return raster_source->GetFlattenedPicture(); | 177 return raster_source->GetFlattenedPicture(); |
| 149 } | 178 } |
| 150 | 179 |
| 151 bool PictureLayer::IsSuitableForGpuRasterization() const { | 180 bool PictureLayer::IsSuitableForGpuRasterization() const { |
| 152 return recording_source_->IsSuitableForGpuRasterization(); | 181 // The display list needs to be created (see: UpdateAndExpandInvalidation) |
| 182 // before checking for suitability. There are cases where an update will not | |
| 183 // create a display list (e.g., if the size is empty). We return true in these | |
| 184 // cases because the gpu suitability bit sticks false. | |
| 185 return !inputs_.display_list || | |
| 186 inputs_.display_list->IsSuitableForGpuRasterization(); | |
| 153 } | 187 } |
| 154 | 188 |
| 155 void PictureLayer::ClearClient() { | 189 void PictureLayer::ClearClient() { |
| 156 inputs_.client = nullptr; | 190 inputs_.client = nullptr; |
| 157 UpdateDrawsContent(HasDrawableContent()); | 191 UpdateDrawsContent(HasDrawableContent()); |
| 158 } | 192 } |
| 159 | 193 |
| 160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { | 194 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { |
| 161 if (inputs_.nearest_neighbor == nearest_neighbor) | 195 if (inputs_.nearest_neighbor == nearest_neighbor) |
| 162 return; | 196 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 174 } | 208 } |
| 175 | 209 |
| 176 void PictureLayer::LayerSpecificPropertiesToProto( | 210 void PictureLayer::LayerSpecificPropertiesToProto( |
| 177 proto::LayerProperties* proto) { | 211 proto::LayerProperties* proto) { |
| 178 Layer::LayerSpecificPropertiesToProto(proto); | 212 Layer::LayerSpecificPropertiesToProto(proto); |
| 179 DropRecordingSourceContentIfInvalid(); | 213 DropRecordingSourceContentIfInvalid(); |
| 180 | 214 |
| 181 proto::PictureLayerProperties* picture = proto->mutable_picture(); | 215 proto::PictureLayerProperties* picture = proto->mutable_picture(); |
| 182 recording_source_->ToProtobuf(picture->mutable_recording_source()); | 216 recording_source_->ToProtobuf(picture->mutable_recording_source()); |
| 183 | 217 |
| 184 // Add all SkPicture items to the picture cache. | 218 RectToProto(inputs_.recorded_viewport, picture->mutable_recorded_viewport()); |
| 185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); | 219 if (inputs_.display_list) { |
| 186 if (display_list) { | 220 inputs_.display_list->ToProtobuf(picture->mutable_display_list()); |
| 187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { | 221 for (auto it = inputs_.display_list->begin(); |
| 222 it != inputs_.display_list->end(); ++it) { | |
| 188 sk_sp<const SkPicture> picture = it->GetPicture(); | 223 sk_sp<const SkPicture> picture = it->GetPicture(); |
| 189 // Only DrawingDisplayItems have SkPictures. | 224 // Only DrawingDisplayItems have SkPictures. |
| 190 if (!picture) | 225 if (!picture) |
| 191 continue; | 226 continue; |
| 192 | 227 |
| 193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); | 228 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); |
| 194 } | 229 } |
| 195 } | 230 } |
| 196 | 231 |
| 197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); | 232 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); |
| 198 picture->set_is_mask(is_mask_); | 233 picture->set_is_mask(is_mask_); |
| 199 picture->set_nearest_neighbor(inputs_.nearest_neighbor); | 234 picture->set_nearest_neighbor(inputs_.nearest_neighbor); |
| 200 | 235 |
| 201 picture->set_update_source_frame_number(update_source_frame_number_); | 236 picture->set_update_source_frame_number(update_source_frame_number_); |
| 202 | 237 |
| 203 last_updated_invalidation_.Clear(); | 238 last_updated_invalidation_.Clear(); |
| 204 } | 239 } |
| 205 | 240 |
| 206 void PictureLayer::FromLayerSpecificPropertiesProto( | 241 void PictureLayer::FromLayerSpecificPropertiesProto( |
| 207 const proto::LayerProperties& proto) { | 242 const proto::LayerProperties& proto) { |
| 208 Layer::FromLayerSpecificPropertiesProto(proto); | 243 Layer::FromLayerSpecificPropertiesProto(proto); |
| 209 const proto::PictureLayerProperties& picture = proto.picture(); | 244 const proto::PictureLayerProperties& picture = proto.picture(); |
| 210 // If this is a new layer, ensure it has a recording source. During layer | 245 // If this is a new layer, ensure it has a recording source. During layer |
| 211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but | 246 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but |
| 212 // instead the member is set directly, so it needs to be set here explicitly. | 247 // instead the member is set directly, so it needs to be set here explicitly. |
| 213 if (!recording_source_) | 248 if (!recording_source_) |
| 214 recording_source_.reset(new RecordingSource); | 249 recording_source_.reset(new RecordingSource); |
| 215 | 250 |
| 216 std::vector<uint32_t> used_engine_picture_ids; | 251 std::vector<uint32_t> used_engine_picture_ids; |
| 252 | |
| 253 inputs_.recorded_viewport = ProtoToRect(picture.recorded_viewport()); | |
| 254 | |
| 255 ClientPictureCache* client_picture_cache = | |
| 256 layer_tree_host()->client_picture_cache(); | |
| 257 DCHECK(client_picture_cache); | |
| 258 // This might not exist if the |input_.display_list| of the serialized | |
| 259 // RecordingSource was null, which can happen if |Clear()| is | |
| 260 // called. | |
| 261 if (picture.has_display_list()) { | |
| 262 inputs_.display_list = DisplayItemList::CreateFromProto( | |
| 263 picture.display_list(), client_picture_cache, &used_engine_picture_ids); | |
| 264 } else { | |
| 265 inputs_.display_list = nullptr; | |
| 266 } | |
| 267 | |
| 217 recording_source_->FromProtobuf(picture.recording_source(), | 268 recording_source_->FromProtobuf(picture.recording_source(), |
| 218 layer_tree_host()->client_picture_cache(), | 269 inputs_.display_list); |
| 219 &used_engine_picture_ids); | |
| 220 | 270 |
| 221 // Inform picture cache about which SkPictures are now in use. | 271 // Inform picture cache about which SkPictures are now in use. |
| 222 for (uint32_t engine_picture_id : used_engine_picture_ids) | 272 for (uint32_t engine_picture_id : used_engine_picture_ids) |
| 223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); | 273 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); |
| 224 | 274 |
| 225 Region new_invalidation = RegionFromProto(picture.invalidation()); | 275 Region new_invalidation = RegionFromProto(picture.invalidation()); |
| 226 last_updated_invalidation_.Swap(&new_invalidation); | 276 last_updated_invalidation_.Swap(&new_invalidation); |
| 227 is_mask_ = picture.is_mask(); | 277 is_mask_ = picture.is_mask(); |
| 228 inputs_.nearest_neighbor = picture.nearest_neighbor(); | 278 inputs_.nearest_neighbor = picture.nearest_neighbor(); |
| 229 | 279 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 248 layer_bounds == recording_source_bounds) | 298 layer_bounds == recording_source_bounds) |
| 249 << " bounds " << layer_bounds.ToString() << " recording source " | 299 << " bounds " << layer_bounds.ToString() << " recording source " |
| 250 << recording_source_bounds.ToString(); | 300 << recording_source_bounds.ToString(); |
| 251 | 301 |
| 252 if (update_source_frame_number_ != source_frame_number && | 302 if (update_source_frame_number_ != source_frame_number && |
| 253 recording_source_bounds != layer_bounds) { | 303 recording_source_bounds != layer_bounds) { |
| 254 // Update may not get called for the layer (if it's not in the viewport | 304 // 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 | 305 // for example), even though it has resized making the recording source no |
| 256 // longer valid. In this case just destroy the recording source. | 306 // longer valid. In this case just destroy the recording source. |
| 257 recording_source_->SetEmptyBounds(); | 307 recording_source_->SetEmptyBounds(); |
| 308 inputs_.recorded_viewport = gfx::Rect(); | |
| 309 inputs_.display_list = nullptr; | |
| 310 inputs_.painter_reported_memory_usage = 0; | |
| 258 } | 311 } |
| 259 } | 312 } |
| 260 | 313 |
| 261 } // namespace cc | 314 } // namespace cc |
| OLD | NEW |