| 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.h" | 5 #include "cc/debug/rasterize_and_record_benchmark.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "cc/debug/lap_timer.h" | 16 #include "cc/debug/lap_timer.h" |
| 16 #include "cc/debug/rasterize_and_record_benchmark_impl.h" | 17 #include "cc/debug/rasterize_and_record_benchmark_impl.h" |
| 17 #include "cc/layers/content_layer_client.h" | 18 #include "cc/layers/content_layer_client.h" |
| 18 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
| 19 #include "cc/layers/picture_layer.h" | 20 #include "cc/layers/picture_layer.h" |
| 20 #include "cc/playback/display_item_list.h" | 21 #include "cc/playback/display_item_list.h" |
| 21 #include "cc/playback/recording_source.h" | 22 #include "cc/playback/recording_source.h" |
| 22 #include "cc/trees/layer_tree_host.h" | 23 #include "cc/trees/layer_tree_host.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 "", | 41 "", |
| 41 "_sk_null_canvas", | 42 "_sk_null_canvas", |
| 42 "_painting_disabled", | 43 "_painting_disabled", |
| 43 "_caching_disabled", | 44 "_caching_disabled", |
| 44 "_construction_disabled", | 45 "_construction_disabled", |
| 45 "_subsequence_caching_disabled"}; | 46 "_subsequence_caching_disabled"}; |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( | 50 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( |
| 50 scoped_ptr<base::Value> value, | 51 std::unique_ptr<base::Value> value, |
| 51 const MicroBenchmark::DoneCallback& callback) | 52 const MicroBenchmark::DoneCallback& callback) |
| 52 : MicroBenchmark(callback), | 53 : MicroBenchmark(callback), |
| 53 record_repeat_count_(kDefaultRecordRepeatCount), | 54 record_repeat_count_(kDefaultRecordRepeatCount), |
| 54 settings_(std::move(value)), | 55 settings_(std::move(value)), |
| 55 main_thread_benchmark_done_(false), | 56 main_thread_benchmark_done_(false), |
| 56 host_(nullptr), | 57 host_(nullptr), |
| 57 weak_ptr_factory_(this) { | 58 weak_ptr_factory_(this) { |
| 58 base::DictionaryValue* settings = nullptr; | 59 base::DictionaryValue* settings = nullptr; |
| 59 settings_->GetAsDictionary(&settings); | 60 settings_->GetAsDictionary(&settings); |
| 60 if (!settings) | 61 if (!settings) |
| 61 return; | 62 return; |
| 62 | 63 |
| 63 if (settings->HasKey("record_repeat_count")) | 64 if (settings->HasKey("record_repeat_count")) |
| 64 settings->GetInteger("record_repeat_count", &record_repeat_count_); | 65 settings->GetInteger("record_repeat_count", &record_repeat_count_); |
| 65 } | 66 } |
| 66 | 67 |
| 67 RasterizeAndRecordBenchmark::~RasterizeAndRecordBenchmark() { | 68 RasterizeAndRecordBenchmark::~RasterizeAndRecordBenchmark() { |
| 68 weak_ptr_factory_.InvalidateWeakPtrs(); | 69 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void RasterizeAndRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) { | 72 void RasterizeAndRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
| 72 host_ = host; | 73 host_ = host; |
| 73 LayerTreeHostCommon::CallFunctionForEveryLayer( | 74 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 74 host, [this](Layer* layer) { layer->RunMicroBenchmark(this); }, | 75 host, [this](Layer* layer) { layer->RunMicroBenchmark(this); }, |
| 75 CallFunctionLayerType::ALL_LAYERS); | 76 CallFunctionLayerType::ALL_LAYERS); |
| 76 | 77 |
| 77 DCHECK(!results_.get()); | 78 DCHECK(!results_.get()); |
| 78 results_ = make_scoped_ptr(new base::DictionaryValue); | 79 results_ = base::WrapUnique(new base::DictionaryValue); |
| 79 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); | 80 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); |
| 80 results_->SetInteger("picture_memory_usage", | 81 results_->SetInteger("picture_memory_usage", |
| 81 static_cast<int>(record_results_.bytes_used)); | 82 static_cast<int>(record_results_.bytes_used)); |
| 82 | 83 |
| 83 for (int i = 0; i < RecordingSource::RECORDING_MODE_COUNT; i++) { | 84 for (int i = 0; i < RecordingSource::RECORDING_MODE_COUNT; i++) { |
| 84 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); | 85 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); |
| 85 results_->SetDouble(name, | 86 results_->SetDouble(name, |
| 86 record_results_.total_best_time[i].InMillisecondsF()); | 87 record_results_.total_best_time[i].InMillisecondsF()); |
| 87 } | 88 } |
| 88 main_thread_benchmark_done_ = true; | 89 main_thread_benchmark_done_ = true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void RasterizeAndRecordBenchmark::RecordRasterResults( | 92 void RasterizeAndRecordBenchmark::RecordRasterResults( |
| 92 scoped_ptr<base::Value> results_value) { | 93 std::unique_ptr<base::Value> results_value) { |
| 93 DCHECK(main_thread_benchmark_done_); | 94 DCHECK(main_thread_benchmark_done_); |
| 94 | 95 |
| 95 base::DictionaryValue* results = nullptr; | 96 base::DictionaryValue* results = nullptr; |
| 96 results_value->GetAsDictionary(&results); | 97 results_value->GetAsDictionary(&results); |
| 97 DCHECK(results); | 98 DCHECK(results); |
| 98 | 99 |
| 99 results_->MergeDictionary(results); | 100 results_->MergeDictionary(results); |
| 100 | 101 |
| 101 NotifyDone(std::move(results_)); | 102 NotifyDone(std::move(results_)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 scoped_ptr<MicroBenchmarkImpl> RasterizeAndRecordBenchmark::CreateBenchmarkImpl( | 105 std::unique_ptr<MicroBenchmarkImpl> |
| 106 RasterizeAndRecordBenchmark::CreateBenchmarkImpl( |
| 105 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) { | 107 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) { |
| 106 return make_scoped_ptr(new RasterizeAndRecordBenchmarkImpl( | 108 return base::WrapUnique(new RasterizeAndRecordBenchmarkImpl( |
| 107 origin_task_runner, settings_.get(), | 109 origin_task_runner, settings_.get(), |
| 108 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, | 110 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, |
| 109 weak_ptr_factory_.GetWeakPtr()))); | 111 weak_ptr_factory_.GetWeakPtr()))); |
| 110 } | 112 } |
| 111 | 113 |
| 112 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { | 114 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { |
| 113 DCHECK(host_); | 115 DCHECK(host_); |
| 114 | 116 |
| 115 if (!layer->DrawsContent()) | 117 if (!layer->DrawsContent()) |
| 116 return; | 118 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 190 } |
| 189 } | 191 } |
| 190 | 192 |
| 191 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | 193 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
| 192 : pixels_recorded(0), bytes_used(0) { | 194 : pixels_recorded(0), bytes_used(0) { |
| 193 } | 195 } |
| 194 | 196 |
| 195 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | 197 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
| 196 | 198 |
| 197 } // namespace cc | 199 } // namespace cc |
| OLD | NEW |