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" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 } | 24 } |
| 25 | 25 |
| 26 PictureLayer::PictureLayer(ContentLayerClient* client) | 26 PictureLayer::PictureLayer(ContentLayerClient* client) |
| 27 : instrumentation_object_tracker_(id()), | 27 : instrumentation_object_tracker_(id()), |
| 28 update_source_frame_number_(-1), | 28 update_source_frame_number_(-1), |
| 29 is_mask_(false) { | 29 is_mask_(false) { |
| 30 inputs_.client = client; | 30 inputs_.client = client; |
| 31 } | 31 } |
| 32 | 32 |
| 33 PictureLayer::PictureLayer(ContentLayerClient* client, | 33 PictureLayer::PictureLayer(ContentLayerClient* client, |
| 34 std::unique_ptr<RecordingSource> source) | 34 const PictureLayerData& pl_data, |
| 35 const ContentLayerClientData& clc_data) | |
| 35 : PictureLayer(client) { | 36 : PictureLayer(client) { |
| 36 recording_source_ = std::move(source); | 37 pl_data_ = pl_data; |
|
vmpstr
2016/07/19 23:43:22
set these in the initialization list just above
Menglin
2016/07/20 00:28:42
Done.
Menglin
2016/07/20 21:25:22
Actually, if i move the initialization in the list
| |
| 38 clc_data_ = clc_data; | |
| 37 } | 39 } |
| 38 | 40 |
| 39 PictureLayer::~PictureLayer() { | 41 PictureLayer::~PictureLayer() { |
| 40 } | 42 } |
| 41 | 43 |
| 42 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl( | 44 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl( |
| 43 LayerTreeImpl* tree_impl) { | 45 LayerTreeImpl* tree_impl) { |
| 44 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); | 46 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 49 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
| 48 Layer::PushPropertiesTo(base_layer); | 50 Layer::PushPropertiesTo(base_layer); |
| 49 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); | 51 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); |
| 50 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 52 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 51 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. | 53 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. |
| 52 DCHECK_EQ(layer_impl->is_mask(), is_mask_); | 54 DCHECK_EQ(layer_impl->is_mask(), is_mask_); |
| 53 DropRecordingSourceContentIfInvalid(); | 55 DropRecordingSourceContentIfInvalid(); |
| 54 | 56 |
| 55 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor); | 57 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor); |
| 56 | 58 |
| 57 // Preserve lcd text settings from the current raster source. | 59 // Preserve lcd text settings from the current raster source. |
| 58 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); | 60 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); |
| 61 std::unique_ptr<RecordingSource> recording_source( | |
|
vmpstr
2016/07/19 23:43:22
Just create this on the stack if you need it. Do y
Menglin
2016/07/20 00:18:13
Currently the raster source is constructed based o
vmpstr
2016/07/20 00:27:06
I think we can just have RasterSource(display_list
Menglin
2016/07/20 21:25:22
I change it to RasterSource(const PictureLayerData
| |
| 62 new RecordingSource(pl_data_, clc_data_)); | |
| 59 scoped_refptr<RasterSource> raster_source = | 63 scoped_refptr<RasterSource> raster_source = |
| 60 recording_source_->CreateRasterSource(can_use_lcd_text); | 64 recording_source->CreateRasterSource(can_use_lcd_text); |
| 61 layer_impl->set_gpu_raster_max_texture_size( | 65 layer_impl->set_gpu_raster_max_texture_size( |
| 62 layer_tree_host()->device_viewport_size()); | 66 layer_tree_host()->device_viewport_size()); |
| 63 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, | 67 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, |
| 64 nullptr); | 68 nullptr); |
| 65 DCHECK(last_updated_invalidation_.IsEmpty()); | 69 DCHECK(last_updated_invalidation_.IsEmpty()); |
| 66 } | 70 } |
| 67 | 71 |
| 68 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 72 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 69 Layer::SetLayerTreeHost(host); | 73 Layer::SetLayerTreeHost(host); |
| 70 if (!host) | 74 if (!host) |
| 71 return; | 75 return; |
| 72 | 76 |
| 73 if (!recording_source_) | 77 pl_data_.reset(); |
|
vmpstr
2016/07/19 23:43:22
Where is PictureLayerData defined? I can't find it
Menglin
2016/07/20 00:18:13
Now it's in recording_source.h. I had it there bec
| |
| 74 recording_source_.reset(new RecordingSource); | 78 clc_data_.reset(); |
| 75 recording_source_->SetSlowdownRasterScaleFactor( | 79 SetSlowdownRasterScaleFactor( |
| 76 host->debug_state().slow_down_raster_scale_factor); | 80 host->debug_state().slow_down_raster_scale_factor); |
| 77 // If we need to enable image decode tasks, then we have to generate the | 81 // If we need to enable image decode tasks, then we have to generate the |
| 78 // discardable images metadata. | 82 // discardable images metadata. |
| 79 const LayerTreeSettings& settings = layer_tree_host()->settings(); | 83 const LayerTreeSettings& settings = layer_tree_host()->settings(); |
| 80 recording_source_->SetGenerateDiscardableImagesMetadata( | 84 SetGenerateDiscardableImagesMetadata(settings.image_decode_tasks_enabled); |
| 81 settings.image_decode_tasks_enabled); | |
| 82 } | 85 } |
| 83 | 86 |
| 84 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 87 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
| 85 DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); | 88 DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); |
| 86 if (recording_source_) | 89 SetNeedsDisplayRectSimple(layer_rect); |
| 87 recording_source_->SetNeedsDisplayRect(layer_rect); | |
| 88 Layer::SetNeedsDisplayRect(layer_rect); | 90 Layer::SetNeedsDisplayRect(layer_rect); |
| 89 } | 91 } |
| 90 | 92 |
| 91 bool PictureLayer::Update() { | 93 bool PictureLayer::Update() { |
| 92 update_source_frame_number_ = layer_tree_host()->source_frame_number(); | 94 update_source_frame_number_ = layer_tree_host()->source_frame_number(); |
| 93 bool updated = Layer::Update(); | 95 bool updated = Layer::Update(); |
| 94 | 96 |
| 95 gfx::Size layer_size = paint_properties().bounds; | 97 gfx::Size layer_size = paint_properties().bounds; |
| 96 | 98 |
| 97 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); | 99 SetBackgroundColorSimple(SafeOpaqueBackgroundColor()); |
| 98 recording_source_->SetRequiresClear(!contents_opaque() && | 100 SetRequiresClear(!contents_opaque() && |
| 99 !inputs_.client->FillsBoundsCompletely()); | 101 !inputs_.client->FillsBoundsCompletely()); |
| 100 | 102 |
| 101 TRACE_EVENT1("cc", "PictureLayer::Update", | 103 TRACE_EVENT1("cc", "PictureLayer::Update", |
| 102 "source_frame_number", | 104 "source_frame_number", |
| 103 layer_tree_host()->source_frame_number()); | 105 layer_tree_host()->source_frame_number()); |
| 104 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 106 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
| 105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 107 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
| 106 | 108 |
| 107 // UpdateAndExpandInvalidation will give us an invalidation that covers | 109 // UpdateAndExpandInvalidation will give us an invalidation that covers |
| 108 // anything not explicitly recorded in this frame. We give this region | 110 // 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 | 111 // to the impl side so that it drops tiles that may not have a recording |
| 110 // for them. | 112 // for them. |
| 111 DCHECK(inputs_.client); | 113 DCHECK(inputs_.client); |
| 112 updated |= recording_source_->UpdateAndExpandInvalidation( | 114 updated |= UpdateAndExpandInvalidation( |
| 113 inputs_.client, &last_updated_invalidation_, layer_size, | 115 &last_updated_invalidation_, layer_size, RecordingSource::RECORD_NORMALLY, |
| 114 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); | 116 &pl_data_, &clc_data_, &invalidation_); |
| 115 | 117 |
| 116 if (updated) { | 118 if (updated) { |
| 117 SetNeedsPushProperties(); | 119 SetNeedsPushProperties(); |
| 118 } else { | 120 } else { |
| 119 // If this invalidation did not affect the recording source, then it can be | 121 // If this invalidation did not affect the recording source, then it can be |
| 120 // cleared as an optimization. | 122 // cleared as an optimization. |
| 121 last_updated_invalidation_.Clear(); | 123 last_updated_invalidation_.Clear(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 return updated; | 126 return updated; |
| 125 } | 127 } |
| 126 | 128 |
| 127 void PictureLayer::SetIsMask(bool is_mask) { | 129 void PictureLayer::SetIsMask(bool is_mask) { |
| 128 is_mask_ = is_mask; | 130 is_mask_ = is_mask; |
| 129 } | 131 } |
| 130 | 132 |
| 131 sk_sp<SkPicture> PictureLayer::GetPicture() const { | 133 sk_sp<SkPicture> PictureLayer::GetPicture() const { |
| 132 // We could either flatten the RecordingSource into a single | 134 // 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 | 135 // 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. | 136 // picture. For now we just paint a fresh one to get consistent results. |
| 135 if (!DrawsContent()) | 137 if (!DrawsContent()) |
| 136 return nullptr; | 138 return nullptr; |
| 137 | 139 |
| 138 gfx::Size layer_size = bounds(); | 140 gfx::Size layer_size = bounds(); |
| 139 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); | |
| 140 Region recording_invalidation; | 141 Region recording_invalidation; |
| 141 recording_source->UpdateAndExpandInvalidation( | 142 InvalidationRegion invalidation_local; |
|
vmpstr
2016/07/19 23:43:22
I don't think you need the word "local".. lack of
Menglin
2016/07/20 21:25:22
Done.
| |
| 142 inputs_.client, &recording_invalidation, layer_size, | 143 PictureLayerData pl_data_local = PictureLayerData(); |
| 143 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); | 144 ContentLayerClientData clc_data_local = ContentLayerClientData(); |
| 144 | 145 UpdateAndExpandInvalidation(&recording_invalidation, layer_size, |
| 146 RecordingSource::RECORD_NORMALLY, &pl_data_local, | |
| 147 &clc_data_local, &invalidation_local); | |
| 148 std::unique_ptr<RecordingSource> recording_source( | |
|
vmpstr
2016/07/19 23:43:22
Same comment as above: Either create it on the sta
Menglin
2016/07/20 21:25:22
Done.
| |
| 149 new RecordingSource(pl_data_local, clc_data_local)); | |
| 145 scoped_refptr<RasterSource> raster_source = | 150 scoped_refptr<RasterSource> raster_source = |
| 146 recording_source->CreateRasterSource(false); | 151 recording_source->CreateRasterSource(false); |
| 147 | 152 |
| 148 return raster_source->GetFlattenedPicture(); | 153 return raster_source->GetFlattenedPicture(); |
| 149 } | 154 } |
| 150 | 155 |
| 151 bool PictureLayer::IsSuitableForGpuRasterization() const { | 156 bool PictureLayer::IsSuitableForGpuRasterization() const { |
| 152 return recording_source_->IsSuitableForGpuRasterization(); | 157 // The display list needs to be created (see: UpdateAndExpandInvalidation) |
| 158 // before checking for suitability. There are cases where an update will not | |
| 159 // create a display list (e.g., if the size is empty). We return true in these | |
| 160 // cases because the gpu suitability bit sticks false. | |
| 161 return !clc_data_.display_list || | |
| 162 clc_data_.display_list->IsSuitableForGpuRasterization(); | |
| 153 } | 163 } |
| 154 | 164 |
| 155 void PictureLayer::ClearClient() { | 165 void PictureLayer::ClearClient() { |
| 156 inputs_.client = nullptr; | 166 inputs_.client = nullptr; |
| 157 UpdateDrawsContent(HasDrawableContent()); | 167 UpdateDrawsContent(HasDrawableContent()); |
| 158 } | 168 } |
| 159 | 169 |
| 160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { | 170 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { |
| 161 if (inputs_.nearest_neighbor == nearest_neighbor) | 171 if (inputs_.nearest_neighbor == nearest_neighbor) |
| 162 return; | 172 return; |
| 163 | 173 |
| 164 inputs_.nearest_neighbor = nearest_neighbor; | 174 inputs_.nearest_neighbor = nearest_neighbor; |
| 165 SetNeedsCommit(); | 175 SetNeedsCommit(); |
| 166 } | 176 } |
| 167 | 177 |
| 168 bool PictureLayer::HasDrawableContent() const { | 178 bool PictureLayer::HasDrawableContent() const { |
| 169 return inputs_.client && Layer::HasDrawableContent(); | 179 return inputs_.client && Layer::HasDrawableContent(); |
| 170 } | 180 } |
| 171 | 181 |
| 172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | 182 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { |
| 173 proto->set_type(proto::LayerNode::PICTURE_LAYER); | 183 proto->set_type(proto::LayerNode::PICTURE_LAYER); |
| 174 } | 184 } |
| 175 | 185 |
| 176 void PictureLayer::LayerSpecificPropertiesToProto( | 186 void PictureLayer::LayerSpecificPropertiesToProto( |
| 177 proto::LayerProperties* proto) { | 187 proto::LayerProperties* proto) { |
| 178 Layer::LayerSpecificPropertiesToProto(proto); | 188 Layer::LayerSpecificPropertiesToProto(proto); |
| 179 DropRecordingSourceContentIfInvalid(); | 189 DropRecordingSourceContentIfInvalid(); |
| 180 | 190 |
| 181 proto::PictureLayerProperties* picture = proto->mutable_picture(); | 191 proto::PictureLayerProperties* picture = proto->mutable_picture(); |
| 182 recording_source_->ToProtobuf(picture->mutable_recording_source()); | 192 |
| 193 RectToProto(clc_data_.recorded_viewport, | |
| 194 picture->mutable_recorded_viewport()); | |
| 195 SizeToProto(pl_data_.size, picture->mutable_size()); | |
| 196 picture->set_slow_down_raster_scale_factor_for_debug( | |
| 197 pl_data_.slow_down_raster_scale_factor_for_debug); | |
| 198 picture->set_generate_discardable_images_metadata( | |
| 199 pl_data_.generate_discardable_images_metadata); | |
| 200 picture->set_requires_clear(pl_data_.requires_clear); | |
| 201 picture->set_is_solid_color(pl_data_.is_solid_color); | |
| 202 picture->set_clear_canvas_with_debug_color( | |
| 203 pl_data_.clear_canvas_with_debug_color); | |
| 204 picture->set_solid_color(static_cast<uint64_t>(pl_data_.solid_color)); | |
| 205 picture->set_background_color( | |
| 206 static_cast<uint64_t>(pl_data_.background_color)); | |
| 207 if (clc_data_.display_list) | |
| 208 clc_data_.display_list->ToProtobuf(picture->mutable_display_list()); | |
| 183 | 209 |
| 184 // Add all SkPicture items to the picture cache. | 210 // Add all SkPicture items to the picture cache. |
| 185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); | 211 const DisplayItemList* display_list = GetDisplayItemList(); |
| 186 if (display_list) { | 212 if (display_list) { |
| 187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { | 213 for (auto it = display_list->begin(); it != 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 pl_data_.reset(); |
| 214 recording_source_.reset(new RecordingSource); | 240 clc_data_.reset(); |
| 241 std::vector<uint32_t> used_engine_picture_ids; | |
| 215 | 242 |
| 216 std::vector<uint32_t> used_engine_picture_ids; | 243 DCHECK(layer_tree_host()->client_picture_cache()); |
| 217 recording_source_->FromProtobuf(picture.recording_source(), | 244 clc_data_.recorded_viewport = ProtoToRect(picture.recorded_viewport()); |
| 218 layer_tree_host()->client_picture_cache(), | 245 pl_data_.size = ProtoToSize(picture.size()); |
| 219 &used_engine_picture_ids); | 246 pl_data_.slow_down_raster_scale_factor_for_debug = |
| 247 picture.slow_down_raster_scale_factor_for_debug(); | |
| 248 pl_data_.generate_discardable_images_metadata = | |
| 249 picture.generate_discardable_images_metadata(); | |
| 250 pl_data_.requires_clear = picture.requires_clear(); | |
| 251 pl_data_.is_solid_color = picture.is_solid_color(); | |
| 252 pl_data_.clear_canvas_with_debug_color = | |
| 253 picture.clear_canvas_with_debug_color(); | |
| 254 pl_data_.solid_color = static_cast<SkColor>(picture.solid_color()); | |
| 255 pl_data_.background_color = static_cast<SkColor>(picture.background_color()); | |
| 256 | |
| 257 // This might not exist if the |clc_data_.display_list| of the serialized | |
| 258 // RecordingSource was null, which can happen if |Clear()| is | |
| 259 // called. | |
| 260 if (picture.has_display_list()) { | |
| 261 clc_data_.display_list = DisplayItemList::CreateFromProto( | |
| 262 picture.display_list(), layer_tree_host()->client_picture_cache(), | |
| 263 &used_engine_picture_ids); | |
| 264 FinishDisplayItemListUpdate(&pl_data_, &clc_data_); | |
| 265 } else { | |
| 266 clc_data_.display_list = nullptr; | |
| 267 } | |
| 220 | 268 |
| 221 // Inform picture cache about which SkPictures are now in use. | 269 // Inform picture cache about which SkPictures are now in use. |
| 222 for (uint32_t engine_picture_id : used_engine_picture_ids) | 270 for (uint32_t engine_picture_id : used_engine_picture_ids) |
| 223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); | 271 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); |
| 224 | 272 |
| 225 Region new_invalidation = RegionFromProto(picture.invalidation()); | 273 Region new_invalidation = RegionFromProto(picture.invalidation()); |
| 226 last_updated_invalidation_.Swap(&new_invalidation); | 274 last_updated_invalidation_.Swap(&new_invalidation); |
| 227 is_mask_ = picture.is_mask(); | 275 is_mask_ = picture.is_mask(); |
| 228 inputs_.nearest_neighbor = picture.nearest_neighbor(); | 276 inputs_.nearest_neighbor = picture.nearest_neighbor(); |
| 229 | 277 |
| 230 update_source_frame_number_ = picture.update_source_frame_number(); | 278 update_source_frame_number_ = picture.update_source_frame_number(); |
| 231 } | 279 } |
| 232 | 280 |
| 233 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 281 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 234 benchmark->RunOnLayer(this); | 282 benchmark->RunOnLayer(this); |
| 235 } | 283 } |
| 236 | 284 |
| 285 bool PictureLayer::UpdateAndExpandInvalidation( | |
| 286 Region* invalidation, | |
| 287 const gfx::Size& layer_size, | |
| 288 RecordingSource::RecordingMode recording_mode, | |
| 289 PictureLayerData* pl_data, | |
| 290 ContentLayerClientData* clc_data, | |
| 291 InvalidationRegion* invalidation_state) const { | |
| 292 bool updated = false; | |
| 293 | |
| 294 if (pl_data->size != layer_size) | |
| 295 pl_data->size = layer_size; | |
| 296 | |
| 297 invalidation_state->Swap(invalidation); | |
| 298 invalidation_state->Clear(); | |
| 299 | |
| 300 gfx::Rect new_recorded_viewport = inputs_.client->PaintableRegion(); | |
| 301 if (new_recorded_viewport != clc_data->recorded_viewport) { | |
| 302 UpdateInvalidationForNewViewport(clc_data->recorded_viewport, | |
| 303 new_recorded_viewport, invalidation); | |
| 304 clc_data->recorded_viewport = new_recorded_viewport; | |
| 305 updated = true; | |
| 306 } | |
| 307 | |
| 308 if (!updated && !invalidation->Intersects(clc_data->recorded_viewport)) | |
| 309 return false; | |
| 310 | |
| 311 if (invalidation->IsEmpty()) | |
| 312 return false; | |
| 313 | |
| 314 ContentLayerClient::PaintingControlSetting painting_control = | |
| 315 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; | |
| 316 | |
| 317 switch (recording_mode) { | |
| 318 case RecordingSource::RECORD_NORMALLY: | |
| 319 // Already setup for normal recording. | |
| 320 break; | |
| 321 case RecordingSource::RECORD_WITH_PAINTING_DISABLED: | |
| 322 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED; | |
| 323 break; | |
| 324 case RecordingSource::RECORD_WITH_CACHING_DISABLED: | |
| 325 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | |
| 326 break; | |
| 327 case RecordingSource::RECORD_WITH_CONSTRUCTION_DISABLED: | |
| 328 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; | |
| 329 break; | |
| 330 case RecordingSource::RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: | |
| 331 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; | |
| 332 break; | |
| 333 case RecordingSource::RECORD_WITH_SK_NULL_CANVAS: | |
| 334 case RecordingSource::RECORDING_MODE_COUNT: | |
| 335 NOTREACHED(); | |
| 336 } | |
| 337 | |
| 338 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able | |
| 339 // to slow down recording. | |
| 340 clc_data->display_list = | |
| 341 inputs_.client->PaintContentsToDisplayList(painting_control); | |
| 342 clc_data->painter_reported_memory_usage = | |
| 343 inputs_.client->GetApproximateUnsharedMemoryUsage(); | |
| 344 | |
| 345 FinishDisplayItemListUpdate(pl_data, clc_data); | |
| 346 | |
| 347 return true; | |
| 348 } | |
| 349 | |
| 350 void PictureLayer::SetEmptyBounds() { | |
| 351 pl_data_.size = gfx::Size(); | |
| 352 Clear(); | |
| 353 } | |
| 354 | |
| 355 void PictureLayer::SetSlowdownRasterScaleFactor(int factor) { | |
|
vmpstr
2016/07/19 23:43:22
As far as I can tell there's not a lot of places t
Menglin
2016/07/20 00:18:13
OK. I will check each one of them, and do the clea
Menglin
2016/07/20 21:25:22
For now I only removed SetSlowdownRasterScaleFacto
| |
| 356 pl_data_.slow_down_raster_scale_factor_for_debug = factor; | |
| 357 } | |
| 358 | |
| 359 void PictureLayer::SetGenerateDiscardableImagesMetadata( | |
| 360 bool generate_metadata) { | |
| 361 pl_data_.generate_discardable_images_metadata = generate_metadata; | |
| 362 } | |
| 363 | |
| 364 void PictureLayer::SetBackgroundColorSimple(SkColor background_color) { | |
| 365 pl_data_.background_color = background_color; | |
| 366 } | |
| 367 | |
| 368 void PictureLayer::SetRequiresClear(bool requires_clear) { | |
| 369 pl_data_.requires_clear = requires_clear; | |
| 370 } | |
| 371 | |
| 372 void PictureLayer::SetNeedsDisplayRectSimple(const gfx::Rect& layer_rect) { | |
| 373 if (!layer_rect.IsEmpty()) { | |
| 374 // Clamp invalidation to the layer bounds. | |
| 375 invalidation_.Union( | |
| 376 gfx::IntersectRects(layer_rect, gfx::Rect(pl_data_.size))); | |
| 377 } | |
| 378 } | |
| 379 | |
| 380 gfx::Size PictureLayer::GetSize() const { | |
| 381 return pl_data_.size; | |
| 382 } | |
| 383 | |
| 384 const DisplayItemList* PictureLayer::GetDisplayItemList() { | |
| 385 return clc_data_.display_list.get(); | |
| 386 } | |
| 387 | |
| 388 void PictureLayer::Clear() { | |
| 389 clc_data_.recorded_viewport = gfx::Rect(); | |
| 390 clc_data_.display_list = nullptr; | |
| 391 clc_data_.painter_reported_memory_usage = 0; | |
| 392 pl_data_.is_solid_color = false; | |
| 393 } | |
| 394 | |
| 237 void PictureLayer::DropRecordingSourceContentIfInvalid() { | 395 void PictureLayer::DropRecordingSourceContentIfInvalid() { |
| 238 int source_frame_number = layer_tree_host()->source_frame_number(); | 396 int source_frame_number = layer_tree_host()->source_frame_number(); |
| 239 gfx::Size recording_source_bounds = recording_source_->GetSize(); | 397 gfx::Size recording_source_bounds = GetSize(); |
| 240 | 398 |
| 241 gfx::Size layer_bounds = bounds(); | 399 gfx::Size layer_bounds = bounds(); |
| 242 if (paint_properties().source_frame_number == source_frame_number) | 400 if (paint_properties().source_frame_number == source_frame_number) |
| 243 layer_bounds = paint_properties().bounds; | 401 layer_bounds = paint_properties().bounds; |
| 244 | 402 |
| 245 // If update called, then recording source size must match bounds pushed to | 403 // If update called, then recording source size must match bounds pushed to |
| 246 // impl layer. | 404 // impl layer. |
| 247 DCHECK(update_source_frame_number_ != source_frame_number || | 405 DCHECK(update_source_frame_number_ != source_frame_number || |
| 248 layer_bounds == recording_source_bounds) | 406 layer_bounds == recording_source_bounds) |
| 249 << " bounds " << layer_bounds.ToString() << " recording source " | 407 << " bounds " << layer_bounds.ToString() << " recording source " |
| 250 << recording_source_bounds.ToString(); | 408 << recording_source_bounds.ToString(); |
| 251 | 409 |
| 252 if (update_source_frame_number_ != source_frame_number && | 410 if (update_source_frame_number_ != source_frame_number && |
| 253 recording_source_bounds != layer_bounds) { | 411 recording_source_bounds != layer_bounds) { |
| 254 // Update may not get called for the layer (if it's not in the viewport | 412 // 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 | 413 // for example), even though it has resized making the recording source no |
| 256 // longer valid. In this case just destroy the recording source. | 414 // longer valid. In this case just destroy the recording source. |
| 257 recording_source_->SetEmptyBounds(); | 415 SetEmptyBounds(); |
| 258 } | 416 } |
| 259 } | 417 } |
| 260 | 418 |
| 419 void PictureLayer::FinishDisplayItemListUpdate( | |
| 420 PictureLayerData* pl_data, | |
| 421 ContentLayerClientData* clc_data) const { | |
| 422 TRACE_EVENT0("cc", "PictureLayer::FinishDisplayItemListUpdate"); | |
| 423 DetermineIfSolidColor(pl_data, clc_data); | |
| 424 clc_data->display_list->EmitTraceSnapshot(); | |
| 425 if (pl_data->generate_discardable_images_metadata) | |
| 426 clc_data->display_list->GenerateDiscardableImagesMetadata(); | |
| 427 } | |
| 428 | |
| 429 void PictureLayer::DetermineIfSolidColor( | |
| 430 PictureLayerData* pl_data, | |
| 431 ContentLayerClientData* clc_data) const { | |
| 432 DCHECK(clc_data->display_list); | |
| 433 pl_data->is_solid_color = false; | |
| 434 pl_data->solid_color = SK_ColorTRANSPARENT; | |
| 435 | |
| 436 if (!clc_data->display_list->ShouldBeAnalyzedForSolidColor()) | |
| 437 return; | |
| 438 | |
| 439 TRACE_EVENT1("cc", "PictureLayer::DetermineIfSolidColor", "opcount", | |
| 440 clc_data->display_list->ApproximateOpCount()); | |
| 441 gfx::Size layer_size = pl_data->size; | |
| 442 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); | |
| 443 clc_data->display_list->Raster(&canvas, nullptr, gfx::Rect(), 1.f); | |
| 444 pl_data->is_solid_color = canvas.GetColorIfSolid(&pl_data->solid_color); | |
| 445 } | |
| 446 | |
| 447 void PictureLayer::UpdateInvalidationForNewViewport( | |
| 448 const gfx::Rect& old_recorded_viewport, | |
| 449 const gfx::Rect& new_recorded_viewport, | |
| 450 Region* invalidation) const { | |
| 451 // Invalidate newly-exposed and no-longer-exposed areas. | |
| 452 Region newly_exposed_region(new_recorded_viewport); | |
| 453 newly_exposed_region.Subtract(old_recorded_viewport); | |
| 454 invalidation->Union(newly_exposed_region); | |
| 455 | |
| 456 Region no_longer_exposed_region(old_recorded_viewport); | |
| 457 no_longer_exposed_region.Subtract(new_recorded_viewport); | |
| 458 invalidation->Union(no_longer_exposed_region); | |
| 459 } | |
| 460 | |
| 261 } // namespace cc | 461 } // namespace cc |
| OLD | NEW |