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