Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: cc/playback/recording_source.cc

Issue 2141233002: cc: Clean up RecordingSource API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address vmpstr's comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/recording_source.h ('k') | cc/playback/recording_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_) {
vmpstr 2016/08/01 20:29:53 nit: braces optional
Menglin 2016/08/02 02:58:43 Done.
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 } 73 }
87 } 74 }
88 75
89 void RecordingSource::UpdateInvalidationForNewViewport( 76 void RecordingSource::UpdateInvalidationForNewViewport(
90 const gfx::Rect& old_recorded_viewport, 77 const gfx::Rect& old_recorded_viewport,
91 const gfx::Rect& new_recorded_viewport, 78 const gfx::Rect& new_recorded_viewport,
92 Region* invalidation) { 79 Region* invalidation) {
93 // Invalidate newly-exposed and no-longer-exposed areas. 80 // Invalidate newly-exposed and no-longer-exposed areas.
94 Region newly_exposed_region(new_recorded_viewport); 81 Region newly_exposed_region(new_recorded_viewport);
95 newly_exposed_region.Subtract(old_recorded_viewport); 82 newly_exposed_region.Subtract(old_recorded_viewport);
(...skipping 16 matching lines...) Expand all
112 if (!layer_rect.IsEmpty()) { 99 if (!layer_rect.IsEmpty()) {
113 // Clamp invalidation to the layer bounds. 100 // Clamp invalidation to the layer bounds.
114 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); 101 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_)));
115 } 102 }
116 } 103 }
117 104
118 bool RecordingSource::UpdateAndExpandInvalidation( 105 bool RecordingSource::UpdateAndExpandInvalidation(
119 ContentLayerClient* painter, 106 ContentLayerClient* painter,
120 Region* invalidation, 107 Region* invalidation,
121 const gfx::Size& layer_size, 108 const gfx::Size& layer_size,
122 int frame_number, 109 const gfx::Rect& new_recorded_viewport,
123 RecordingMode recording_mode) { 110 const scoped_refptr<DisplayItemList>& display_list,
111 const size_t& painter_reported_memory_usage) {
124 bool updated = false; 112 bool updated = false;
125 113
126 if (size_ != layer_size) 114 if (size_ != layer_size)
127 size_ = layer_size; 115 size_ = layer_size;
128 116
129 invalidation_.Swap(invalidation); 117 invalidation_.Swap(invalidation);
130 invalidation_.Clear(); 118 invalidation_.Clear();
131 119
132 gfx::Rect new_recorded_viewport = painter->PaintableRegion();
133 if (new_recorded_viewport != recorded_viewport_) { 120 if (new_recorded_viewport != recorded_viewport_) {
134 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport, 121 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport,
135 invalidation); 122 invalidation);
136 recorded_viewport_ = new_recorded_viewport; 123 recorded_viewport_ = new_recorded_viewport;
137 updated = true; 124 updated = true;
138 } 125 }
139 126
140 if (!updated && !invalidation->Intersects(recorded_viewport_)) 127 if (!updated && !invalidation->Intersects(recorded_viewport_))
141 return false; 128 return false;
142 129
143 if (invalidation->IsEmpty()) 130 if (invalidation->IsEmpty())
144 return false; 131 return false;
145 132
146 ContentLayerClient::PaintingControlSetting painting_control = 133 display_list_ = display_list;
147 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; 134 painter_reported_memory_usage_ = painter_reported_memory_usage;
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 135
175 FinishDisplayItemListUpdate(); 136 FinishDisplayItemListUpdate();
176 137
177 return true; 138 return true;
178 } 139 }
179 140
180 gfx::Size RecordingSource::GetSize() const { 141 gfx::Size RecordingSource::GetSize() const {
181 return size_; 142 return size_;
182 } 143 }
183 144
184 void RecordingSource::SetEmptyBounds() { 145 void RecordingSource::SetEmptyBounds() {
185 size_ = gfx::Size(); 146 size_ = gfx::Size();
186 Clear(); 147 is_solid_color_ = false;
148
149 recorded_viewport_ = gfx::Rect();
150 display_list_ = nullptr;
151 painter_reported_memory_usage_ = 0;
187 } 152 }
188 153
189 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) { 154 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) {
190 slow_down_raster_scale_factor_for_debug_ = factor; 155 slow_down_raster_scale_factor_for_debug_ = factor;
191 } 156 }
192 157
193 void RecordingSource::SetGenerateDiscardableImagesMetadata( 158 void RecordingSource::SetGenerateDiscardableImagesMetadata(
194 bool generate_metadata) { 159 bool generate_metadata) {
195 generate_discardable_images_metadata_ = generate_metadata; 160 generate_discardable_images_metadata_ = generate_metadata;
196 } 161 }
197 162
198 void RecordingSource::SetBackgroundColor(SkColor background_color) { 163 void RecordingSource::SetBackgroundColor(SkColor background_color) {
199 background_color_ = background_color; 164 background_color_ = background_color;
200 } 165 }
201 166
202 void RecordingSource::SetRequiresClear(bool requires_clear) { 167 void RecordingSource::SetRequiresClear(bool requires_clear) {
203 requires_clear_ = requires_clear; 168 requires_clear_ = requires_clear;
204 } 169 }
205 170
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() { 171 const DisplayItemList* RecordingSource::GetDisplayItemList() {
215 return display_list_.get(); 172 return display_list_.get();
216 } 173 }
217 174
218 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource( 175 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource(
219 bool can_use_lcd_text) const { 176 bool can_use_lcd_text) const {
220 return scoped_refptr<RasterSource>( 177 return scoped_refptr<RasterSource>(
221 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text)); 178 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text));
222 } 179 }
223 180
224 void RecordingSource::DetermineIfSolidColor() { 181 void RecordingSource::DetermineIfSolidColor() {
225 DCHECK(display_list_); 182 DCHECK(display_list_);
226 is_solid_color_ = false; 183 is_solid_color_ = false;
227 solid_color_ = SK_ColorTRANSPARENT; 184 solid_color_ = SK_ColorTRANSPARENT;
228 185
229 if (!display_list_->ShouldBeAnalyzedForSolidColor()) 186 if (!display_list_->ShouldBeAnalyzedForSolidColor())
230 return; 187 return;
231 188
232 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", 189 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
233 display_list_->ApproximateOpCount()); 190 display_list_->ApproximateOpCount());
234 gfx::Size layer_size = GetSize(); 191 gfx::Size layer_size = GetSize();
235 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); 192 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height());
236 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); 193 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f);
237 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); 194 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
238 } 195 }
239 196
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 197 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/recording_source.h ('k') | cc/playback/recording_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698