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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "cc/debug/lap_timer.h" |
12 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
13 #include "cc/layers/picture_layer_impl.h" | 14 #include "cc/layers/picture_layer_impl.h" |
14 #include "cc/resources/raster_worker_pool.h" | 15 #include "cc/resources/raster_worker_pool.h" |
15 #include "cc/trees/layer_tree_host_common.h" | 16 #include "cc/trees/layer_tree_host_common.h" |
16 #include "cc/trees/layer_tree_host_impl.h" | 17 #include "cc/trees/layer_tree_host_impl.h" |
17 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const int kDefaultRasterizeRepeatCount = 100; | 24 const int kDefaultRasterizeRepeatCount = 100; |
24 | 25 |
25 base::TimeTicks Now() { | |
26 return base::TimeTicks::IsThreadNowSupported() | |
27 ? base::TimeTicks::ThreadNow() | |
28 : base::TimeTicks::HighResNow(); | |
29 } | |
30 | |
31 class BenchmarkRasterTask : public Task { | 26 class BenchmarkRasterTask : public Task { |
32 public: | 27 public: |
33 BenchmarkRasterTask(PicturePileImpl* picture_pile, | 28 BenchmarkRasterTask(PicturePileImpl* picture_pile, |
34 const gfx::Rect& content_rect, | 29 const gfx::Rect& content_rect, |
35 float contents_scale, | 30 float contents_scale, |
36 size_t repeat_count) | 31 size_t repeat_count) |
37 : picture_pile_(picture_pile), | 32 : picture_pile_(picture_pile), |
38 content_rect_(content_rect), | 33 content_rect_(content_rect), |
39 contents_scale_(contents_scale), | 34 contents_scale_(contents_scale), |
40 repeat_count_(repeat_count), | 35 repeat_count_(repeat_count), |
41 is_solid_color_(false), | 36 is_solid_color_(false), |
42 best_time_(base::TimeDelta::Max()) {} | 37 best_time_(base::TimeDelta::Max()) {} |
43 | 38 |
44 // Overridden from Task: | 39 // Overridden from Task: |
45 virtual void RunOnWorkerThread() OVERRIDE { | 40 virtual void RunOnWorkerThread() OVERRIDE { |
46 PicturePileImpl* picture_pile = picture_pile_->GetCloneForDrawingOnThread( | 41 PicturePileImpl* picture_pile = picture_pile_->GetCloneForDrawingOnThread( |
47 RasterWorkerPool::GetPictureCloneIndexForCurrentThread()); | 42 RasterWorkerPool::GetPictureCloneIndexForCurrentThread()); |
48 | 43 |
| 44 // Parameters for LapTimer. |
| 45 const int kTimeLimitMillis = 1; |
| 46 const int kWarmupRuns = 0; |
| 47 const int kTimeCheckInterval = 1; |
| 48 |
49 for (size_t i = 0; i < repeat_count_; ++i) { | 49 for (size_t i = 0; i < repeat_count_; ++i) { |
50 SkBitmap bitmap; | 50 // Run for a minimum amount of time to avoid problems with timer |
51 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect_.width(), | 51 // quantization when the layer is very small. |
52 content_rect_.height())); | 52 LapTimer timer(kWarmupRuns, |
53 SkCanvas canvas(bitmap); | 53 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
54 PicturePileImpl::Analysis analysis; | 54 kTimeCheckInterval); |
| 55 do { |
| 56 SkBitmap bitmap; |
| 57 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect_.width(), |
| 58 content_rect_.height())); |
| 59 SkCanvas canvas(bitmap); |
| 60 PicturePileImpl::Analysis analysis; |
55 | 61 |
56 base::TimeTicks start = Now(); | 62 picture_pile->AnalyzeInRect( |
57 picture_pile->AnalyzeInRect( | 63 content_rect_, contents_scale_, &analysis, NULL); |
58 content_rect_, contents_scale_, &analysis, NULL); | 64 picture_pile->RasterToBitmap( |
59 picture_pile->RasterToBitmap( | 65 &canvas, content_rect_, contents_scale_, NULL); |
60 &canvas, content_rect_, contents_scale_, NULL); | 66 |
61 base::TimeTicks end = Now(); | 67 is_solid_color_ = analysis.is_solid_color; |
62 base::TimeDelta duration = end - start; | 68 |
| 69 timer.NextLap(); |
| 70 } while (!timer.HasTimeLimitExpired()); |
| 71 base::TimeDelta duration = |
| 72 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
63 if (duration < best_time_) | 73 if (duration < best_time_) |
64 best_time_ = duration; | 74 best_time_ = duration; |
65 | 75 |
66 is_solid_color_ = analysis.is_solid_color; | |
67 } | 76 } |
68 } | 77 } |
69 | 78 |
70 bool IsSolidColor() const { return is_solid_color_; } | 79 bool IsSolidColor() const { return is_solid_color_; } |
71 base::TimeDelta GetBestTime() const { return best_time_; } | 80 base::TimeDelta GetBestTime() const { return best_time_; } |
72 | 81 |
73 private: | 82 private: |
74 virtual ~BenchmarkRasterTask() {} | 83 virtual ~BenchmarkRasterTask() {} |
75 | 84 |
76 PicturePileImpl* picture_pile_; | 85 PicturePileImpl* picture_pile_; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 pixels_rasterized_with_non_solid_color(0), | 213 pixels_rasterized_with_non_solid_color(0), |
205 pixels_rasterized_as_opaque(0), | 214 pixels_rasterized_as_opaque(0), |
206 total_layers(0), | 215 total_layers(0), |
207 total_picture_layers(0), | 216 total_picture_layers(0), |
208 total_picture_layers_with_no_content(0), | 217 total_picture_layers_with_no_content(0), |
209 total_picture_layers_off_screen(0) {} | 218 total_picture_layers_off_screen(0) {} |
210 | 219 |
211 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} | 220 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} |
212 | 221 |
213 } // namespace cc | 222 } // namespace cc |
OLD | NEW |