Chromium Code Reviews| 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 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 namespace cc { | 30 namespace cc { |
| 31 | 31 |
| 32 RecordingSource::RecordingSource() | 32 RecordingSource::RecordingSource() |
| 33 : slow_down_raster_scale_factor_for_debug_(0), | 33 : slow_down_raster_scale_factor_for_debug_(0), |
| 34 generate_discardable_images_metadata_(false), | 34 generate_discardable_images_metadata_(false), |
| 35 requires_clear_(false), | 35 requires_clear_(false), |
| 36 is_solid_color_(false), | 36 is_solid_color_(false), |
| 37 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), | 37 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), |
| 38 solid_color_(SK_ColorTRANSPARENT), | 38 solid_color_(SK_ColorTRANSPARENT), |
| 39 background_color_(SK_ColorTRANSPARENT), | 39 background_color_(SK_ColorTRANSPARENT) {} |
| 40 painter_reported_memory_usage_(0) {} | |
| 41 | 40 |
| 42 RecordingSource::~RecordingSource() {} | 41 RecordingSource::~RecordingSource() {} |
| 43 | 42 |
| 44 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const { | 43 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const { |
| 45 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport()); | |
| 46 SizeToProto(size_, proto->mutable_size()); | 44 SizeToProto(size_, proto->mutable_size()); |
| 47 proto->set_slow_down_raster_scale_factor_for_debug( | 45 proto->set_slow_down_raster_scale_factor_for_debug( |
| 48 slow_down_raster_scale_factor_for_debug_); | 46 slow_down_raster_scale_factor_for_debug_); |
| 49 proto->set_generate_discardable_images_metadata( | 47 proto->set_generate_discardable_images_metadata( |
| 50 generate_discardable_images_metadata_); | 48 generate_discardable_images_metadata_); |
| 51 proto->set_requires_clear(requires_clear_); | 49 proto->set_requires_clear(requires_clear_); |
| 52 proto->set_is_solid_color(is_solid_color_); | 50 proto->set_is_solid_color(is_solid_color_); |
| 53 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_); | 51 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_); |
| 54 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); | 52 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); |
| 55 proto->set_background_color(static_cast<uint64_t>(background_color_)); | 53 proto->set_background_color(static_cast<uint64_t>(background_color_)); |
| 56 if (display_list_) | |
| 57 display_list_->ToProtobuf(proto->mutable_display_list()); | |
| 58 } | 54 } |
| 59 | 55 |
| 60 void RecordingSource::FromProtobuf( | 56 void RecordingSource::FromProtobuf( |
| 61 const proto::RecordingSource& proto, | 57 const proto::RecordingSource& proto, |
| 62 ClientPictureCache* client_picture_cache, | 58 const scoped_refptr<DisplayItemList>& display_list) { |
| 63 std::vector<uint32_t>* used_engine_picture_ids) { | |
| 64 DCHECK(client_picture_cache); | |
| 65 recorded_viewport_ = ProtoToRect(proto.recorded_viewport()); | |
| 66 size_ = ProtoToSize(proto.size()); | 59 size_ = ProtoToSize(proto.size()); |
| 67 slow_down_raster_scale_factor_for_debug_ = | 60 slow_down_raster_scale_factor_for_debug_ = |
| 68 proto.slow_down_raster_scale_factor_for_debug(); | 61 proto.slow_down_raster_scale_factor_for_debug(); |
| 69 generate_discardable_images_metadata_ = | 62 generate_discardable_images_metadata_ = |
| 70 proto.generate_discardable_images_metadata(); | 63 proto.generate_discardable_images_metadata(); |
| 71 requires_clear_ = proto.requires_clear(); | 64 requires_clear_ = proto.requires_clear(); |
| 72 is_solid_color_ = proto.is_solid_color(); | 65 is_solid_color_ = proto.is_solid_color(); |
| 73 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); | 66 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); |
| 74 solid_color_ = static_cast<SkColor>(proto.solid_color()); | 67 solid_color_ = static_cast<SkColor>(proto.solid_color()); |
| 75 background_color_ = static_cast<SkColor>(proto.background_color()); | 68 background_color_ = static_cast<SkColor>(proto.background_color()); |
| 76 | 69 |
| 77 // This might not exist if the |display_list_| of the serialized | 70 display_list_ = display_list; |
| 78 // RecordingSource was null, wich can happen if |Clear()| is | 71 if (display_list_) |
| 79 // called. | |
| 80 if (proto.has_display_list()) { | |
| 81 display_list_ = DisplayItemList::CreateFromProto( | |
| 82 proto.display_list(), client_picture_cache, used_engine_picture_ids); | |
| 83 FinishDisplayItemListUpdate(); | 72 FinishDisplayItemListUpdate(); |
| 84 } else { | |
| 85 display_list_ = nullptr; | |
| 86 } | |
| 87 } | 73 } |
| 88 | 74 |
| 89 void RecordingSource::UpdateInvalidationForNewViewport( | 75 void RecordingSource::UpdateInvalidationForNewViewport( |
| 90 const gfx::Rect& old_recorded_viewport, | 76 const gfx::Rect& old_recorded_viewport, |
| 91 const gfx::Rect& new_recorded_viewport, | 77 const gfx::Rect& new_recorded_viewport, |
| 92 Region* invalidation) { | 78 Region* invalidation) { |
| 93 // Invalidate newly-exposed and no-longer-exposed areas. | 79 // Invalidate newly-exposed and no-longer-exposed areas. |
| 94 Region newly_exposed_region(new_recorded_viewport); | 80 Region newly_exposed_region(new_recorded_viewport); |
| 95 newly_exposed_region.Subtract(old_recorded_viewport); | 81 newly_exposed_region.Subtract(old_recorded_viewport); |
| 96 invalidation->Union(newly_exposed_region); | 82 invalidation->Union(newly_exposed_region); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 109 } | 95 } |
| 110 | 96 |
| 111 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 97 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
| 112 if (!layer_rect.IsEmpty()) { | 98 if (!layer_rect.IsEmpty()) { |
| 113 // Clamp invalidation to the layer bounds. | 99 // Clamp invalidation to the layer bounds. |
| 114 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); | 100 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); |
| 115 } | 101 } |
| 116 } | 102 } |
| 117 | 103 |
| 118 bool RecordingSource::UpdateAndExpandInvalidation( | 104 bool RecordingSource::UpdateAndExpandInvalidation( |
| 119 ContentLayerClient* painter, | 105 ContentLayerClient* painter, |
|
Khushal
2016/08/02 20:20:36
Not used here anymore?
Menglin
2016/08/02 21:04:26
Done.
| |
| 120 Region* invalidation, | 106 Region* invalidation, |
| 121 const gfx::Size& layer_size, | 107 const gfx::Size& layer_size, |
| 122 int frame_number, | 108 const gfx::Rect& new_recorded_viewport) { |
| 123 RecordingMode recording_mode) { | |
| 124 bool updated = false; | 109 bool updated = false; |
| 125 | 110 |
| 126 if (size_ != layer_size) | 111 if (size_ != layer_size) |
| 127 size_ = layer_size; | 112 size_ = layer_size; |
| 128 | 113 |
| 129 invalidation_.Swap(invalidation); | 114 invalidation_.Swap(invalidation); |
| 130 invalidation_.Clear(); | 115 invalidation_.Clear(); |
| 131 | 116 |
| 132 gfx::Rect new_recorded_viewport = painter->PaintableRegion(); | |
| 133 if (new_recorded_viewport != recorded_viewport_) { | 117 if (new_recorded_viewport != recorded_viewport_) { |
| 134 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport, | 118 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport, |
| 135 invalidation); | 119 invalidation); |
| 136 recorded_viewport_ = new_recorded_viewport; | 120 recorded_viewport_ = new_recorded_viewport; |
| 137 updated = true; | 121 updated = true; |
| 138 } | 122 } |
| 139 | 123 |
| 140 if (!updated && !invalidation->Intersects(recorded_viewport_)) | 124 if (!updated && !invalidation->Intersects(recorded_viewport_)) |
| 141 return false; | 125 return false; |
| 142 | 126 |
| 143 if (invalidation->IsEmpty()) | 127 if (invalidation->IsEmpty()) |
| 144 return false; | 128 return false; |
| 145 | 129 |
| 146 ContentLayerClient::PaintingControlSetting painting_control = | |
| 147 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; | |
| 148 | |
| 149 switch (recording_mode) { | |
| 150 case RECORD_NORMALLY: | |
| 151 // Already setup for normal recording. | |
| 152 break; | |
| 153 case RECORD_WITH_PAINTING_DISABLED: | |
| 154 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED; | |
| 155 break; | |
| 156 case RECORD_WITH_CACHING_DISABLED: | |
| 157 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | |
| 158 break; | |
| 159 case RECORD_WITH_CONSTRUCTION_DISABLED: | |
| 160 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; | |
| 161 break; | |
| 162 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: | |
| 163 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; | |
| 164 break; | |
| 165 case RECORD_WITH_SK_NULL_CANVAS: | |
| 166 case RECORDING_MODE_COUNT: | |
| 167 NOTREACHED(); | |
| 168 } | |
| 169 | |
| 170 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able | |
| 171 // to slow down recording. | |
| 172 display_list_ = painter->PaintContentsToDisplayList(painting_control); | |
| 173 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage(); | |
| 174 | |
| 175 FinishDisplayItemListUpdate(); | |
| 176 | |
| 177 return true; | 130 return true; |
| 178 } | 131 } |
| 179 | 132 |
| 133 void RecordingSource::UpdateDisplayItemList( | |
| 134 const scoped_refptr<DisplayItemList>& display_list, | |
| 135 const size_t& painter_reported_memory_usage) { | |
| 136 display_list_ = display_list; | |
| 137 painter_reported_memory_usage_ = painter_reported_memory_usage; | |
| 138 | |
| 139 FinishDisplayItemListUpdate(); | |
| 140 } | |
| 141 | |
| 180 gfx::Size RecordingSource::GetSize() const { | 142 gfx::Size RecordingSource::GetSize() const { |
| 181 return size_; | 143 return size_; |
| 182 } | 144 } |
| 183 | 145 |
| 184 void RecordingSource::SetEmptyBounds() { | 146 void RecordingSource::SetEmptyBounds() { |
| 185 size_ = gfx::Size(); | 147 size_ = gfx::Size(); |
| 186 Clear(); | 148 is_solid_color_ = false; |
| 149 | |
| 150 recorded_viewport_ = gfx::Rect(); | |
| 151 display_list_ = nullptr; | |
| 152 painter_reported_memory_usage_ = 0; | |
| 187 } | 153 } |
| 188 | 154 |
| 189 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) { | 155 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) { |
| 190 slow_down_raster_scale_factor_for_debug_ = factor; | 156 slow_down_raster_scale_factor_for_debug_ = factor; |
| 191 } | 157 } |
| 192 | 158 |
| 193 void RecordingSource::SetGenerateDiscardableImagesMetadata( | 159 void RecordingSource::SetGenerateDiscardableImagesMetadata( |
| 194 bool generate_metadata) { | 160 bool generate_metadata) { |
| 195 generate_discardable_images_metadata_ = generate_metadata; | 161 generate_discardable_images_metadata_ = generate_metadata; |
| 196 } | 162 } |
| 197 | 163 |
| 198 void RecordingSource::SetBackgroundColor(SkColor background_color) { | 164 void RecordingSource::SetBackgroundColor(SkColor background_color) { |
| 199 background_color_ = background_color; | 165 background_color_ = background_color; |
| 200 } | 166 } |
| 201 | 167 |
| 202 void RecordingSource::SetRequiresClear(bool requires_clear) { | 168 void RecordingSource::SetRequiresClear(bool requires_clear) { |
| 203 requires_clear_ = requires_clear; | 169 requires_clear_ = requires_clear; |
| 204 } | 170 } |
| 205 | 171 |
| 206 bool RecordingSource::IsSuitableForGpuRasterization() const { | |
| 207 // The display list needs to be created (see: UpdateAndExpandInvalidation) | |
| 208 // before checking for suitability. There are cases where an update will not | |
| 209 // create a display list (e.g., if the size is empty). We return true in these | |
| 210 // cases because the gpu suitability bit sticks false. | |
| 211 return !display_list_ || display_list_->IsSuitableForGpuRasterization(); | |
| 212 } | |
| 213 | |
| 214 const DisplayItemList* RecordingSource::GetDisplayItemList() { | 172 const DisplayItemList* RecordingSource::GetDisplayItemList() { |
| 215 return display_list_.get(); | 173 return display_list_.get(); |
| 216 } | 174 } |
| 217 | 175 |
| 218 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource( | 176 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource( |
| 219 bool can_use_lcd_text) const { | 177 bool can_use_lcd_text) const { |
| 220 return scoped_refptr<RasterSource>( | 178 return scoped_refptr<RasterSource>( |
| 221 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text)); | 179 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text)); |
| 222 } | 180 } |
| 223 | 181 |
| 224 void RecordingSource::DetermineIfSolidColor() { | 182 void RecordingSource::DetermineIfSolidColor() { |
| 225 DCHECK(display_list_); | 183 DCHECK(display_list_); |
| 226 is_solid_color_ = false; | 184 is_solid_color_ = false; |
| 227 solid_color_ = SK_ColorTRANSPARENT; | 185 solid_color_ = SK_ColorTRANSPARENT; |
| 228 | 186 |
| 229 if (!display_list_->ShouldBeAnalyzedForSolidColor()) | 187 if (!display_list_->ShouldBeAnalyzedForSolidColor()) |
| 230 return; | 188 return; |
| 231 | 189 |
| 232 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", | 190 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", |
| 233 display_list_->ApproximateOpCount()); | 191 display_list_->ApproximateOpCount()); |
| 234 gfx::Size layer_size = GetSize(); | 192 gfx::Size layer_size = GetSize(); |
| 235 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); | 193 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); |
| 236 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); | 194 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); |
| 237 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | 195 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); |
| 238 } | 196 } |
| 239 | 197 |
| 240 void RecordingSource::Clear() { | |
| 241 recorded_viewport_ = gfx::Rect(); | |
| 242 display_list_ = nullptr; | |
| 243 painter_reported_memory_usage_ = 0; | |
| 244 is_solid_color_ = false; | |
| 245 } | |
| 246 | |
| 247 } // namespace cc | 198 } // namespace cc |
| OLD | NEW |