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_impl.h" | 5 #include "cc/debug/rasterize_and_record_benchmark_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
11 | 11 |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "cc/debug/lap_timer.h" | 13 #include "cc/debug/lap_timer.h" |
14 #include "cc/layers/layer_impl.h" | 14 #include "cc/layers/layer_impl.h" |
15 #include "cc/layers/picture_layer_impl.h" | 15 #include "cc/layers/picture_layer_impl.h" |
16 #include "cc/raster/raster_buffer_provider.h" | 16 #include "cc/raster/raster_buffer_provider.h" |
17 #include "cc/trees/layer_tree_host_common.h" | 17 #include "cc/trees/layer_tree_host_common.h" |
18 #include "cc/trees/layer_tree_host_impl.h" | 18 #include "cc/trees/layer_tree_host_impl.h" |
19 #include "cc/trees/layer_tree_impl.h" | 19 #include "cc/trees/layer_tree_impl.h" |
20 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const int kDefaultRasterizeRepeatCount = 100; | 26 const int kDefaultRasterizeRepeatCount = 100; |
27 | 27 |
28 void RunBenchmark(RasterSource* raster_source, | 28 void RunBenchmark(RasterSource* raster_source, |
29 const gfx::Rect& content_rect, | 29 const gfx::Rect& content_rect, |
30 const gfx::SizeF& raster_scales, | 30 float contents_scale, |
31 size_t repeat_count, | 31 size_t repeat_count, |
32 base::TimeDelta* min_time, | 32 base::TimeDelta* min_time, |
33 bool* is_solid_color) { | 33 bool* is_solid_color) { |
34 // Parameters for LapTimer. | 34 // Parameters for LapTimer. |
35 const int kTimeLimitMillis = 1; | 35 const int kTimeLimitMillis = 1; |
36 const int kWarmupRuns = 0; | 36 const int kWarmupRuns = 0; |
37 const int kTimeCheckInterval = 1; | 37 const int kTimeCheckInterval = 1; |
38 | 38 |
39 *min_time = base::TimeDelta::Max(); | 39 *min_time = base::TimeDelta::Max(); |
40 for (size_t i = 0; i < repeat_count; ++i) { | 40 for (size_t i = 0; i < repeat_count; ++i) { |
41 // Run for a minimum amount of time to avoid problems with timer | 41 // Run for a minimum amount of time to avoid problems with timer |
42 // quantization when the layer is very small. | 42 // quantization when the layer is very small. |
43 LapTimer timer(kWarmupRuns, | 43 LapTimer timer(kWarmupRuns, |
44 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 44 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
45 kTimeCheckInterval); | 45 kTimeCheckInterval); |
46 SkColor color = SK_ColorTRANSPARENT; | 46 SkColor color = SK_ColorTRANSPARENT; |
47 *is_solid_color = raster_source->PerformSolidColorAnalysis( | 47 *is_solid_color = raster_source->PerformSolidColorAnalysis( |
48 content_rect, raster_scales, &color); | 48 content_rect, contents_scale, &color); |
49 | 49 |
50 do { | 50 do { |
51 SkBitmap bitmap; | 51 SkBitmap bitmap; |
52 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect.width(), | 52 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect.width(), |
53 content_rect.height())); | 53 content_rect.height())); |
54 SkCanvas canvas(bitmap); | 54 SkCanvas canvas(bitmap); |
55 | 55 |
56 raster_source->PlaybackToCanvas(&canvas, content_rect, content_rect, | 56 raster_source->PlaybackToCanvas(&canvas, content_rect, content_rect, |
57 raster_scales, | 57 contents_scale, |
58 RasterSource::PlaybackSettings()); | 58 RasterSource::PlaybackSettings()); |
59 | 59 |
60 timer.NextLap(); | 60 timer.NextLap(); |
61 } while (!timer.HasTimeLimitExpired()); | 61 } while (!timer.HasTimeLimitExpired()); |
62 base::TimeDelta duration = | 62 base::TimeDelta duration = |
63 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 63 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
64 if (duration < *min_time) | 64 if (duration < *min_time) |
65 *min_time = duration; | 65 *min_time = duration; |
66 } | 66 } |
67 } | 67 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 tiling_set->AddTiling(1.f, layer->GetRasterSource()); | 181 tiling_set->AddTiling(1.f, layer->GetRasterSource()); |
182 tiling->set_resolution(HIGH_RESOLUTION); | 182 tiling->set_resolution(HIGH_RESOLUTION); |
183 tiling->CreateAllTilesForTesting(); | 183 tiling->CreateAllTilesForTesting(); |
184 RasterSource* raster_source = tiling->raster_source().get(); | 184 RasterSource* raster_source = tiling->raster_source().get(); |
185 for (PictureLayerTiling::CoverageIterator it(tiling, 1.f, | 185 for (PictureLayerTiling::CoverageIterator it(tiling, 1.f, |
186 layer->visible_layer_rect()); | 186 layer->visible_layer_rect()); |
187 it; ++it) { | 187 it; ++it) { |
188 DCHECK(*it); | 188 DCHECK(*it); |
189 | 189 |
190 gfx::Rect content_rect = (*it)->content_rect(); | 190 gfx::Rect content_rect = (*it)->content_rect(); |
191 const gfx::SizeF& raster_scales = (*it)->raster_scales(); | 191 float contents_scale = (*it)->contents_scale(); |
192 | 192 |
193 base::TimeDelta min_time; | 193 base::TimeDelta min_time; |
194 bool is_solid_color = false; | 194 bool is_solid_color = false; |
195 RunBenchmark(raster_source, content_rect, raster_scales, | 195 RunBenchmark(raster_source, content_rect, contents_scale, |
196 rasterize_repeat_count_, &min_time, &is_solid_color); | 196 rasterize_repeat_count_, &min_time, &is_solid_color); |
197 | 197 |
198 int tile_size = content_rect.width() * content_rect.height(); | 198 int tile_size = content_rect.width() * content_rect.height(); |
199 if (layer->contents_opaque()) | 199 if (layer->contents_opaque()) |
200 rasterize_results_.pixels_rasterized_as_opaque += tile_size; | 200 rasterize_results_.pixels_rasterized_as_opaque += tile_size; |
201 | 201 |
202 if (!is_solid_color) | 202 if (!is_solid_color) |
203 rasterize_results_.pixels_rasterized_with_non_solid_color += tile_size; | 203 rasterize_results_.pixels_rasterized_with_non_solid_color += tile_size; |
204 | 204 |
205 rasterize_results_.pixels_rasterized += tile_size; | 205 rasterize_results_.pixels_rasterized += tile_size; |
(...skipping 12 matching lines...) Expand all Loading... |
218 total_memory_usage(0), | 218 total_memory_usage(0), |
219 total_layers(0), | 219 total_layers(0), |
220 total_picture_layers(0), | 220 total_picture_layers(0), |
221 total_picture_layers_with_no_content(0), | 221 total_picture_layers_with_no_content(0), |
222 total_picture_layers_off_screen(0) { | 222 total_picture_layers_off_screen(0) { |
223 } | 223 } |
224 | 224 |
225 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} | 225 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} |
226 | 226 |
227 } // namespace cc | 227 } // namespace cc |
OLD | NEW |