OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/invalidation_benchmark.h" | 5 #include "cc/debug/invalidation_benchmark.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
11 | 11 |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
15 #include "cc/layers/picture_layer.h" | 15 #include "cc/layers/picture_layer.h" |
16 #include "cc/trees/draw_property_utils.h" | 16 #include "cc/trees/draw_property_utils.h" |
17 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
18 #include "cc/trees/layer_tree_host_common.h" | 18 #include "cc/trees/layer_tree_host_common.h" |
19 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char* kDefaultInvalidationMode = "viewport"; | 25 const char* kDefaultInvalidationMode = "viewport"; |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 InvalidationBenchmark::InvalidationBenchmark( | 29 InvalidationBenchmark::InvalidationBenchmark( |
30 scoped_ptr<base::Value> value, | 30 std::unique_ptr<base::Value> value, |
31 const MicroBenchmark::DoneCallback& callback) | 31 const MicroBenchmark::DoneCallback& callback) |
32 : MicroBenchmark(callback), seed_(0) { | 32 : MicroBenchmark(callback), seed_(0) { |
33 base::DictionaryValue* settings = nullptr; | 33 base::DictionaryValue* settings = nullptr; |
34 value->GetAsDictionary(&settings); | 34 value->GetAsDictionary(&settings); |
35 if (!settings) | 35 if (!settings) |
36 return; | 36 return; |
37 | 37 |
38 std::string mode_string = kDefaultInvalidationMode; | 38 std::string mode_string = kDefaultInvalidationMode; |
39 | 39 |
40 if (settings->HasKey("mode")) | 40 if (settings->HasKey("mode")) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 break; | 104 break; |
105 } | 105 } |
106 case VIEWPORT: { | 106 case VIEWPORT: { |
107 // Invalidate entire viewport. | 107 // Invalidate entire viewport. |
108 layer->SetNeedsDisplayRect(layer->visible_layer_rect_for_testing()); | 108 layer->SetNeedsDisplayRect(layer->visible_layer_rect_for_testing()); |
109 break; | 109 break; |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 bool InvalidationBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { | 114 bool InvalidationBenchmark::ProcessMessage(std::unique_ptr<base::Value> value) { |
115 base::DictionaryValue* message = nullptr; | 115 base::DictionaryValue* message = nullptr; |
116 value->GetAsDictionary(&message); | 116 value->GetAsDictionary(&message); |
117 if (!message) | 117 if (!message) |
118 return false; | 118 return false; |
119 | 119 |
120 bool notify_done; | 120 bool notify_done; |
121 if (message->HasKey("notify_done")) { | 121 if (message->HasKey("notify_done")) { |
122 message->GetBoolean("notify_done", ¬ify_done); | 122 message->GetBoolean("notify_done", ¬ify_done); |
123 if (notify_done) | 123 if (notify_done) |
124 NotifyDone(base::Value::CreateNullValue()); | 124 NotifyDone(base::Value::CreateNullValue()); |
125 return true; | 125 return true; |
126 } | 126 } |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 // A simple linear congruential generator. The random numbers don't need to be | 130 // A simple linear congruential generator. The random numbers don't need to be |
131 // high quality, but they need to be identical in each run. Therefore, we use a | 131 // high quality, but they need to be identical in each run. Therefore, we use a |
132 // LCG and keep the state locally in the benchmark. | 132 // LCG and keep the state locally in the benchmark. |
133 float InvalidationBenchmark::LCGRandom() { | 133 float InvalidationBenchmark::LCGRandom() { |
134 const uint32_t a = 1664525; | 134 const uint32_t a = 1664525; |
135 const uint32_t c = 1013904223; | 135 const uint32_t c = 1013904223; |
136 seed_ = a * seed_ + c; | 136 seed_ = a * seed_ + c; |
137 return static_cast<float>(seed_) / std::numeric_limits<uint32_t>::max(); | 137 return static_cast<float>(seed_) / std::numeric_limits<uint32_t>::max(); |
138 } | 138 } |
139 | 139 |
140 } // namespace cc | 140 } // namespace cc |
OLD | NEW |