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/debug/lap_timer.h" |
13 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
14 #include "cc/layers/picture_layer_impl.h" | 14 #include "cc/layers/picture_layer_impl.h" |
15 #include "cc/resources/raster_worker_pool.h" | 15 #include "cc/resources/raster_worker_pool.h" |
16 #include "cc/trees/layer_tree_host_common.h" | 16 #include "cc/trees/layer_tree_host_common.h" |
17 #include "cc/trees/layer_tree_host_impl.h" | 17 #include "cc/trees/layer_tree_host_impl.h" |
18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const int kDefaultRasterizeRepeatCount = 100; | 24 const int kDefaultRasterizeRepeatCount = 100; |
25 | 25 |
26 class BenchmarkRasterTask : public Task { | 26 class BenchmarkRasterTask : public Task { |
27 public: | 27 public: |
28 BenchmarkRasterTask(PicturePileImpl* picture_pile, | 28 BenchmarkRasterTask(RasterSource* raster_source, |
29 const gfx::Rect& content_rect, | 29 const gfx::Rect& content_rect, |
30 float contents_scale, | 30 float contents_scale, |
31 size_t repeat_count) | 31 size_t repeat_count) |
32 : picture_pile_(picture_pile), | 32 : raster_source_(raster_source), |
33 content_rect_(content_rect), | 33 content_rect_(content_rect), |
34 contents_scale_(contents_scale), | 34 contents_scale_(contents_scale), |
35 repeat_count_(repeat_count), | 35 repeat_count_(repeat_count), |
36 is_solid_color_(false), | 36 is_solid_color_(false), |
37 best_time_(base::TimeDelta::Max()) {} | 37 best_time_(base::TimeDelta::Max()) {} |
38 | 38 |
39 // Overridden from Task: | 39 // Overridden from Task: |
40 void RunOnWorkerThread() override { | 40 void RunOnWorkerThread() override { |
41 // Parameters for LapTimer. | 41 // Parameters for LapTimer. |
42 const int kTimeLimitMillis = 1; | 42 const int kTimeLimitMillis = 1; |
43 const int kWarmupRuns = 0; | 43 const int kWarmupRuns = 0; |
44 const int kTimeCheckInterval = 1; | 44 const int kTimeCheckInterval = 1; |
45 | 45 |
46 for (size_t i = 0; i < repeat_count_; ++i) { | 46 for (size_t i = 0; i < repeat_count_; ++i) { |
47 // Run for a minimum amount of time to avoid problems with timer | 47 // Run for a minimum amount of time to avoid problems with timer |
48 // quantization when the layer is very small. | 48 // quantization when the layer is very small. |
49 LapTimer timer(kWarmupRuns, | 49 LapTimer timer(kWarmupRuns, |
50 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 50 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
51 kTimeCheckInterval); | 51 kTimeCheckInterval); |
52 do { | 52 do { |
53 SkBitmap bitmap; | 53 SkBitmap bitmap; |
54 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect_.width(), | 54 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect_.width(), |
55 content_rect_.height())); | 55 content_rect_.height())); |
56 SkCanvas canvas(bitmap); | 56 SkCanvas canvas(bitmap); |
57 PicturePileImpl::Analysis analysis; | 57 RasterSource::SolidColorAnalysis analysis; |
58 | 58 |
59 picture_pile_->AnalyzeInRect( | 59 raster_source_->PerformSolidColorAnalysis( |
60 content_rect_, contents_scale_, &analysis, nullptr); | 60 content_rect_, contents_scale_, &analysis, nullptr); |
61 picture_pile_->RasterToBitmap( | 61 raster_source_->PlaybackToCanvas( |
62 &canvas, content_rect_, contents_scale_, nullptr); | 62 &canvas, content_rect_, contents_scale_, nullptr); |
63 | 63 |
64 is_solid_color_ = analysis.is_solid_color; | 64 is_solid_color_ = analysis.is_solid_color; |
65 | 65 |
66 timer.NextLap(); | 66 timer.NextLap(); |
67 } while (!timer.HasTimeLimitExpired()); | 67 } while (!timer.HasTimeLimitExpired()); |
68 base::TimeDelta duration = | 68 base::TimeDelta duration = |
69 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 69 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
70 if (duration < best_time_) | 70 if (duration < best_time_) |
71 best_time_ = duration; | 71 best_time_ = duration; |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 bool IsSolidColor() const { return is_solid_color_; } | 75 bool IsSolidColor() const { return is_solid_color_; } |
76 base::TimeDelta GetBestTime() const { return best_time_; } | 76 base::TimeDelta GetBestTime() const { return best_time_; } |
77 | 77 |
78 private: | 78 private: |
79 ~BenchmarkRasterTask() override {} | 79 ~BenchmarkRasterTask() override {} |
80 | 80 |
81 PicturePileImpl* picture_pile_; | 81 RasterSource* raster_source_; |
82 gfx::Rect content_rect_; | 82 gfx::Rect content_rect_; |
83 float contents_scale_; | 83 float contents_scale_; |
84 size_t repeat_count_; | 84 size_t repeat_count_; |
85 bool is_solid_color_; | 85 bool is_solid_color_; |
86 base::TimeDelta best_time_; | 86 base::TimeDelta best_time_; |
87 }; | 87 }; |
88 | 88 |
89 class FixedInvalidationPictureLayerTilingClient | 89 class FixedInvalidationPictureLayerTilingClient |
90 : public PictureLayerTilingClient { | 90 : public PictureLayerTilingClient { |
91 public: | 91 public: |
92 FixedInvalidationPictureLayerTilingClient( | 92 FixedInvalidationPictureLayerTilingClient( |
93 PictureLayerTilingClient* base_client, | 93 PictureLayerTilingClient* base_client, |
94 const Region invalidation) | 94 const Region invalidation) |
95 : base_client_(base_client), invalidation_(invalidation) {} | 95 : base_client_(base_client), invalidation_(invalidation) {} |
96 | 96 |
97 scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling, | 97 scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling, |
98 const gfx::Rect& content_rect) override { | 98 const gfx::Rect& content_rect) override { |
99 return base_client_->CreateTile(tiling, content_rect); | 99 return base_client_->CreateTile(tiling, content_rect); |
100 } | 100 } |
101 | 101 |
102 PicturePileImpl* GetPile() override { return base_client_->GetPile(); } | 102 RasterSource* GetRasterSource() override { |
| 103 return base_client_->GetRasterSource(); |
| 104 } |
103 | 105 |
104 gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override { | 106 gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override { |
105 return base_client_->CalculateTileSize(content_bounds); | 107 return base_client_->CalculateTileSize(content_bounds); |
106 } | 108 } |
107 | 109 |
108 // This is the only function that returns something different from the base | 110 // This is the only function that returns something different from the base |
109 // client. Avoids sharing tiles in this area. | 111 // client. Avoids sharing tiles in this area. |
110 const Region* GetPendingInvalidation() override { return &invalidation_; } | 112 const Region* GetPendingInvalidation() override { return &invalidation_; } |
111 | 113 |
112 const PictureLayerTiling* GetPendingOrActiveTwinTiling( | 114 const PictureLayerTiling* GetPendingOrActiveTwinTiling( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 217 |
216 PictureLayerTiling* tiling = | 218 PictureLayerTiling* tiling = |
217 tiling_set.AddTiling(layer->contents_scale_x(), layer->bounds()); | 219 tiling_set.AddTiling(layer->contents_scale_x(), layer->bounds()); |
218 tiling->CreateAllTilesForTesting(); | 220 tiling->CreateAllTilesForTesting(); |
219 for (PictureLayerTiling::CoverageIterator it( | 221 for (PictureLayerTiling::CoverageIterator it( |
220 tiling, layer->contents_scale_x(), layer->visible_content_rect()); | 222 tiling, layer->contents_scale_x(), layer->visible_content_rect()); |
221 it; | 223 it; |
222 ++it) { | 224 ++it) { |
223 DCHECK(*it); | 225 DCHECK(*it); |
224 | 226 |
225 PicturePileImpl* picture_pile = (*it)->picture_pile(); | 227 RasterSource* raster_source = (*it)->raster_source(); |
226 gfx::Rect content_rect = (*it)->content_rect(); | 228 gfx::Rect content_rect = (*it)->content_rect(); |
227 float contents_scale = (*it)->contents_scale(); | 229 float contents_scale = (*it)->contents_scale(); |
228 | 230 |
229 scoped_refptr<BenchmarkRasterTask> benchmark_raster_task( | 231 scoped_refptr<BenchmarkRasterTask> benchmark_raster_task( |
230 new BenchmarkRasterTask(picture_pile, | 232 new BenchmarkRasterTask(raster_source, |
231 content_rect, | 233 content_rect, |
232 contents_scale, | 234 contents_scale, |
233 rasterize_repeat_count_)); | 235 rasterize_repeat_count_)); |
234 | 236 |
235 TaskGraph graph; | 237 TaskGraph graph; |
236 | 238 |
237 graph.nodes.push_back( | 239 graph.nodes.push_back( |
238 TaskGraph::Node(benchmark_raster_task.get(), | 240 TaskGraph::Node(benchmark_raster_task.get(), |
239 RasterWorkerPool::kBenchmarkRasterTaskPriority, | 241 RasterWorkerPool::kBenchmarkRasterTaskPriority, |
240 0u)); | 242 0u)); |
(...skipping 27 matching lines...) Expand all Loading... |
268 pixels_rasterized_with_non_solid_color(0), | 270 pixels_rasterized_with_non_solid_color(0), |
269 pixels_rasterized_as_opaque(0), | 271 pixels_rasterized_as_opaque(0), |
270 total_layers(0), | 272 total_layers(0), |
271 total_picture_layers(0), | 273 total_picture_layers(0), |
272 total_picture_layers_with_no_content(0), | 274 total_picture_layers_with_no_content(0), |
273 total_picture_layers_off_screen(0) {} | 275 total_picture_layers_off_screen(0) {} |
274 | 276 |
275 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} | 277 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} |
276 | 278 |
277 } // namespace cc | 279 } // namespace cc |
OLD | NEW |