| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DropRecordingSourceContentIfInvalid(); | 58 DropRecordingSourceContentIfInvalid(); |
| 59 | 59 |
| 60 layer_impl->SetNearestNeighbor(nearest_neighbor_); | 60 layer_impl->SetNearestNeighbor(nearest_neighbor_); |
| 61 | 61 |
| 62 // Preserve lcd text settings from the current raster source. | 62 // Preserve lcd text settings from the current raster source. |
| 63 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); | 63 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); |
| 64 scoped_refptr<DisplayListRasterSource> raster_source = | 64 scoped_refptr<DisplayListRasterSource> raster_source = |
| 65 recording_source_->CreateRasterSource(can_use_lcd_text); | 65 recording_source_->CreateRasterSource(can_use_lcd_text); |
| 66 layer_impl->set_gpu_raster_max_texture_size( | 66 layer_impl->set_gpu_raster_max_texture_size( |
| 67 layer_tree_host()->device_viewport_size()); | 67 layer_tree_host()->device_viewport_size()); |
| 68 layer_impl->UpdateRasterSource(raster_source, invalidation_.region(), | 68 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, |
| 69 nullptr); | 69 nullptr); |
| 70 DCHECK(invalidation_.IsEmpty()); | 70 DCHECK(last_updated_invalidation_.IsEmpty()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 73 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 74 Layer::SetLayerTreeHost(host); | 74 Layer::SetLayerTreeHost(host); |
| 75 if (!host) | 75 if (!host) |
| 76 return; | 76 return; |
| 77 | 77 |
| 78 if (!recording_source_) | 78 if (!recording_source_) |
| 79 recording_source_.reset(new DisplayListRecordingSource); | 79 recording_source_.reset(new DisplayListRecordingSource); |
| 80 recording_source_->SetSlowdownRasterScaleFactor( | 80 recording_source_->SetSlowdownRasterScaleFactor( |
| 81 host->debug_state().slow_down_raster_scale_factor); | 81 host->debug_state().slow_down_raster_scale_factor); |
| 82 // If we need to enable image decode tasks, then we have to generate the | 82 // If we need to enable image decode tasks, then we have to generate the |
| 83 // discardable images metadata. | 83 // discardable images metadata. |
| 84 const LayerTreeSettings& settings = layer_tree_host()->settings(); | 84 const LayerTreeSettings& settings = layer_tree_host()->settings(); |
| 85 recording_source_->SetGenerateDiscardableImagesMetadata( | 85 recording_source_->SetGenerateDiscardableImagesMetadata( |
| 86 settings.image_decode_tasks_enabled); | 86 settings.image_decode_tasks_enabled); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 89 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
| 90 DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); | 90 DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); |
| 91 if (!layer_rect.IsEmpty()) { | 91 if (recording_source_) |
| 92 // Clamp invalidation to the layer bounds. | 92 recording_source_->SetNeedsDisplayRect(layer_rect); |
| 93 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); | |
| 94 } | |
| 95 Layer::SetNeedsDisplayRect(layer_rect); | 93 Layer::SetNeedsDisplayRect(layer_rect); |
| 96 } | 94 } |
| 97 | 95 |
| 98 bool PictureLayer::Update() { | 96 bool PictureLayer::Update() { |
| 99 update_source_frame_number_ = layer_tree_host()->source_frame_number(); | 97 update_source_frame_number_ = layer_tree_host()->source_frame_number(); |
| 100 bool updated = Layer::Update(); | 98 bool updated = Layer::Update(); |
| 101 | 99 |
| 102 gfx::Rect update_rect = visible_layer_rect(); | 100 gfx::Rect update_rect = visible_layer_rect(); |
| 103 gfx::Size layer_size = paint_properties().bounds; | 101 gfx::Size layer_size = paint_properties().bounds; |
| 104 | 102 |
| 105 if (last_updated_visible_layer_rect_ == update_rect && | |
| 106 recording_source_->GetSize() == layer_size && invalidation_.IsEmpty()) { | |
| 107 // Only early out if the visible content rect of this layer hasn't changed. | |
| 108 return updated; | |
| 109 } | |
| 110 | |
| 111 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); | 103 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); |
| 112 recording_source_->SetRequiresClear(!contents_opaque() && | 104 recording_source_->SetRequiresClear(!contents_opaque() && |
| 113 !client_->FillsBoundsCompletely()); | 105 !client_->FillsBoundsCompletely()); |
| 114 | 106 |
| 115 TRACE_EVENT1("cc", "PictureLayer::Update", | 107 TRACE_EVENT1("cc", "PictureLayer::Update", |
| 116 "source_frame_number", | 108 "source_frame_number", |
| 117 layer_tree_host()->source_frame_number()); | 109 layer_tree_host()->source_frame_number()); |
| 118 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 110 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
| 119 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 111 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
| 120 | 112 |
| 121 // UpdateAndExpandInvalidation will give us an invalidation that covers | 113 // UpdateAndExpandInvalidation will give us an invalidation that covers |
| 122 // anything not explicitly recorded in this frame. We give this region | 114 // anything not explicitly recorded in this frame. We give this region |
| 123 // 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 |
| 124 // for them. | 116 // for them. |
| 125 DCHECK(client_); | 117 DCHECK(client_); |
| 126 updated |= recording_source_->UpdateAndExpandInvalidation( | 118 updated |= recording_source_->UpdateAndExpandInvalidation( |
| 127 client_, invalidation_.region(), layer_size, update_rect, | 119 client_, &last_updated_invalidation_, layer_size, update_rect, |
| 128 update_source_frame_number_, DisplayListRecordingSource::RECORD_NORMALLY); | 120 update_source_frame_number_, DisplayListRecordingSource::RECORD_NORMALLY); |
| 129 last_updated_visible_layer_rect_ = visible_layer_rect(); | 121 last_updated_visible_layer_rect_ = visible_layer_rect(); |
| 130 | 122 |
| 131 if (updated) { | 123 if (updated) { |
| 132 SetNeedsPushProperties(); | 124 SetNeedsPushProperties(); |
| 133 } else { | 125 } else { |
| 134 // If this invalidation did not affect the recording source, then it can be | 126 // If this invalidation did not affect the recording source, then it can be |
| 135 // cleared as an optimization. | 127 // cleared as an optimization. |
| 136 invalidation_.Clear(); | 128 last_updated_invalidation_.Clear(); |
| 137 } | 129 } |
| 138 | 130 |
| 139 return updated; | 131 return updated; |
| 140 } | 132 } |
| 141 | 133 |
| 142 void PictureLayer::SetIsMask(bool is_mask) { | 134 void PictureLayer::SetIsMask(bool is_mask) { |
| 143 is_mask_ = is_mask; | 135 is_mask_ = is_mask; |
| 144 } | 136 } |
| 145 | 137 |
| 146 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { | 138 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 183 |
| 192 void PictureLayer::LayerSpecificPropertiesToProto( | 184 void PictureLayer::LayerSpecificPropertiesToProto( |
| 193 proto::LayerProperties* proto) { | 185 proto::LayerProperties* proto) { |
| 194 Layer::LayerSpecificPropertiesToProto(proto); | 186 Layer::LayerSpecificPropertiesToProto(proto); |
| 195 DropRecordingSourceContentIfInvalid(); | 187 DropRecordingSourceContentIfInvalid(); |
| 196 | 188 |
| 197 proto::PictureLayerProperties* picture = proto->mutable_picture(); | 189 proto::PictureLayerProperties* picture = proto->mutable_picture(); |
| 198 recording_source_->ToProtobuf( | 190 recording_source_->ToProtobuf( |
| 199 picture->mutable_recording_source(), | 191 picture->mutable_recording_source(), |
| 200 layer_tree_host()->image_serialization_processor()); | 192 layer_tree_host()->image_serialization_processor()); |
| 201 RegionToProto(*invalidation_.region(), picture->mutable_invalidation()); | 193 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); |
| 202 RectToProto(last_updated_visible_layer_rect_, | 194 RectToProto(last_updated_visible_layer_rect_, |
| 203 picture->mutable_last_updated_visible_layer_rect()); | 195 picture->mutable_last_updated_visible_layer_rect()); |
| 204 picture->set_is_mask(is_mask_); | 196 picture->set_is_mask(is_mask_); |
| 205 picture->set_nearest_neighbor(nearest_neighbor_); | 197 picture->set_nearest_neighbor(nearest_neighbor_); |
| 206 | 198 |
| 207 picture->set_update_source_frame_number(update_source_frame_number_); | 199 picture->set_update_source_frame_number(update_source_frame_number_); |
| 208 | 200 |
| 209 invalidation_.Clear(); | 201 last_updated_invalidation_.Clear(); |
| 210 } | 202 } |
| 211 | 203 |
| 212 void PictureLayer::FromLayerSpecificPropertiesProto( | 204 void PictureLayer::FromLayerSpecificPropertiesProto( |
| 213 const proto::LayerProperties& proto) { | 205 const proto::LayerProperties& proto) { |
| 214 Layer::FromLayerSpecificPropertiesProto(proto); | 206 Layer::FromLayerSpecificPropertiesProto(proto); |
| 215 const proto::PictureLayerProperties& picture = proto.picture(); | 207 const proto::PictureLayerProperties& picture = proto.picture(); |
| 216 // If this is a new layer, ensure it has a recording source. During layer | 208 // If this is a new layer, ensure it has a recording source. During layer |
| 217 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but | 209 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but |
| 218 // instead the member is set directly, so it needs to be set here explicitly. | 210 // instead the member is set directly, so it needs to be set here explicitly. |
| 219 if (!recording_source_) | 211 if (!recording_source_) |
| 220 recording_source_.reset(new DisplayListRecordingSource); | 212 recording_source_.reset(new DisplayListRecordingSource); |
| 221 | 213 |
| 222 recording_source_->FromProtobuf( | 214 recording_source_->FromProtobuf( |
| 223 picture.recording_source(), | 215 picture.recording_source(), |
| 224 layer_tree_host()->image_serialization_processor()); | 216 layer_tree_host()->image_serialization_processor()); |
| 225 | 217 |
| 226 Region new_invalidation = RegionFromProto(picture.invalidation()); | 218 Region new_invalidation = RegionFromProto(picture.invalidation()); |
| 227 invalidation_.Swap(&new_invalidation); | 219 last_updated_invalidation_.Swap(&new_invalidation); |
| 228 last_updated_visible_layer_rect_ = | 220 last_updated_visible_layer_rect_ = |
| 229 ProtoToRect(picture.last_updated_visible_layer_rect()); | 221 ProtoToRect(picture.last_updated_visible_layer_rect()); |
| 230 is_mask_ = picture.is_mask(); | 222 is_mask_ = picture.is_mask(); |
| 231 nearest_neighbor_ = picture.nearest_neighbor(); | 223 nearest_neighbor_ = picture.nearest_neighbor(); |
| 232 | 224 |
| 233 update_source_frame_number_ = picture.update_source_frame_number(); | 225 update_source_frame_number_ = picture.update_source_frame_number(); |
| 234 } | 226 } |
| 235 | 227 |
| 236 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 228 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 237 benchmark->RunOnLayer(this); | 229 benchmark->RunOnLayer(this); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 255 if (update_source_frame_number_ != source_frame_number && | 247 if (update_source_frame_number_ != source_frame_number && |
| 256 recording_source_bounds != layer_bounds) { | 248 recording_source_bounds != layer_bounds) { |
| 257 // Update may not get called for the layer (if it's not in the viewport | 249 // Update may not get called for the layer (if it's not in the viewport |
| 258 // for example), even though it has resized making the recording source no | 250 // for example), even though it has resized making the recording source no |
| 259 // longer valid. In this case just destroy the recording source. | 251 // longer valid. In this case just destroy the recording source. |
| 260 recording_source_->SetEmptyBounds(); | 252 recording_source_->SetEmptyBounds(); |
| 261 } | 253 } |
| 262 } | 254 } |
| 263 | 255 |
| 264 } // namespace cc | 256 } // namespace cc |
| OLD | NEW |