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/micro_benchmark_controller.h" | 5 #include "cc/debug/micro_benchmark_controller.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "cc/debug/picture_record_benchmark.h" | 12 #include "cc/debug/picture_record_benchmark.h" |
12 #include "cc/debug/unittest_only_benchmark.h" | 13 #include "cc/debug/unittest_only_benchmark.h" |
13 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
| 15 #include "cc/trees/layer_tree_host_impl.h" |
14 | 16 |
15 namespace cc { | 17 namespace cc { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 scoped_ptr<MicroBenchmark> CreateBenchmark( | 21 scoped_ptr<MicroBenchmark> CreateBenchmark( |
20 const std::string& name, | 22 const std::string& name, |
21 scoped_ptr<base::Value> value, | 23 scoped_ptr<base::Value> value, |
22 const MicroBenchmark::DoneCallback& callback) { | 24 const MicroBenchmark::DoneCallback& callback) { |
23 if (name == "picture_record_benchmark") { | 25 if (name == "picture_record_benchmark") { |
(...skipping 12 matching lines...) Expand all Loading... |
36 typedef bool result_type; | 38 typedef bool result_type; |
37 | 39 |
38 result_type operator()(argument_type benchmark) const { | 40 result_type operator()(argument_type benchmark) const { |
39 return benchmark->IsDone(); | 41 return benchmark->IsDone(); |
40 } | 42 } |
41 }; | 43 }; |
42 | 44 |
43 } // namespace | 45 } // namespace |
44 | 46 |
45 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) | 47 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) |
46 : host_(host) { | 48 : host_(host), |
| 49 main_controller_message_loop_(base::MessageLoopProxy::current().get()) { |
47 DCHECK(host_); | 50 DCHECK(host_); |
48 } | 51 } |
49 | 52 |
50 MicroBenchmarkController::~MicroBenchmarkController() {} | 53 MicroBenchmarkController::~MicroBenchmarkController() {} |
51 | 54 |
52 bool MicroBenchmarkController::ScheduleRun( | 55 bool MicroBenchmarkController::ScheduleRun( |
53 const std::string& micro_benchmark_name, | 56 const std::string& micro_benchmark_name, |
54 scoped_ptr<base::Value> value, | 57 scoped_ptr<base::Value> value, |
55 const MicroBenchmark::DoneCallback& callback) { | 58 const MicroBenchmark::DoneCallback& callback) { |
56 scoped_ptr<MicroBenchmark> benchmark = | 59 scoped_ptr<MicroBenchmark> benchmark = |
57 CreateBenchmark(micro_benchmark_name, value.Pass(), callback); | 60 CreateBenchmark(micro_benchmark_name, value.Pass(), callback); |
58 if (benchmark.get()) { | 61 if (benchmark.get()) { |
59 benchmarks_.push_back(benchmark.Pass()); | 62 benchmarks_.push_back(benchmark.Pass()); |
60 host_->SetNeedsCommit(); | 63 host_->SetNeedsCommit(); |
61 return true; | 64 return true; |
62 } | 65 } |
63 return false; | 66 return false; |
64 } | 67 } |
65 | 68 |
| 69 void MicroBenchmarkController::ScheduleImplBenchmarks( |
| 70 LayerTreeHostImpl* host_impl) { |
| 71 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); |
| 72 it != benchmarks_.end(); |
| 73 ++it) { |
| 74 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; |
| 75 if (!(*it)->ProcessedForBenchmarkImpl()) { |
| 76 benchmark_impl = |
| 77 (*it)->GetBenchmarkImpl(main_controller_message_loop_); |
| 78 } |
| 79 |
| 80 if (benchmark_impl.get()) |
| 81 host_impl->ScheduleMicroBenchmark(benchmark_impl.Pass()); |
| 82 } |
| 83 } |
| 84 |
66 void MicroBenchmarkController::DidUpdateLayers() { | 85 void MicroBenchmarkController::DidUpdateLayers() { |
67 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); | 86 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); |
68 it != benchmarks_.end(); | 87 it != benchmarks_.end(); |
69 ++it) { | 88 ++it) { |
70 DCHECK(!(*it)->IsDone()); | 89 if (!(*it)->IsDone()) |
71 (*it)->DidUpdateLayers(host_); | 90 (*it)->DidUpdateLayers(host_); |
72 } | 91 } |
73 | 92 |
74 CleanUpFinishedBenchmarks(); | 93 CleanUpFinishedBenchmarks(); |
75 } | 94 } |
76 | 95 |
77 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { | 96 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { |
78 benchmarks_.erase( | 97 benchmarks_.erase( |
79 benchmarks_.partition(std::not1(IsDonePredicate())), | 98 benchmarks_.partition(std::not1(IsDonePredicate())), |
80 benchmarks_.end()); | 99 benchmarks_.end()); |
81 } | 100 } |
82 | 101 |
83 } // namespace cc | 102 } // namespace cc |
OLD | NEW |