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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "cc/debug/lap_timer.h" | 14 #include "cc/debug/lap_timer.h" |
15 #include "cc/debug/rasterize_and_record_benchmark_impl.h" | 15 #include "cc/debug/rasterize_and_record_benchmark_impl.h" |
16 #include "cc/layers/content_layer_client.h" | |
16 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
17 #include "cc/layers/picture_layer.h" | 18 #include "cc/layers/picture_layer.h" |
19 #include "cc/resources/display_item_list.h" | |
18 #include "cc/resources/picture_pile.h" | 20 #include "cc/resources/picture_pile.h" |
19 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
20 #include "cc/trees/layer_tree_host_common.h" | 22 #include "cc/trees/layer_tree_host_common.h" |
21 #include "third_party/skia/include/utils/SkPictureUtils.h" | 23 #include "third_party/skia/include/utils/SkPictureUtils.h" |
22 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
23 | 25 |
24 namespace cc { | 26 namespace cc { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 settings_.get(), | 97 settings_.get(), |
96 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, | 98 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, |
97 weak_ptr_factory_.GetWeakPtr()))); | 99 weak_ptr_factory_.GetWeakPtr()))); |
98 } | 100 } |
99 | 101 |
100 void RasterizeAndRecordBenchmark::Run(Layer* layer) { | 102 void RasterizeAndRecordBenchmark::Run(Layer* layer) { |
101 layer->RunMicroBenchmark(this); | 103 layer->RunMicroBenchmark(this); |
102 } | 104 } |
103 | 105 |
104 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { | 106 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { |
105 ContentLayerClient* painter = layer->client(); | |
106 gfx::Size content_bounds = layer->content_bounds(); | |
107 | |
108 DCHECK(host_); | 107 DCHECK(host_); |
109 gfx::Size tile_grid_size = host_->settings().default_tile_size; | |
110 | 108 |
111 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( | 109 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( |
112 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); | 110 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); |
113 if (visible_content_rect.IsEmpty()) | 111 if (visible_content_rect.IsEmpty()) |
114 return; | 112 return; |
115 | 113 |
114 if (host_->settings().use_display_lists) { | |
115 RunOnDisplayListLayer(layer, visible_content_rect); | |
116 } else { | |
117 RunOnPictureLayer(layer, visible_content_rect); | |
118 } | |
119 } | |
120 | |
121 void RasterizeAndRecordBenchmark::RunOnPictureLayer( | |
122 PictureLayer* layer, | |
123 const gfx::Rect& visible_content_rect) { | |
124 ContentLayerClient* painter = layer->client(); | |
125 | |
126 DCHECK(host_ && !host_->settings().use_display_lists); | |
127 | |
128 gfx::Size tile_grid_size = host_->settings().default_tile_size; | |
129 | |
116 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT; | 130 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT; |
117 mode_index++) { | 131 mode_index++) { |
118 Picture::RecordingMode mode = | 132 Picture::RecordingMode mode = |
119 static_cast<Picture::RecordingMode>(mode_index); | 133 static_cast<Picture::RecordingMode>(mode_index); |
120 base::TimeDelta min_time = base::TimeDelta::Max(); | 134 base::TimeDelta min_time = base::TimeDelta::Max(); |
121 size_t memory_used = 0; | 135 size_t memory_used = 0; |
122 | 136 |
123 // Parameters for LapTimer. | 137 // Parameters for LapTimer. |
124 const int kTimeLimitMillis = 1; | 138 const int kTimeLimitMillis = 1; |
125 const int kWarmupRuns = 0; | 139 const int kWarmupRuns = 0; |
126 const int kTimeCheckInterval = 1; | 140 const int kTimeCheckInterval = 1; |
127 | 141 |
128 for (int i = 0; i < record_repeat_count_; ++i) { | 142 for (int i = 0; i < record_repeat_count_; ++i) { |
129 // Run for a minimum amount of time to avoid problems with timer | 143 // Run for a minimum amount of time to avoid problems with timer |
130 // quantization when the layer is very small. | 144 // quantization when the layer is very small. |
131 LapTimer timer(kWarmupRuns, | 145 LapTimer timer(kWarmupRuns, |
132 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 146 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
133 kTimeCheckInterval); | 147 kTimeCheckInterval); |
134 scoped_refptr<Picture> picture; | 148 scoped_refptr<Picture> picture; |
135 do { | 149 do { |
136 picture = Picture::Create(visible_content_rect, painter, tile_grid_size, | 150 picture = Picture::Create(visible_content_rect, painter, tile_grid_size, |
137 false, mode); | 151 false, mode); |
152 if (memory_used) { | |
153 // Verify we are recording the same thing each time. | |
154 DCHECK(memory_used == picture->ApproximateMemoryUsage()); | |
155 } else { | |
156 memory_used = picture->ApproximateMemoryUsage(); | |
157 } | |
158 | |
138 timer.NextLap(); | 159 timer.NextLap(); |
139 } while (!timer.HasTimeLimitExpired()); | 160 } while (!timer.HasTimeLimitExpired()); |
140 base::TimeDelta duration = | 161 base::TimeDelta duration = |
141 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 162 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
142 if (duration < min_time) | 163 if (duration < min_time) |
143 min_time = duration; | 164 min_time = duration; |
144 memory_used = picture->ApproximateMemoryUsage(); | |
145 } | 165 } |
146 | 166 |
147 if (mode == Picture::RECORD_NORMALLY) { | 167 if (mode == Picture::RECORD_NORMALLY) { |
148 record_results_.bytes_used += memory_used; | 168 record_results_.bytes_used += memory_used; |
149 record_results_.pixels_recorded += | 169 record_results_.pixels_recorded += |
150 visible_content_rect.width() * visible_content_rect.height(); | 170 visible_content_rect.width() * visible_content_rect.height(); |
151 } | 171 } |
152 record_results_.total_best_time[mode_index] += min_time; | 172 record_results_.total_best_time[mode_index] += min_time; |
153 } | 173 } |
154 } | 174 } |
155 | 175 |
176 void RasterizeAndRecordBenchmark::RunOnDisplayListLayer( | |
177 PictureLayer* layer, | |
178 const gfx::Rect& visible_content_rect) { | |
179 ContentLayerClient* painter = layer->client(); | |
180 | |
181 DCHECK(host_ && host_->settings().use_display_lists); | |
182 | |
183 base::TimeDelta min_time = base::TimeDelta::Max(); | |
184 size_t memory_used = 0; | |
185 | |
186 // Parameters for LapTimer. | |
187 const int kTimeLimitMillis = 1; | |
vmpstr
2015/01/27 22:57:32
nit: You can move this to anonymous namespace
Stephen Chennney
2015/01/28 00:24:08
Done.
| |
188 const int kWarmupRuns = 0; | |
189 const int kTimeCheckInterval = 1; | |
190 | |
191 // TODO(schenney): What are the corresponding Picture::RecordingMode modes | |
192 // for Slimming Paint. We could disable SkPicture creation in | |
193 // DrawingDisplayItems, or we could only generate the display list and not | |
194 // do any work on it in the compositor, or something else, or all of the | |
195 // above. | |
196 scoped_refptr<DisplayItemList> display_list; | |
197 for (int i = 0; i < record_repeat_count_; ++i) { | |
198 // Run for a minimum amount of time to avoid problems with timer | |
199 // quantization when the layer is very small. | |
200 LapTimer timer(kWarmupRuns, | |
201 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | |
202 kTimeCheckInterval); | |
203 | |
204 do { | |
205 // TODO(schenney): Cached content will not be regenerated, which skews | |
206 // the results significantly in favor of Slimming Paint (or should). | |
207 // Add a flag or API call to disable caching, and maybe run the test | |
208 // twice, without and with caching. | |
209 display_list = painter->PaintContentsToDisplayList( | |
210 visible_content_rect, ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | |
211 | |
212 if (memory_used) { | |
213 // Verify we are recording the same thing each time. | |
214 DCHECK(memory_used == display_list->PictureMemoryUsage()); | |
215 } else { | |
216 memory_used = display_list->PictureMemoryUsage(); | |
217 } | |
218 | |
219 timer.NextLap(); | |
220 } while (!timer.HasTimeLimitExpired()); | |
221 base::TimeDelta duration = | |
222 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | |
223 if (duration < min_time) | |
224 min_time = duration; | |
225 } | |
226 | |
227 record_results_.bytes_used += memory_used; | |
228 record_results_.pixels_recorded += | |
229 visible_content_rect.width() * visible_content_rect.height(); | |
230 record_results_.total_best_time[Picture::RECORD_NORMALLY] += min_time; | |
231 } | |
232 | |
156 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | 233 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
157 : pixels_recorded(0), bytes_used(0) { | 234 : pixels_recorded(0), bytes_used(0) { |
235 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT; | |
236 mode_index++) { | |
237 total_best_time[mode_index] = base::TimeDelta(); | |
vmpstr
2015/01/27 22:57:32
nit: I don't think this is required?
Stephen Chennney
2015/01/28 00:24:08
Done, and verified that you still see 0 in output.
| |
238 } | |
158 } | 239 } |
159 | 240 |
160 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | 241 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
161 | 242 |
162 } // namespace cc | 243 } // namespace cc |
OLD | NEW |