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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return make_scoped_ptr(new RasterizeAndRecordBenchmarkImpl( | 98 return make_scoped_ptr(new RasterizeAndRecordBenchmarkImpl( |
99 origin_loop, | 99 origin_loop, |
100 settings_.get(), | 100 settings_.get(), |
101 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, | 101 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, |
102 weak_ptr_factory_.GetWeakPtr()))); | 102 weak_ptr_factory_.GetWeakPtr()))); |
103 } | 103 } |
104 | 104 |
105 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { | 105 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { |
106 DCHECK(host_); | 106 DCHECK(host_); |
107 | 107 |
108 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( | 108 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
109 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); | 109 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); |
110 if (visible_content_rect.IsEmpty()) | 110 if (visible_layer_rect.IsEmpty()) |
111 return; | 111 return; |
112 | 112 |
113 if (host_->settings().use_display_lists) { | 113 if (host_->settings().use_display_lists) { |
114 RunOnDisplayListLayer(layer, visible_content_rect); | 114 RunOnDisplayListLayer(layer, visible_layer_rect); |
115 } else { | 115 } else { |
116 RunOnPictureLayer(layer, visible_content_rect); | 116 RunOnPictureLayer(layer, visible_layer_rect); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 void RasterizeAndRecordBenchmark::RunOnPictureLayer( | 120 void RasterizeAndRecordBenchmark::RunOnPictureLayer( |
121 PictureLayer* layer, | 121 PictureLayer* layer, |
122 const gfx::Rect& visible_content_rect) { | 122 const gfx::Rect& visible_layer_rect) { |
123 ContentLayerClient* painter = layer->client(); | 123 ContentLayerClient* painter = layer->client(); |
124 | 124 |
125 DCHECK(host_ && !host_->settings().use_display_lists); | 125 DCHECK(host_ && !host_->settings().use_display_lists); |
126 | 126 |
127 gfx::Size tile_grid_size = host_->settings().default_tile_size; | 127 gfx::Size tile_grid_size = host_->settings().default_tile_size; |
128 | 128 |
129 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; | 129 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; |
130 mode_index++) { | 130 mode_index++) { |
131 RecordingSource::RecordingMode mode = | 131 RecordingSource::RecordingMode mode = |
132 static_cast<RecordingSource::RecordingMode>(mode_index); | 132 static_cast<RecordingSource::RecordingMode>(mode_index); |
133 base::TimeDelta min_time = base::TimeDelta::Max(); | 133 base::TimeDelta min_time = base::TimeDelta::Max(); |
134 size_t memory_used = 0; | 134 size_t memory_used = 0; |
135 | 135 |
136 for (int i = 0; i < record_repeat_count_; ++i) { | 136 for (int i = 0; i < record_repeat_count_; ++i) { |
137 // Run for a minimum amount of time to avoid problems with timer | 137 // Run for a minimum amount of time to avoid problems with timer |
138 // quantization when the layer is very small. | 138 // quantization when the layer is very small. |
139 LapTimer timer(kWarmupRuns, | 139 LapTimer timer(kWarmupRuns, |
140 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 140 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
141 kTimeCheckInterval); | 141 kTimeCheckInterval); |
142 scoped_refptr<Picture> picture; | 142 scoped_refptr<Picture> picture; |
143 do { | 143 do { |
144 picture = Picture::Create(visible_content_rect, painter, tile_grid_size, | 144 picture = Picture::Create(visible_layer_rect, painter, tile_grid_size, |
145 false, mode); | 145 false, mode); |
146 if (memory_used) { | 146 if (memory_used) { |
147 // Verify we are recording the same thing each time. | 147 // Verify we are recording the same thing each time. |
148 DCHECK(memory_used == picture->ApproximateMemoryUsage()); | 148 DCHECK(memory_used == picture->ApproximateMemoryUsage()); |
149 } else { | 149 } else { |
150 memory_used = picture->ApproximateMemoryUsage(); | 150 memory_used = picture->ApproximateMemoryUsage(); |
151 } | 151 } |
152 | 152 |
153 timer.NextLap(); | 153 timer.NextLap(); |
154 } while (!timer.HasTimeLimitExpired()); | 154 } while (!timer.HasTimeLimitExpired()); |
155 base::TimeDelta duration = | 155 base::TimeDelta duration = |
156 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 156 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
157 if (duration < min_time) | 157 if (duration < min_time) |
158 min_time = duration; | 158 min_time = duration; |
159 } | 159 } |
160 | 160 |
161 if (mode == RecordingSource::RECORD_NORMALLY) { | 161 if (mode == RecordingSource::RECORD_NORMALLY) { |
162 record_results_.bytes_used += memory_used; | 162 record_results_.bytes_used += memory_used; |
163 record_results_.pixels_recorded += | 163 record_results_.pixels_recorded += |
164 visible_content_rect.width() * visible_content_rect.height(); | 164 visible_layer_rect.width() * visible_layer_rect.height(); |
165 } | 165 } |
166 record_results_.total_best_time[mode_index] += min_time; | 166 record_results_.total_best_time[mode_index] += min_time; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void RasterizeAndRecordBenchmark::RunOnDisplayListLayer( | 170 void RasterizeAndRecordBenchmark::RunOnDisplayListLayer( |
171 PictureLayer* layer, | 171 PictureLayer* layer, |
172 const gfx::Rect& visible_content_rect) { | 172 const gfx::Rect& visible_layer_rect) { |
173 ContentLayerClient* painter = layer->client(); | 173 ContentLayerClient* painter = layer->client(); |
174 | 174 |
175 DCHECK(host_ && host_->settings().use_display_lists); | 175 DCHECK(host_ && host_->settings().use_display_lists); |
176 | 176 |
177 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; | 177 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; |
178 mode_index++) { | 178 mode_index++) { |
179 ContentLayerClient::PaintingControlSetting painting_control = | 179 ContentLayerClient::PaintingControlSetting painting_control = |
180 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; | 180 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; |
181 switch (static_cast<RecordingSource::RecordingMode>(mode_index)) { | 181 switch (static_cast<RecordingSource::RecordingMode>(mode_index)) { |
182 case RecordingSource::RECORD_NORMALLY: | 182 case RecordingSource::RECORD_NORMALLY: |
(...skipping 17 matching lines...) Expand all Loading... |
200 | 200 |
201 scoped_refptr<DisplayItemList> display_list; | 201 scoped_refptr<DisplayItemList> display_list; |
202 for (int i = 0; i < record_repeat_count_; ++i) { | 202 for (int i = 0; i < record_repeat_count_; ++i) { |
203 // Run for a minimum amount of time to avoid problems with timer | 203 // Run for a minimum amount of time to avoid problems with timer |
204 // quantization when the layer is very small. | 204 // quantization when the layer is very small. |
205 LapTimer timer(kWarmupRuns, | 205 LapTimer timer(kWarmupRuns, |
206 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 206 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
207 kTimeCheckInterval); | 207 kTimeCheckInterval); |
208 | 208 |
209 do { | 209 do { |
210 display_list = painter->PaintContentsToDisplayList(visible_content_rect, | 210 display_list = painter->PaintContentsToDisplayList(visible_layer_rect, |
211 painting_control); | 211 painting_control); |
| 212 display_list->CreateAndCacheSkPicture(); |
212 | 213 |
213 if (memory_used) { | 214 if (memory_used) { |
214 // Verify we are recording the same thing each time. | 215 // Verify we are recording the same thing each time. |
215 DCHECK(memory_used == display_list->PictureMemoryUsage()); | 216 DCHECK(memory_used == display_list->PictureMemoryUsage()); |
216 } else { | 217 } else { |
217 memory_used = display_list->PictureMemoryUsage(); | 218 memory_used = display_list->PictureMemoryUsage(); |
218 } | 219 } |
219 | 220 |
220 timer.NextLap(); | 221 timer.NextLap(); |
221 } while (!timer.HasTimeLimitExpired()); | 222 } while (!timer.HasTimeLimitExpired()); |
222 base::TimeDelta duration = | 223 base::TimeDelta duration = |
223 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 224 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
224 if (duration < min_time) | 225 if (duration < min_time) |
225 min_time = duration; | 226 min_time = duration; |
226 } | 227 } |
227 | 228 |
228 if (mode_index == RecordingSource::RECORD_NORMALLY) { | 229 if (mode_index == RecordingSource::RECORD_NORMALLY) { |
229 record_results_.bytes_used += memory_used; | 230 record_results_.bytes_used += memory_used; |
230 record_results_.pixels_recorded += | 231 record_results_.pixels_recorded += |
231 visible_content_rect.width() * visible_content_rect.height(); | 232 visible_layer_rect.width() * visible_layer_rect.height(); |
232 } | 233 } |
233 record_results_.total_best_time[mode_index] += min_time; | 234 record_results_.total_best_time[mode_index] += min_time; |
234 } | 235 } |
235 } | 236 } |
236 | 237 |
237 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | 238 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
238 : pixels_recorded(0), bytes_used(0) { | 239 : pixels_recorded(0), bytes_used(0) { |
239 } | 240 } |
240 | 241 |
241 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | 242 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
242 | 243 |
243 } // namespace cc | 244 } // namespace cc |
OLD | NEW |