OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/debug/invalidation_benchmark.h" | |
6 | |
7 #include <algorithm> | |
8 #include <limits> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/rand_util.h" | |
12 #include "base/values.h" | |
13 #include "cc/layers/layer.h" | |
14 #include "cc/layers/picture_layer.h" | |
15 #include "cc/trees/layer_tree_host.h" | |
16 #include "cc/trees/layer_tree_host_common.h" | |
17 #include "ui/gfx/rect.h" | |
18 | |
19 namespace cc { | |
20 | |
21 namespace { | |
22 | |
23 const char* kDefaultInvalidationMode = "viewport"; | |
24 | |
25 } // namespace | |
26 | |
27 InvalidationBenchmark::InvalidationBenchmark( | |
28 scoped_ptr<base::Value> value, | |
29 const MicroBenchmark::DoneCallback& callback) | |
30 : MicroBenchmark(callback), seed_(0) { | |
31 base::DictionaryValue* settings = NULL; | |
32 value->GetAsDictionary(&settings); | |
33 if (!settings) | |
34 return; | |
35 | |
36 std::string mode_string = kDefaultInvalidationMode; | |
37 | |
38 if (settings->HasKey("mode")) | |
39 settings->GetString("mode", &mode_string); | |
40 | |
41 if (mode_string == "layer") { | |
42 mode_ = LAYER; | |
43 } else if (mode_string == "viewport") { | |
44 mode_ = VIEWPORT; | |
45 } else if (mode_string == "random") { | |
46 mode_ = RANDOM; | |
47 } else { | |
48 LOG(ERROR) << "Invalid mode: " << mode_string | |
vmpstr
2014/05/27 21:24:21
You can just do CHECK(false) << "blah" (the macro
ernstm
2014/05/27 21:34:46
Done.
| |
49 << ". One of {layer, viewport, random} expected"; | |
50 CHECK(false); | |
51 } | |
52 } | |
53 | |
54 InvalidationBenchmark::~InvalidationBenchmark() { | |
55 } | |
56 | |
57 void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) { | |
58 LayerTreeHostCommon::CallFunctionForSubtree( | |
59 host->root_layer(), | |
60 base::Bind(&InvalidationBenchmark::Run, base::Unretained(this))); | |
61 } | |
62 | |
63 void InvalidationBenchmark::Run(Layer* layer) { | |
64 layer->RunMicroBenchmark(this); | |
65 } | |
66 | |
67 void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) { | |
68 switch (mode_) { | |
69 case LAYER: | |
70 // Invalidate entire layer. | |
71 layer->SetNeedsDisplay(); | |
72 break; | |
73 case VIEWPORT: | |
74 // Invalidate entire viewport. | |
75 layer->SetNeedsDisplayRect(layer->visible_content_rect()); | |
76 break; | |
77 case RANDOM: { | |
78 // Random invalidation inside the viewport. | |
79 gfx::Rect visible_content_rect = layer->visible_content_rect(); | |
80 int x_min = LCGRandom() * visible_content_rect.width(); | |
81 int x_max = LCGRandom() * visible_content_rect.width(); | |
82 int y_min = LCGRandom() * visible_content_rect.height(); | |
83 int y_max = LCGRandom() * visible_content_rect.height(); | |
84 if (x_min > x_max) | |
85 std::swap(x_min, x_max); | |
86 if (y_min > y_max) | |
87 std::swap(y_min, y_max); | |
88 gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min); | |
89 layer->SetNeedsDisplayRect(invalidation_rect); | |
90 break; | |
91 } | |
92 default: | |
93 NOTREACHED(); | |
94 break; | |
95 } | |
96 } | |
97 | |
98 // A simple linear congruential generator. The random numbers don't need to be | |
99 // high quality, but they need to be identical in each run. Therefore, we use a | |
100 // LCG and keep the state locally in the benchmark. | |
101 float InvalidationBenchmark::LCGRandom() { | |
102 const uint32 a = 1664525; | |
103 const uint32 c = 1013904223; | |
104 seed_ = a * seed_ + c; | |
vmpstr
2014/05/27 21:24:21
I'm not familiar with rng algorithms, but I assume
ernstm
2014/05/27 21:34:46
Yes, this is expected to overflow and wrap around.
| |
105 return seed_ / std::numeric_limits<uint32>::max(); | |
vmpstr
2014/05/27 21:24:21
Doesn't this just give you 0, because of integer d
ernstm
2014/05/27 21:34:46
Yes, I accidentally removed the cast in #2 and add
| |
106 } | |
107 | |
108 } // namespace cc | |
OLD | NEW |