OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/debug/rasterize_and_record_benchmark.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <limits> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/values.h" |
| 12 #include "cc/debug/rasterize_and_record_benchmark_impl.h" |
| 13 #include "cc/layers/layer.h" |
| 14 #include "cc/layers/picture_layer.h" |
| 15 #include "cc/trees/layer_tree_host.h" |
| 16 #include "cc/trees/layer_tree_host_common.h" |
| 17 #include "ui/gfx/rect.h" |
| 18 |
| 19 namespace cc { |
| 20 |
| 21 namespace { |
| 22 |
| 23 const int kTileGridSize = 512; |
| 24 const int kTileGridBorder = 1; |
| 25 |
| 26 const int kDefaultRecordRepeatCount = 100; |
| 27 |
| 28 base::TimeTicks Now() { |
| 29 return base::TimeTicks::IsThreadNowSupported() |
| 30 ? base::TimeTicks::ThreadNow() |
| 31 : base::TimeTicks::HighResNow(); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( |
| 37 scoped_ptr<base::Value> value, |
| 38 const MicroBenchmark::DoneCallback& callback) |
| 39 : MicroBenchmark(callback), |
| 40 record_repeat_count_(kDefaultRecordRepeatCount), |
| 41 settings_(value.Pass()), |
| 42 main_thread_benchmark_done_(false) { |
| 43 base::DictionaryValue* settings = NULL; |
| 44 settings_->GetAsDictionary(&settings); |
| 45 if (!settings) |
| 46 return; |
| 47 |
| 48 if (settings->HasKey("record_repeat_count")) |
| 49 settings->GetInteger("record_repeat_count", &record_repeat_count_); |
| 50 } |
| 51 |
| 52 RasterizeAndRecordBenchmark::~RasterizeAndRecordBenchmark() {} |
| 53 |
| 54 void RasterizeAndRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
| 55 LayerTreeHostCommon::CallFunctionForSubtree( |
| 56 host->root_layer(), |
| 57 base::Bind(&RasterizeAndRecordBenchmark::Run, base::Unretained(this))); |
| 58 |
| 59 DCHECK(!results_.get()); |
| 60 results_ = make_scoped_ptr(new base::DictionaryValue); |
| 61 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); |
| 62 results_->SetDouble("record_time_ms", |
| 63 record_results_.total_best_time.InMillisecondsF()); |
| 64 main_thread_benchmark_done_ = true; |
| 65 } |
| 66 |
| 67 void RasterizeAndRecordBenchmark::RecordRasterResults( |
| 68 scoped_ptr<base::Value> results_value) { |
| 69 DCHECK(main_thread_benchmark_done_); |
| 70 |
| 71 base::DictionaryValue* results = NULL; |
| 72 results_value->GetAsDictionary(&results); |
| 73 |
| 74 DCHECK(results); |
| 75 DCHECK(results->HasKey("pixels_rasterized")); |
| 76 DCHECK(results->HasKey("rasterize_time_ms")); |
| 77 |
| 78 int pixels_rasterized; |
| 79 results->GetInteger("pixels_rasterized", &pixels_rasterized); |
| 80 double rasterize_time_ms; |
| 81 results->GetDouble("rasterize_time_ms", &rasterize_time_ms); |
| 82 |
| 83 results_->SetInteger("pixels_rasterized", pixels_rasterized); |
| 84 results_->SetDouble("rasterize_time_ms", rasterize_time_ms); |
| 85 |
| 86 NotifyDone(results_.PassAs<base::Value>()); |
| 87 } |
| 88 |
| 89 scoped_ptr<MicroBenchmarkImpl> RasterizeAndRecordBenchmark::CreateBenchmarkImpl( |
| 90 scoped_refptr<base::MessageLoopProxy> origin_loop) { |
| 91 return scoped_ptr<MicroBenchmarkImpl>(new RasterizeAndRecordBenchmarkImpl( |
| 92 origin_loop, |
| 93 settings_.get(), |
| 94 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, |
| 95 base::Unretained(this)))); |
| 96 } |
| 97 |
| 98 void RasterizeAndRecordBenchmark::Run(Layer* layer) { |
| 99 layer->RunMicroBenchmark(this); |
| 100 } |
| 101 |
| 102 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { |
| 103 ContentLayerClient* painter = layer->client(); |
| 104 gfx::Size content_bounds = layer->content_bounds(); |
| 105 |
| 106 SkTileGridPicture::TileGridInfo tile_grid_info; |
| 107 tile_grid_info.fTileInterval.set(kTileGridSize - 2 * kTileGridBorder, |
| 108 kTileGridSize - 2 * kTileGridBorder); |
| 109 tile_grid_info.fMargin.set(kTileGridBorder, kTileGridBorder); |
| 110 tile_grid_info.fOffset.set(-kTileGridBorder, -kTileGridBorder); |
| 111 |
| 112 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( |
| 113 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); |
| 114 if (visible_content_rect.IsEmpty()) |
| 115 return; |
| 116 |
| 117 scoped_refptr<Picture> picture = Picture::Create(visible_content_rect); |
| 118 |
| 119 base::TimeDelta min_time = |
| 120 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); |
| 121 for (int i = 0; i < record_repeat_count_; ++i) { |
| 122 base::TimeTicks start = Now(); |
| 123 picture->Record(painter, tile_grid_info); |
| 124 base::TimeTicks end = Now(); |
| 125 base::TimeDelta duration = end - start; |
| 126 if (duration < min_time) |
| 127 min_time = duration; |
| 128 } |
| 129 |
| 130 record_results_.pixels_recorded += |
| 131 visible_content_rect.width() * visible_content_rect.height(); |
| 132 record_results_.total_best_time += min_time; |
| 133 } |
| 134 |
| 135 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
| 136 : pixels_recorded(0) {} |
| 137 |
| 138 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
| 139 |
| 140 } // namespace cc |
OLD | NEW |