OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/debug/rasterize_and_record_benchmark.h" | 5 #include "cc/debug/rasterize_and_record_benchmark.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const int kDefaultRecordRepeatCount = 100; | 30 const int kDefaultRecordRepeatCount = 100; |
31 | 31 |
32 // Parameters for LapTimer. | 32 // Parameters for LapTimer. |
33 const int kTimeLimitMillis = 1; | 33 const int kTimeLimitMillis = 1; |
34 const int kWarmupRuns = 0; | 34 const int kWarmupRuns = 0; |
35 const int kTimeCheckInterval = 1; | 35 const int kTimeCheckInterval = 1; |
36 | 36 |
37 const char* kModeSuffixes[Picture::RECORDING_MODE_COUNT] = { | 37 const char* kModeSuffixes[RecordingSource::RECORDING_MODE_COUNT] = |
38 "", | 38 {"", "_sk_null_canvas", "_painting_disabled", "_caching_disabled"}; |
39 "_sk_null_canvas", | |
40 "_painting_disabled"}; | |
41 | 39 |
42 } // namespace | 40 } // namespace |
43 | 41 |
44 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( | 42 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( |
45 scoped_ptr<base::Value> value, | 43 scoped_ptr<base::Value> value, |
46 const MicroBenchmark::DoneCallback& callback) | 44 const MicroBenchmark::DoneCallback& callback) |
47 : MicroBenchmark(callback), | 45 : MicroBenchmark(callback), |
48 record_repeat_count_(kDefaultRecordRepeatCount), | 46 record_repeat_count_(kDefaultRecordRepeatCount), |
49 settings_(value.Pass()), | 47 settings_(value.Pass()), |
50 main_thread_benchmark_done_(false), | 48 main_thread_benchmark_done_(false), |
(...skipping 16 matching lines...) Expand all Loading... |
67 host_ = host; | 65 host_ = host; |
68 LayerTreeHostCommon::CallFunctionForSubtree( | 66 LayerTreeHostCommon::CallFunctionForSubtree( |
69 host->root_layer(), | 67 host->root_layer(), |
70 base::Bind(&RasterizeAndRecordBenchmark::Run, base::Unretained(this))); | 68 base::Bind(&RasterizeAndRecordBenchmark::Run, base::Unretained(this))); |
71 | 69 |
72 DCHECK(!results_.get()); | 70 DCHECK(!results_.get()); |
73 results_ = make_scoped_ptr(new base::DictionaryValue); | 71 results_ = make_scoped_ptr(new base::DictionaryValue); |
74 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); | 72 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); |
75 results_->SetInteger("picture_memory_usage", record_results_.bytes_used); | 73 results_->SetInteger("picture_memory_usage", record_results_.bytes_used); |
76 | 74 |
77 for (int i = 0; i < Picture::RECORDING_MODE_COUNT; i++) { | 75 for (int i = 0; i < RecordingSource::RECORDING_MODE_COUNT; i++) { |
78 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); | 76 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); |
79 results_->SetDouble(name, | 77 results_->SetDouble(name, |
80 record_results_.total_best_time[i].InMillisecondsF()); | 78 record_results_.total_best_time[i].InMillisecondsF()); |
81 } | 79 } |
82 main_thread_benchmark_done_ = true; | 80 main_thread_benchmark_done_ = true; |
83 } | 81 } |
84 | 82 |
85 void RasterizeAndRecordBenchmark::RecordRasterResults( | 83 void RasterizeAndRecordBenchmark::RecordRasterResults( |
86 scoped_ptr<base::Value> results_value) { | 84 scoped_ptr<base::Value> results_value) { |
87 DCHECK(main_thread_benchmark_done_); | 85 DCHECK(main_thread_benchmark_done_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 123 |
126 void RasterizeAndRecordBenchmark::RunOnPictureLayer( | 124 void RasterizeAndRecordBenchmark::RunOnPictureLayer( |
127 PictureLayer* layer, | 125 PictureLayer* layer, |
128 const gfx::Rect& visible_content_rect) { | 126 const gfx::Rect& visible_content_rect) { |
129 ContentLayerClient* painter = layer->client(); | 127 ContentLayerClient* painter = layer->client(); |
130 | 128 |
131 DCHECK(host_ && !host_->settings().use_display_lists); | 129 DCHECK(host_ && !host_->settings().use_display_lists); |
132 | 130 |
133 gfx::Size tile_grid_size = host_->settings().default_tile_size; | 131 gfx::Size tile_grid_size = host_->settings().default_tile_size; |
134 | 132 |
135 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT; | 133 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; |
136 mode_index++) { | 134 mode_index++) { |
137 Picture::RecordingMode mode = | 135 RecordingSource::RecordingMode mode = |
138 static_cast<Picture::RecordingMode>(mode_index); | 136 static_cast<RecordingSource::RecordingMode>(mode_index); |
139 base::TimeDelta min_time = base::TimeDelta::Max(); | 137 base::TimeDelta min_time = base::TimeDelta::Max(); |
140 size_t memory_used = 0; | 138 size_t memory_used = 0; |
141 | 139 |
142 for (int i = 0; i < record_repeat_count_; ++i) { | 140 for (int i = 0; i < record_repeat_count_; ++i) { |
143 // Run for a minimum amount of time to avoid problems with timer | 141 // Run for a minimum amount of time to avoid problems with timer |
144 // quantization when the layer is very small. | 142 // quantization when the layer is very small. |
145 LapTimer timer(kWarmupRuns, | 143 LapTimer timer(kWarmupRuns, |
146 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 144 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
147 kTimeCheckInterval); | 145 kTimeCheckInterval); |
148 scoped_refptr<Picture> picture; | 146 scoped_refptr<Picture> picture; |
149 do { | 147 do { |
150 picture = Picture::Create(visible_content_rect, painter, tile_grid_size, | 148 picture = Picture::Create(visible_content_rect, painter, tile_grid_size, |
151 false, mode); | 149 false, mode); |
152 if (memory_used) { | 150 if (memory_used) { |
153 // Verify we are recording the same thing each time. | 151 // Verify we are recording the same thing each time. |
154 DCHECK(memory_used == picture->ApproximateMemoryUsage()); | 152 DCHECK(memory_used == picture->ApproximateMemoryUsage()); |
155 } else { | 153 } else { |
156 memory_used = picture->ApproximateMemoryUsage(); | 154 memory_used = picture->ApproximateMemoryUsage(); |
157 } | 155 } |
158 | 156 |
159 timer.NextLap(); | 157 timer.NextLap(); |
160 } while (!timer.HasTimeLimitExpired()); | 158 } while (!timer.HasTimeLimitExpired()); |
161 base::TimeDelta duration = | 159 base::TimeDelta duration = |
162 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 160 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
163 if (duration < min_time) | 161 if (duration < min_time) |
164 min_time = duration; | 162 min_time = duration; |
165 } | 163 } |
166 | 164 |
167 if (mode == Picture::RECORD_NORMALLY) { | 165 if (mode == RecordingSource::RECORD_NORMALLY) { |
168 record_results_.bytes_used += memory_used; | 166 record_results_.bytes_used += memory_used; |
169 record_results_.pixels_recorded += | 167 record_results_.pixels_recorded += |
170 visible_content_rect.width() * visible_content_rect.height(); | 168 visible_content_rect.width() * visible_content_rect.height(); |
171 } | 169 } |
172 record_results_.total_best_time[mode_index] += min_time; | 170 record_results_.total_best_time[mode_index] += min_time; |
173 } | 171 } |
174 } | 172 } |
175 | 173 |
176 void RasterizeAndRecordBenchmark::RunOnDisplayListLayer( | 174 void RasterizeAndRecordBenchmark::RunOnDisplayListLayer( |
177 PictureLayer* layer, | 175 PictureLayer* layer, |
178 const gfx::Rect& visible_content_rect) { | 176 const gfx::Rect& visible_content_rect) { |
179 ContentLayerClient* painter = layer->client(); | 177 ContentLayerClient* painter = layer->client(); |
180 | 178 |
181 DCHECK(host_ && host_->settings().use_display_lists); | 179 DCHECK(host_ && host_->settings().use_display_lists); |
182 | 180 |
183 base::TimeDelta min_time = base::TimeDelta::Max(); | 181 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; |
184 size_t memory_used = 0; | 182 mode_index++) { |
| 183 ContentLayerClient::PaintingControlSetting painting_control = |
| 184 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; |
| 185 switch (static_cast<RecordingSource::RecordingMode>(mode_index)) { |
| 186 case RecordingSource::RECORD_NORMALLY: |
| 187 // Already setup for normal recording. |
| 188 break; |
| 189 case RecordingSource::RECORD_WITH_SK_NULL_CANVAS: |
| 190 // TODO(schenney): Remove this when DisplayList recording is the only |
| 191 // option. For now, fall through and disable construction. |
| 192 case RecordingSource::RECORD_WITH_PAINTING_DISABLED: |
| 193 painting_control = |
| 194 ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; |
| 195 break; |
| 196 case RecordingSource::RECORD_WITH_CACHING_DISABLED: |
| 197 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; |
| 198 break; |
| 199 default: |
| 200 NOTREACHED(); |
| 201 } |
| 202 base::TimeDelta min_time = base::TimeDelta::Max(); |
| 203 size_t memory_used = 0; |
185 | 204 |
186 // TODO(schenney): What are the corresponding Picture::RecordingMode modes | 205 scoped_refptr<DisplayItemList> display_list; |
187 // for Slimming Paint. We could disable SkPicture creation in | 206 for (int i = 0; i < record_repeat_count_; ++i) { |
188 // DrawingDisplayItems, or we could only generate the display list and not | 207 // Run for a minimum amount of time to avoid problems with timer |
189 // do any work on it in the compositor, or something else, or all of the | 208 // quantization when the layer is very small. |
190 // above. | 209 LapTimer timer(kWarmupRuns, |
191 scoped_refptr<DisplayItemList> display_list; | 210 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
192 for (int i = 0; i < record_repeat_count_; ++i) { | 211 kTimeCheckInterval); |
193 // Run for a minimum amount of time to avoid problems with timer | |
194 // quantization when the layer is very small. | |
195 LapTimer timer(kWarmupRuns, | |
196 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | |
197 kTimeCheckInterval); | |
198 | 212 |
199 do { | 213 do { |
200 // TODO(schenney): Cached content will not be regenerated, which skews | 214 display_list = painter->PaintContentsToDisplayList(visible_content_rect, |
201 // the results significantly in favor of Slimming Paint (or should). | 215 painting_control); |
202 // Add a flag or API call to disable caching, and maybe run the test | |
203 // twice, without and with caching. | |
204 display_list = painter->PaintContentsToDisplayList( | |
205 visible_content_rect, ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | |
206 | 216 |
207 if (memory_used) { | 217 if (memory_used) { |
208 // Verify we are recording the same thing each time. | 218 // Verify we are recording the same thing each time. |
209 DCHECK(memory_used == display_list->PictureMemoryUsage()); | 219 DCHECK(memory_used == display_list->PictureMemoryUsage()); |
210 } else { | 220 } else { |
211 memory_used = display_list->PictureMemoryUsage(); | 221 memory_used = display_list->PictureMemoryUsage(); |
212 } | 222 } |
213 | 223 |
214 timer.NextLap(); | 224 timer.NextLap(); |
215 } while (!timer.HasTimeLimitExpired()); | 225 } while (!timer.HasTimeLimitExpired()); |
216 base::TimeDelta duration = | 226 base::TimeDelta duration = |
217 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 227 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
218 if (duration < min_time) | 228 if (duration < min_time) |
219 min_time = duration; | 229 min_time = duration; |
| 230 } |
| 231 |
| 232 record_results_.bytes_used += memory_used; |
| 233 record_results_.pixels_recorded += |
| 234 visible_content_rect.width() * visible_content_rect.height(); |
| 235 record_results_.total_best_time[mode_index] += min_time; |
220 } | 236 } |
221 | |
222 record_results_.bytes_used += memory_used; | |
223 record_results_.pixels_recorded += | |
224 visible_content_rect.width() * visible_content_rect.height(); | |
225 record_results_.total_best_time[Picture::RECORD_NORMALLY] += min_time; | |
226 } | 237 } |
227 | 238 |
228 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | 239 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
229 : pixels_recorded(0), bytes_used(0) { | 240 : pixels_recorded(0), bytes_used(0) { |
230 } | 241 } |
231 | 242 |
232 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | 243 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
233 | 244 |
234 } // namespace cc | 245 } // namespace cc |
OLD | NEW |