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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 break; | 105 break; |
106 } | 106 } |
107 case VIEWPORT: { | 107 case VIEWPORT: { |
108 // Invalidate entire viewport. | 108 // Invalidate entire viewport. |
109 layer->SetNeedsDisplayRect(layer->visible_layer_rect_for_testing()); | 109 layer->SetNeedsDisplayRect(layer->visible_layer_rect_for_testing()); |
110 break; | 110 break; |
111 } | 111 } |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 bool InvalidationBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { | 115 bool InvalidationBenchmark::ProcessMessage(std::unique_ptr<base::Value> value) { |
116 base::DictionaryValue* message = nullptr; | 116 base::DictionaryValue* message = nullptr; |
117 value->GetAsDictionary(&message); | 117 value->GetAsDictionary(&message); |
118 if (!message) | 118 if (!message) |
119 return false; | 119 return false; |
120 | 120 |
121 bool notify_done; | 121 bool notify_done; |
122 if (message->HasKey("notify_done")) { | 122 if (message->HasKey("notify_done")) { |
123 message->GetBoolean("notify_done", ¬ify_done); | 123 message->GetBoolean("notify_done", ¬ify_done); |
124 if (notify_done) | 124 if (notify_done) |
125 NotifyDone(base::Value::CreateNullValue()); | 125 NotifyDone(base::Value::CreateNullValue()); |
126 return true; | 126 return true; |
127 } | 127 } |
128 return false; | 128 return false; |
129 } | 129 } |
130 | 130 |
131 // A simple linear congruential generator. The random numbers don't need to be | 131 // A simple linear congruential generator. The random numbers don't need to be |
132 // high quality, but they need to be identical in each run. Therefore, we use a | 132 // high quality, but they need to be identical in each run. Therefore, we use a |
133 // LCG and keep the state locally in the benchmark. | 133 // LCG and keep the state locally in the benchmark. |
134 float InvalidationBenchmark::LCGRandom() { | 134 float InvalidationBenchmark::LCGRandom() { |
135 const uint32_t a = 1664525; | 135 const uint32_t a = 1664525; |
136 const uint32_t c = 1013904223; | 136 const uint32_t c = 1013904223; |
137 seed_ = a * seed_ + c; | 137 seed_ = a * seed_ + c; |
138 return static_cast<float>(seed_) / std::numeric_limits<uint32_t>::max(); | 138 return static_cast<float>(seed_) / std::numeric_limits<uint32_t>::max(); |
139 } | 139 } |
140 | 140 |
141 } // namespace cc | 141 } // namespace cc |
OLD | NEW |