| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/playback/recording_source.h" | 5 #include "cc/playback/recording_source.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/numerics/safe_math.h" | 11 #include "base/numerics/safe_math.h" |
| 12 #include "cc/base/region.h" | 12 #include "cc/base/region.h" |
| 13 #include "cc/layers/content_layer_client.h" | 13 #include "cc/layers/content_layer_client.h" |
| 14 #include "cc/playback/display_item_list.h" | 14 #include "cc/playback/display_item_list.h" |
| 15 #include "cc/playback/raster_source.h" | 15 #include "cc/playback/raster_source.h" |
| 16 #include "cc/proto/gfx_conversions.h" | 16 #include "cc/proto/gfx_conversions.h" |
| 17 #include "cc/proto/picture_cache.h" |
| 17 #include "cc/proto/recording_source.pb.h" | 18 #include "cc/proto/recording_source.pb.h" |
| 18 #include "skia/ext/analysis_canvas.h" | 19 #include "skia/ext/analysis_canvas.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 #ifdef NDEBUG | 23 #ifdef NDEBUG |
| 23 const bool kDefaultClearCanvasSetting = false; | 24 const bool kDefaultClearCanvasSetting = false; |
| 24 #else | 25 #else |
| 25 const bool kDefaultClearCanvasSetting = true; | 26 const bool kDefaultClearCanvasSetting = true; |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 namespace cc { | 31 namespace cc { |
| 31 class ImageSerializationProcessor; | |
| 32 | 32 |
| 33 RecordingSource::RecordingSource() | 33 RecordingSource::RecordingSource() |
| 34 : slow_down_raster_scale_factor_for_debug_(0), | 34 : slow_down_raster_scale_factor_for_debug_(0), |
| 35 generate_discardable_images_metadata_(false), | 35 generate_discardable_images_metadata_(false), |
| 36 requires_clear_(false), | 36 requires_clear_(false), |
| 37 is_solid_color_(false), | 37 is_solid_color_(false), |
| 38 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), | 38 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), |
| 39 solid_color_(SK_ColorTRANSPARENT), | 39 solid_color_(SK_ColorTRANSPARENT), |
| 40 background_color_(SK_ColorTRANSPARENT), | 40 background_color_(SK_ColorTRANSPARENT), |
| 41 painter_reported_memory_usage_(0) {} | 41 painter_reported_memory_usage_(0), |
| 42 engine_picture_cache_(nullptr), |
| 43 client_picture_cache_(nullptr) {} |
| 42 | 44 |
| 43 RecordingSource::~RecordingSource() {} | 45 RecordingSource::~RecordingSource() { |
| 46 Clear(); |
| 47 } |
| 44 | 48 |
| 45 void RecordingSource::ToProtobuf( | 49 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const { |
| 46 proto::RecordingSource* proto, | |
| 47 ImageSerializationProcessor* image_serialization_processor) const { | |
| 48 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport()); | 50 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport()); |
| 49 SizeToProto(size_, proto->mutable_size()); | 51 SizeToProto(size_, proto->mutable_size()); |
| 50 proto->set_slow_down_raster_scale_factor_for_debug( | 52 proto->set_slow_down_raster_scale_factor_for_debug( |
| 51 slow_down_raster_scale_factor_for_debug_); | 53 slow_down_raster_scale_factor_for_debug_); |
| 52 proto->set_generate_discardable_images_metadata( | 54 proto->set_generate_discardable_images_metadata( |
| 53 generate_discardable_images_metadata_); | 55 generate_discardable_images_metadata_); |
| 54 proto->set_requires_clear(requires_clear_); | 56 proto->set_requires_clear(requires_clear_); |
| 55 proto->set_is_solid_color(is_solid_color_); | 57 proto->set_is_solid_color(is_solid_color_); |
| 56 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_); | 58 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_); |
| 57 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); | 59 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); |
| 58 proto->set_background_color(static_cast<uint64_t>(background_color_)); | 60 proto->set_background_color(static_cast<uint64_t>(background_color_)); |
| 59 if (display_list_) { | 61 if (display_list_) |
| 60 display_list_->ToProtobuf(proto->mutable_display_list(), | 62 display_list_->ToProtobuf(proto->mutable_display_list()); |
| 61 image_serialization_processor); | |
| 62 } | |
| 63 } | 63 } |
| 64 | 64 |
| 65 void RecordingSource::FromProtobuf( | 65 void RecordingSource::FromProtobuf(const proto::RecordingSource& proto) { |
| 66 const proto::RecordingSource& proto, | 66 DCHECK(client_picture_cache_); |
| 67 ImageSerializationProcessor* image_serialization_processor) { | |
| 68 recorded_viewport_ = ProtoToRect(proto.recorded_viewport()); | 67 recorded_viewport_ = ProtoToRect(proto.recorded_viewport()); |
| 69 size_ = ProtoToSize(proto.size()); | 68 size_ = ProtoToSize(proto.size()); |
| 70 slow_down_raster_scale_factor_for_debug_ = | 69 slow_down_raster_scale_factor_for_debug_ = |
| 71 proto.slow_down_raster_scale_factor_for_debug(); | 70 proto.slow_down_raster_scale_factor_for_debug(); |
| 72 generate_discardable_images_metadata_ = | 71 generate_discardable_images_metadata_ = |
| 73 proto.generate_discardable_images_metadata(); | 72 proto.generate_discardable_images_metadata(); |
| 74 requires_clear_ = proto.requires_clear(); | 73 requires_clear_ = proto.requires_clear(); |
| 75 is_solid_color_ = proto.is_solid_color(); | 74 is_solid_color_ = proto.is_solid_color(); |
| 76 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); | 75 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); |
| 77 solid_color_ = static_cast<SkColor>(proto.solid_color()); | 76 solid_color_ = static_cast<SkColor>(proto.solid_color()); |
| 78 background_color_ = static_cast<SkColor>(proto.background_color()); | 77 background_color_ = static_cast<SkColor>(proto.background_color()); |
| 79 | 78 |
| 80 // This might not exist if the |display_list_| of the serialized | 79 // This might not exist if the |display_list_| of the serialized |
| 81 // RecordingSource was null, wich can happen if |Clear()| is | 80 // RecordingSource was null, wich can happen if |Clear()| is |
| 82 // called. | 81 // called. Whenever the |display_list_| is updated, first unregister the |
| 82 // current content, and then register the new content directly afterwards. |
| 83 MarkForUnregistrationClient(); |
| 84 display_list_ = nullptr; |
| 83 if (proto.has_display_list()) { | 85 if (proto.has_display_list()) { |
| 84 display_list_ = DisplayItemList::CreateFromProto( | 86 display_list_ = DisplayItemList::CreateFromProto(proto.display_list(), |
| 85 proto.display_list(), image_serialization_processor); | 87 client_picture_cache_); |
| 86 FinishDisplayItemListUpdate(); | 88 FinishDisplayItemListUpdate(); |
| 87 } else { | |
| 88 display_list_ = nullptr; | |
| 89 } | 89 } |
| 90 MarkForRegistrationClient(); |
| 91 } |
| 92 |
| 93 void RecordingSource::MarkForRegistrationEngine() { |
| 94 if (display_list_ && engine_picture_cache_) |
| 95 display_list_->MarkForRegistrationEngine(engine_picture_cache_); |
| 96 } |
| 97 |
| 98 void RecordingSource::MarkForUnregistrationEngine() { |
| 99 if (display_list_ && engine_picture_cache_) |
| 100 display_list_->MarkForUnregistrationEngine(engine_picture_cache_); |
| 101 } |
| 102 |
| 103 void RecordingSource::MarkForRegistrationClient() { |
| 104 if (display_list_ && client_picture_cache_) |
| 105 display_list_->MarkForRegistrationClient(client_picture_cache_); |
| 106 } |
| 107 |
| 108 void RecordingSource::MarkForUnregistrationClient() { |
| 109 if (display_list_ && client_picture_cache_) |
| 110 display_list_->MarkForUnregistrationClient(client_picture_cache_); |
| 90 } | 111 } |
| 91 | 112 |
| 92 void RecordingSource::UpdateInvalidationForNewViewport( | 113 void RecordingSource::UpdateInvalidationForNewViewport( |
| 93 const gfx::Rect& old_recorded_viewport, | 114 const gfx::Rect& old_recorded_viewport, |
| 94 const gfx::Rect& new_recorded_viewport, | 115 const gfx::Rect& new_recorded_viewport, |
| 95 Region* invalidation) { | 116 Region* invalidation) { |
| 96 // Invalidate newly-exposed and no-longer-exposed areas. | 117 // Invalidate newly-exposed and no-longer-exposed areas. |
| 97 Region newly_exposed_region(new_recorded_viewport); | 118 Region newly_exposed_region(new_recorded_viewport); |
| 98 newly_exposed_region.Subtract(old_recorded_viewport); | 119 newly_exposed_region.Subtract(old_recorded_viewport); |
| 99 invalidation->Union(newly_exposed_region); | 120 invalidation->Union(newly_exposed_region); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 display_list_->GenerateDiscardableImagesMetadata(); | 132 display_list_->GenerateDiscardableImagesMetadata(); |
| 112 } | 133 } |
| 113 | 134 |
| 114 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 135 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
| 115 if (!layer_rect.IsEmpty()) { | 136 if (!layer_rect.IsEmpty()) { |
| 116 // Clamp invalidation to the layer bounds. | 137 // Clamp invalidation to the layer bounds. |
| 117 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); | 138 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); |
| 118 } | 139 } |
| 119 } | 140 } |
| 120 | 141 |
| 142 void RecordingSource::SetEnginePictureCache( |
| 143 EnginePictureCache* engine_picture_cache) { |
| 144 if (engine_picture_cache_) |
| 145 MarkForUnregistrationEngine(); |
| 146 engine_picture_cache_ = engine_picture_cache; |
| 147 if (engine_picture_cache_) |
| 148 MarkForRegistrationEngine(); |
| 149 } |
| 150 |
| 151 void RecordingSource::SetClientPictureCache( |
| 152 ClientPictureCache* client_picture_cache) { |
| 153 if (client_picture_cache_) |
| 154 MarkForUnregistrationClient(); |
| 155 client_picture_cache_ = client_picture_cache; |
| 156 if (client_picture_cache_) |
| 157 MarkForRegistrationClient(); |
| 158 } |
| 159 |
| 121 bool RecordingSource::UpdateAndExpandInvalidation( | 160 bool RecordingSource::UpdateAndExpandInvalidation( |
| 122 ContentLayerClient* painter, | 161 ContentLayerClient* painter, |
| 123 Region* invalidation, | 162 Region* invalidation, |
| 124 const gfx::Size& layer_size, | 163 const gfx::Size& layer_size, |
| 125 int frame_number, | 164 int frame_number, |
| 126 RecordingMode recording_mode) { | 165 RecordingMode recording_mode) { |
| 127 bool updated = false; | 166 bool updated = false; |
| 128 | 167 |
| 129 if (size_ != layer_size) | 168 if (size_ != layer_size) |
| 130 size_ = layer_size; | 169 size_ = layer_size; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: | 204 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: |
| 166 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; | 205 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; |
| 167 break; | 206 break; |
| 168 case RECORD_WITH_SK_NULL_CANVAS: | 207 case RECORD_WITH_SK_NULL_CANVAS: |
| 169 case RECORDING_MODE_COUNT: | 208 case RECORDING_MODE_COUNT: |
| 170 NOTREACHED(); | 209 NOTREACHED(); |
| 171 } | 210 } |
| 172 | 211 |
| 173 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able | 212 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able |
| 174 // to slow down recording. | 213 // to slow down recording. |
| 214 // Whenever the |display_list_| is updated, first unregister the |
| 215 // current content, and then register the new content directly afterwards. |
| 216 MarkForUnregistrationEngine(); |
| 175 display_list_ = painter->PaintContentsToDisplayList(painting_control); | 217 display_list_ = painter->PaintContentsToDisplayList(painting_control); |
| 218 MarkForRegistrationEngine(); |
| 219 |
| 176 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage(); | 220 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage(); |
| 177 | 221 |
| 178 FinishDisplayItemListUpdate(); | 222 FinishDisplayItemListUpdate(); |
| 179 | 223 |
| 180 return true; | 224 return true; |
| 181 } | 225 } |
| 182 | 226 |
| 183 gfx::Size RecordingSource::GetSize() const { | 227 gfx::Size RecordingSource::GetSize() const { |
| 184 return size_; | 228 return size_; |
| 185 } | 229 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 274 |
| 231 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", | 275 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", |
| 232 display_list_->ApproximateOpCount()); | 276 display_list_->ApproximateOpCount()); |
| 233 gfx::Size layer_size = GetSize(); | 277 gfx::Size layer_size = GetSize(); |
| 234 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); | 278 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); |
| 235 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); | 279 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); |
| 236 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | 280 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); |
| 237 } | 281 } |
| 238 | 282 |
| 239 void RecordingSource::Clear() { | 283 void RecordingSource::Clear() { |
| 284 // Depending on whether this code is being run on either the engine or client |
| 285 // side, the picture cache needs to be informed that the SkPicture |
| 286 MarkForUnregistrationEngine(); |
| 287 MarkForUnregistrationClient(); |
| 240 recorded_viewport_ = gfx::Rect(); | 288 recorded_viewport_ = gfx::Rect(); |
| 241 display_list_ = nullptr; | 289 display_list_ = nullptr; |
| 242 painter_reported_memory_usage_ = 0; | 290 painter_reported_memory_usage_ = 0; |
| 243 is_solid_color_ = false; | 291 is_solid_color_ = false; |
| 244 } | 292 } |
| 245 | 293 |
| 246 } // namespace cc | 294 } // namespace cc |
| OLD | NEW |