| 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/tile_task_worker_pool.h" | 15 #include "cc/resources/tile_task_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 "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const int kDefaultRasterizeRepeatCount = 100; | 25 const int kDefaultRasterizeRepeatCount = 100; |
| 26 | 26 |
| 27 class BenchmarkRasterTask : public Task { | 27 void RunBenchmark(RasterSource* raster_source, |
| 28 public: | 28 const gfx::Rect& content_rect, |
| 29 BenchmarkRasterTask(RasterSource* raster_source, | 29 float contents_scale, |
| 30 const gfx::Rect& content_rect, | 30 size_t repeat_count, |
| 31 float contents_scale, | 31 base::TimeDelta* min_time, |
| 32 size_t repeat_count) | 32 bool* is_solid_color) { |
| 33 : raster_source_(raster_source), | 33 // Parameters for LapTimer. |
| 34 content_rect_(content_rect), | 34 const int kTimeLimitMillis = 1; |
| 35 contents_scale_(contents_scale), | 35 const int kWarmupRuns = 0; |
| 36 repeat_count_(repeat_count), | 36 const int kTimeCheckInterval = 1; |
| 37 is_solid_color_(false), | |
| 38 best_time_(base::TimeDelta::Max()) {} | |
| 39 | 37 |
| 40 // Overridden from Task: | 38 *min_time = base::TimeDelta::Max(); |
| 41 void RunOnWorkerThread() override { | 39 for (size_t i = 0; i < repeat_count; ++i) { |
| 42 // Parameters for LapTimer. | 40 // Run for a minimum amount of time to avoid problems with timer |
| 43 const int kTimeLimitMillis = 1; | 41 // quantization when the layer is very small. |
| 44 const int kWarmupRuns = 0; | 42 LapTimer timer(kWarmupRuns, |
| 45 const int kTimeCheckInterval = 1; | 43 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 44 kTimeCheckInterval); |
| 45 do { |
| 46 SkBitmap bitmap; |
| 47 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect.width(), |
| 48 content_rect.height())); |
| 49 SkCanvas canvas(bitmap); |
| 50 RasterSource::SolidColorAnalysis analysis; |
| 46 | 51 |
| 47 for (size_t i = 0; i < repeat_count_; ++i) { | 52 raster_source->PerformSolidColorAnalysis(content_rect, contents_scale, |
| 48 // Run for a minimum amount of time to avoid problems with timer | 53 &analysis); |
| 49 // quantization when the layer is very small. | 54 raster_source->PlaybackToCanvas(&canvas, content_rect, contents_scale); |
| 50 LapTimer timer(kWarmupRuns, | |
| 51 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | |
| 52 kTimeCheckInterval); | |
| 53 do { | |
| 54 SkBitmap bitmap; | |
| 55 bitmap.allocPixels(SkImageInfo::MakeN32Premul(content_rect_.width(), | |
| 56 content_rect_.height())); | |
| 57 SkCanvas canvas(bitmap); | |
| 58 RasterSource::SolidColorAnalysis analysis; | |
| 59 | 55 |
| 60 raster_source_->PerformSolidColorAnalysis(content_rect_, | 56 *is_solid_color = analysis.is_solid_color; |
| 61 contents_scale_, &analysis); | |
| 62 raster_source_->PlaybackToCanvas(&canvas, content_rect_, | |
| 63 contents_scale_); | |
| 64 | 57 |
| 65 is_solid_color_ = analysis.is_solid_color; | 58 timer.NextLap(); |
| 66 | 59 } while (!timer.HasTimeLimitExpired()); |
| 67 timer.NextLap(); | 60 base::TimeDelta duration = |
| 68 } while (!timer.HasTimeLimitExpired()); | 61 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
| 69 base::TimeDelta duration = | 62 if (duration < *min_time) |
| 70 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 63 *min_time = duration; |
| 71 if (duration < best_time_) | |
| 72 best_time_ = duration; | |
| 73 } | |
| 74 } | 64 } |
| 75 | 65 } |
| 76 bool IsSolidColor() const { return is_solid_color_; } | |
| 77 base::TimeDelta GetBestTime() const { return best_time_; } | |
| 78 | |
| 79 private: | |
| 80 ~BenchmarkRasterTask() override {} | |
| 81 | |
| 82 RasterSource* raster_source_; | |
| 83 gfx::Rect content_rect_; | |
| 84 float contents_scale_; | |
| 85 size_t repeat_count_; | |
| 86 bool is_solid_color_; | |
| 87 base::TimeDelta best_time_; | |
| 88 }; | |
| 89 | 66 |
| 90 class FixedInvalidationPictureLayerTilingClient | 67 class FixedInvalidationPictureLayerTilingClient |
| 91 : public PictureLayerTilingClient { | 68 : public PictureLayerTilingClient { |
| 92 public: | 69 public: |
| 93 FixedInvalidationPictureLayerTilingClient( | 70 FixedInvalidationPictureLayerTilingClient( |
| 94 PictureLayerTilingClient* base_client, | 71 PictureLayerTilingClient* base_client, |
| 95 const Region invalidation) | 72 const Region invalidation) |
| 96 : base_client_(base_client), invalidation_(invalidation) {} | 73 : base_client_(base_client), invalidation_(invalidation) {} |
| 97 | 74 |
| 98 scoped_refptr<Tile> CreateTile(float contents_scale, | 75 scoped_refptr<Tile> CreateTile(float contents_scale, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 rasterize_results_.total_picture_layers++; | 166 rasterize_results_.total_picture_layers++; |
| 190 if (!layer->CanHaveTilings()) { | 167 if (!layer->CanHaveTilings()) { |
| 191 rasterize_results_.total_picture_layers_with_no_content++; | 168 rasterize_results_.total_picture_layers_with_no_content++; |
| 192 return; | 169 return; |
| 193 } | 170 } |
| 194 if (layer->visible_content_rect().IsEmpty()) { | 171 if (layer->visible_content_rect().IsEmpty()) { |
| 195 rasterize_results_.total_picture_layers_off_screen++; | 172 rasterize_results_.total_picture_layers_off_screen++; |
| 196 return; | 173 return; |
| 197 } | 174 } |
| 198 | 175 |
| 199 TaskGraphRunner* task_graph_runner = TileTaskWorkerPool::GetTaskGraphRunner(); | |
| 200 DCHECK(task_graph_runner); | |
| 201 | |
| 202 if (!task_namespace_.IsValid()) | |
| 203 task_namespace_ = task_graph_runner->GetNamespaceToken(); | |
| 204 | |
| 205 FixedInvalidationPictureLayerTilingClient client( | 176 FixedInvalidationPictureLayerTilingClient client( |
| 206 layer, gfx::Rect(layer->content_bounds())); | 177 layer, gfx::Rect(layer->content_bounds())); |
| 207 | 178 |
| 208 // In this benchmark, we will create a local tiling set and measure how long | 179 // In this benchmark, we will create a local tiling set and measure how long |
| 209 // it takes to rasterize content. As such, the actual settings used here don't | 180 // it takes to rasterize content. As such, the actual settings used here don't |
| 210 // really matter. | 181 // really matter. |
| 211 const LayerTreeSettings& settings = layer->layer_tree_impl()->settings(); | 182 const LayerTreeSettings& settings = layer->layer_tree_impl()->settings(); |
| 212 scoped_ptr<PictureLayerTilingSet> tiling_set = PictureLayerTilingSet::Create( | 183 scoped_ptr<PictureLayerTilingSet> tiling_set = PictureLayerTilingSet::Create( |
| 213 &client, settings.max_tiles_for_interest_area, | 184 &client, settings.max_tiles_for_interest_area, |
| 214 settings.skewport_target_time_in_seconds, | 185 settings.skewport_target_time_in_seconds, |
| 215 settings.skewport_extrapolation_limit_in_content_pixels); | 186 settings.skewport_extrapolation_limit_in_content_pixels); |
| 216 | 187 |
| 217 PictureLayerTiling* tiling = tiling_set->AddTiling(layer->contents_scale_x(), | 188 PictureLayerTiling* tiling = tiling_set->AddTiling(layer->contents_scale_x(), |
| 218 layer->GetRasterSource()); | 189 layer->GetRasterSource()); |
| 219 tiling->CreateAllTilesForTesting(); | 190 tiling->CreateAllTilesForTesting(); |
| 220 for (PictureLayerTiling::CoverageIterator it( | 191 for (PictureLayerTiling::CoverageIterator it( |
| 221 tiling, layer->contents_scale_x(), layer->visible_content_rect()); | 192 tiling, layer->contents_scale_x(), layer->visible_content_rect()); |
| 222 it; | 193 it; |
| 223 ++it) { | 194 ++it) { |
| 224 DCHECK(*it); | 195 DCHECK(*it); |
| 225 | 196 |
| 226 RasterSource* raster_source = (*it)->raster_source(); | 197 RasterSource* raster_source = (*it)->raster_source(); |
| 227 gfx::Rect content_rect = (*it)->content_rect(); | 198 gfx::Rect content_rect = (*it)->content_rect(); |
| 228 float contents_scale = (*it)->contents_scale(); | 199 float contents_scale = (*it)->contents_scale(); |
| 229 | 200 |
| 230 scoped_refptr<BenchmarkRasterTask> benchmark_raster_task( | 201 base::TimeDelta min_time; |
| 231 new BenchmarkRasterTask(raster_source, | 202 bool is_solid_color = false; |
| 232 content_rect, | 203 RunBenchmark(raster_source, content_rect, contents_scale, |
| 233 contents_scale, | 204 rasterize_repeat_count_, &min_time, &is_solid_color); |
| 234 rasterize_repeat_count_)); | |
| 235 | |
| 236 TaskGraph graph; | |
| 237 | |
| 238 graph.nodes.push_back( | |
| 239 TaskGraph::Node(benchmark_raster_task.get(), | |
| 240 TileTaskWorkerPool::kBenchmarkTaskPriority, 0u)); | |
| 241 | |
| 242 task_graph_runner->ScheduleTasks(task_namespace_, &graph); | |
| 243 task_graph_runner->WaitForTasksToFinishRunning(task_namespace_); | |
| 244 | |
| 245 Task::Vector completed_tasks; | |
| 246 task_graph_runner->CollectCompletedTasks(task_namespace_, &completed_tasks); | |
| 247 DCHECK_EQ(1u, completed_tasks.size()); | |
| 248 DCHECK_EQ(completed_tasks[0], benchmark_raster_task); | |
| 249 | 205 |
| 250 int tile_size = content_rect.width() * content_rect.height(); | 206 int tile_size = content_rect.width() * content_rect.height(); |
| 251 base::TimeDelta min_time = benchmark_raster_task->GetBestTime(); | |
| 252 bool is_solid_color = benchmark_raster_task->IsSolidColor(); | |
| 253 | |
| 254 if (layer->contents_opaque()) | 207 if (layer->contents_opaque()) |
| 255 rasterize_results_.pixels_rasterized_as_opaque += tile_size; | 208 rasterize_results_.pixels_rasterized_as_opaque += tile_size; |
| 256 | 209 |
| 257 if (!is_solid_color) { | 210 if (!is_solid_color) |
| 258 rasterize_results_.pixels_rasterized_with_non_solid_color += tile_size; | 211 rasterize_results_.pixels_rasterized_with_non_solid_color += tile_size; |
| 259 } | |
| 260 | 212 |
| 261 rasterize_results_.pixels_rasterized += tile_size; | 213 rasterize_results_.pixels_rasterized += tile_size; |
| 262 rasterize_results_.total_best_time += min_time; | 214 rasterize_results_.total_best_time += min_time; |
| 263 } | 215 } |
| 264 | 216 |
| 265 const RasterSource* layer_raster_source = layer->GetRasterSource(); | 217 const RasterSource* layer_raster_source = layer->GetRasterSource(); |
| 266 rasterize_results_.total_memory_usage += | 218 rasterize_results_.total_memory_usage += |
| 267 layer_raster_source->GetPictureMemoryUsage(); | 219 layer_raster_source->GetPictureMemoryUsage(); |
| 268 } | 220 } |
| 269 | 221 |
| 270 RasterizeAndRecordBenchmarkImpl::RasterizeResults::RasterizeResults() | 222 RasterizeAndRecordBenchmarkImpl::RasterizeResults::RasterizeResults() |
| 271 : pixels_rasterized(0), | 223 : pixels_rasterized(0), |
| 272 pixels_rasterized_with_non_solid_color(0), | 224 pixels_rasterized_with_non_solid_color(0), |
| 273 pixels_rasterized_as_opaque(0), | 225 pixels_rasterized_as_opaque(0), |
| 274 total_memory_usage(0), | 226 total_memory_usage(0), |
| 275 total_layers(0), | 227 total_layers(0), |
| 276 total_picture_layers(0), | 228 total_picture_layers(0), |
| 277 total_picture_layers_with_no_content(0), | 229 total_picture_layers_with_no_content(0), |
| 278 total_picture_layers_off_screen(0) { | 230 total_picture_layers_off_screen(0) { |
| 279 } | 231 } |
| 280 | 232 |
| 281 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} | 233 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} |
| 282 | 234 |
| 283 } // namespace cc | 235 } // namespace cc |
| OLD | NEW |