| 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 | 76 |
| 76 DCHECK(!results_.get()); | 77 DCHECK(!results_.get()); |
| 77 results_ = make_scoped_ptr(new base::DictionaryValue); | 78 results_ = base::WrapUnique(new base::DictionaryValue); |
| 78 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); | 79 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); |
| 79 results_->SetInteger("picture_memory_usage", | 80 results_->SetInteger("picture_memory_usage", |
| 80 static_cast<int>(record_results_.bytes_used)); | 81 static_cast<int>(record_results_.bytes_used)); |
| 81 | 82 |
| 82 for (int i = 0; i < RecordingSource::RECORDING_MODE_COUNT; i++) { | 83 for (int i = 0; i < RecordingSource::RECORDING_MODE_COUNT; i++) { |
| 83 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); | 84 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); |
| 84 results_->SetDouble(name, | 85 results_->SetDouble(name, |
| 85 record_results_.total_best_time[i].InMillisecondsF()); | 86 record_results_.total_best_time[i].InMillisecondsF()); |
| 86 } | 87 } |
| 87 main_thread_benchmark_done_ = true; | 88 main_thread_benchmark_done_ = true; |
| 88 } | 89 } |
| 89 | 90 |
| 90 void RasterizeAndRecordBenchmark::RecordRasterResults( | 91 void RasterizeAndRecordBenchmark::RecordRasterResults( |
| 91 scoped_ptr<base::Value> results_value) { | 92 std::unique_ptr<base::Value> results_value) { |
| 92 DCHECK(main_thread_benchmark_done_); | 93 DCHECK(main_thread_benchmark_done_); |
| 93 | 94 |
| 94 base::DictionaryValue* results = nullptr; | 95 base::DictionaryValue* results = nullptr; |
| 95 results_value->GetAsDictionary(&results); | 96 results_value->GetAsDictionary(&results); |
| 96 DCHECK(results); | 97 DCHECK(results); |
| 97 | 98 |
| 98 results_->MergeDictionary(results); | 99 results_->MergeDictionary(results); |
| 99 | 100 |
| 100 NotifyDone(std::move(results_)); | 101 NotifyDone(std::move(results_)); |
| 101 } | 102 } |
| 102 | 103 |
| 103 scoped_ptr<MicroBenchmarkImpl> RasterizeAndRecordBenchmark::CreateBenchmarkImpl( | 104 std::unique_ptr<MicroBenchmarkImpl> |
| 105 RasterizeAndRecordBenchmark::CreateBenchmarkImpl( |
| 104 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) { | 106 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) { |
| 105 return make_scoped_ptr(new RasterizeAndRecordBenchmarkImpl( | 107 return base::WrapUnique(new RasterizeAndRecordBenchmarkImpl( |
| 106 origin_task_runner, settings_.get(), | 108 origin_task_runner, settings_.get(), |
| 107 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, | 109 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, |
| 108 weak_ptr_factory_.GetWeakPtr()))); | 110 weak_ptr_factory_.GetWeakPtr()))); |
| 109 } | 111 } |
| 110 | 112 |
| 111 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { | 113 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { |
| 112 DCHECK(host_); | 114 DCHECK(host_); |
| 113 | 115 |
| 114 if (!layer->DrawsContent()) | 116 if (!layer->DrawsContent()) |
| 115 return; | 117 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 | 191 |
| 190 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | 192 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
| 191 : pixels_recorded(0), bytes_used(0) { | 193 : pixels_recorded(0), bytes_used(0) { |
| 192 } | 194 } |
| 193 | 195 |
| 194 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | 196 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
| 195 | 197 |
| 196 } // namespace cc | 198 } // namespace cc |
| OLD | NEW |