Chromium Code Reviews| 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 weak_ptr_factory_(this) { | |
| 44 base::DictionaryValue* settings = NULL; | |
| 45 settings_->GetAsDictionary(&settings); | |
| 46 if (!settings) | |
| 47 return; | |
| 48 | |
| 49 if (settings->HasKey("record_repeat_count")) | |
| 50 settings->GetInteger("record_repeat_count", &record_repeat_count_); | |
| 51 } | |
| 52 | |
| 53 RasterizeAndRecordBenchmark::~RasterizeAndRecordBenchmark() { | |
| 54 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 55 } | |
| 56 | |
| 57 void RasterizeAndRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) { | |
| 58 LayerTreeHostCommon::CallFunctionForSubtree( | |
| 59 host->root_layer(), | |
| 60 base::Bind(&RasterizeAndRecordBenchmark::Run, base::Unretained(this))); | |
| 61 | |
| 62 DCHECK(!results_.get()); | |
| 63 results_ = make_scoped_ptr(new base::DictionaryValue); | |
| 64 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); | |
| 65 results_->SetDouble("record_time_ms", | |
| 66 record_results_.total_best_time.InMillisecondsF()); | |
| 67 main_thread_benchmark_done_ = true; | |
| 68 } | |
| 69 | |
| 70 void RasterizeAndRecordBenchmark::RecordRasterResults( | |
| 71 scoped_ptr<base::Value> results_value) { | |
| 72 DCHECK(main_thread_benchmark_done_); | |
| 73 | |
| 74 base::DictionaryValue* results = NULL; | |
| 75 results_value->GetAsDictionary(&results); | |
| 76 | |
| 77 DCHECK(results); | |
| 78 DCHECK(results->HasKey("pixels_rasterized")); | |
| 79 DCHECK(results->HasKey("rasterize_time_ms")); | |
| 80 | |
| 81 int pixels_rasterized; | |
| 82 results->GetInteger("pixels_rasterized", &pixels_rasterized); | |
| 83 double rasterize_time_ms; | |
| 84 results->GetDouble("rasterize_time_ms", &rasterize_time_ms); | |
| 85 | |
| 86 results_->SetInteger("pixels_rasterized", pixels_rasterized); | |
| 87 results_->SetDouble("rasterize_time_ms", rasterize_time_ms); | |
| 88 | |
| 89 NotifyDone(results_.PassAs<base::Value>()); | |
| 90 } | |
| 91 | |
| 92 scoped_ptr<MicroBenchmarkImpl> RasterizeAndRecordBenchmark::CreateBenchmarkImpl( | |
| 93 scoped_refptr<base::MessageLoopProxy> origin_loop) { | |
| 94 return scoped_ptr<MicroBenchmarkImpl>(new RasterizeAndRecordBenchmarkImpl( | |
| 95 origin_loop, | |
| 96 settings_.get(), | |
| 97 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, | |
| 98 weak_ptr_factory_.GetWeakPtr()))); | |
| 99 } | |
| 100 | |
| 101 void RasterizeAndRecordBenchmark::Run(Layer* layer) { | |
| 102 layer->RunMicroBenchmark(this); | |
| 103 } | |
| 104 | |
| 105 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { | |
| 106 ContentLayerClient* painter = layer->client(); | |
| 107 gfx::Size content_bounds = layer->content_bounds(); | |
| 108 | |
| 109 SkTileGridPicture::TileGridInfo tile_grid_info; | |
|
enne (OOO)
2013/11/14 00:24:05
Maybe add this as a static accessor on cc::Picture
vmpstr
2013/11/14 19:38:24
Unfortunately we don't store tile_grid_info on the
enne (OOO)
2013/11/14 19:44:59
They could both get it from a static accessor on c
vmpstr
2013/11/14 20:04:35
Done. (added it to PicturePileBase since that's wh
| |
| 110 tile_grid_info.fTileInterval.set(kTileGridSize - 2 * kTileGridBorder, | |
| 111 kTileGridSize - 2 * kTileGridBorder); | |
| 112 tile_grid_info.fMargin.set(kTileGridBorder, kTileGridBorder); | |
| 113 tile_grid_info.fOffset.set(-kTileGridBorder, -kTileGridBorder); | |
| 114 | |
| 115 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( | |
| 116 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); | |
| 117 if (visible_content_rect.IsEmpty()) | |
| 118 return; | |
| 119 | |
| 120 scoped_refptr<Picture> picture = Picture::Create(visible_content_rect); | |
| 121 | |
| 122 base::TimeDelta min_time = | |
| 123 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); | |
| 124 for (int i = 0; i < record_repeat_count_; ++i) { | |
| 125 base::TimeTicks start = Now(); | |
| 126 picture->Record(painter, tile_grid_info); | |
| 127 base::TimeTicks end = Now(); | |
| 128 base::TimeDelta duration = end - start; | |
| 129 if (duration < min_time) | |
| 130 min_time = duration; | |
| 131 } | |
| 132 | |
| 133 record_results_.pixels_recorded += | |
| 134 visible_content_rect.width() * visible_content_rect.height(); | |
| 135 record_results_.total_best_time += min_time; | |
| 136 } | |
| 137 | |
| 138 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | |
| 139 : pixels_recorded(0) {} | |
| 140 | |
| 141 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | |
| 142 | |
| 143 } // namespace cc | |
| OLD | NEW |