| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) { | 64 void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
| 65 LayerTreeHostCommon::CallFunctionForSubtree( | 65 LayerTreeHostCommon::CallFunctionForSubtree( |
| 66 host->root_layer(), | 66 host->root_layer(), |
| 67 [this](Layer* layer) { layer->RunMicroBenchmark(this); }); | 67 [this](Layer* layer) { layer->RunMicroBenchmark(this); }); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) { | 70 void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) { |
| 71 switch (mode_) { | 71 switch (mode_) { |
| 72 case FIXED_SIZE: { | 72 case FIXED_SIZE: { |
| 73 // Invalidation with a random position and fixed size. | 73 // Invalidation with a random position and fixed size. |
| 74 gfx::Rect visible_content_rect = layer->visible_content_rect(); | 74 gfx::Rect visible_layer_rect = layer->visible_layer_rect(); |
| 75 int x = LCGRandom() * (visible_content_rect.width() - width_); | 75 int x = LCGRandom() * (visible_layer_rect.width() - width_); |
| 76 int y = LCGRandom() * (visible_content_rect.height() - height_); | 76 int y = LCGRandom() * (visible_layer_rect.height() - height_); |
| 77 gfx::Rect invalidation_rect(x, y, width_, height_); | 77 gfx::Rect invalidation_rect(x, y, width_, height_); |
| 78 layer->SetNeedsDisplayRect(invalidation_rect); | 78 layer->SetNeedsDisplayRect(invalidation_rect); |
| 79 break; | 79 break; |
| 80 } | 80 } |
| 81 case LAYER: { | 81 case LAYER: { |
| 82 // Invalidate entire layer. | 82 // Invalidate entire layer. |
| 83 layer->SetNeedsDisplay(); | 83 layer->SetNeedsDisplay(); |
| 84 break; | 84 break; |
| 85 } | 85 } |
| 86 case RANDOM: { | 86 case RANDOM: { |
| 87 // Random invalidation inside the viewport. | 87 // Random invalidation inside the viewport. |
| 88 gfx::Rect visible_content_rect = layer->visible_content_rect(); | 88 gfx::Rect visible_layer_rect = layer->visible_layer_rect(); |
| 89 int x_min = LCGRandom() * visible_content_rect.width(); | 89 int x_min = LCGRandom() * visible_layer_rect.width(); |
| 90 int x_max = LCGRandom() * visible_content_rect.width(); | 90 int x_max = LCGRandom() * visible_layer_rect.width(); |
| 91 int y_min = LCGRandom() * visible_content_rect.height(); | 91 int y_min = LCGRandom() * visible_layer_rect.height(); |
| 92 int y_max = LCGRandom() * visible_content_rect.height(); | 92 int y_max = LCGRandom() * visible_layer_rect.height(); |
| 93 if (x_min > x_max) | 93 if (x_min > x_max) |
| 94 std::swap(x_min, x_max); | 94 std::swap(x_min, x_max); |
| 95 if (y_min > y_max) | 95 if (y_min > y_max) |
| 96 std::swap(y_min, y_max); | 96 std::swap(y_min, y_max); |
| 97 gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min); | 97 gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min); |
| 98 layer->SetNeedsDisplayRect(invalidation_rect); | 98 layer->SetNeedsDisplayRect(invalidation_rect); |
| 99 break; | 99 break; |
| 100 } | 100 } |
| 101 case VIEWPORT: { | 101 case VIEWPORT: { |
| 102 // Invalidate entire viewport. | 102 // Invalidate entire viewport. |
| 103 layer->SetNeedsDisplayRect(layer->visible_content_rect()); | 103 layer->SetNeedsDisplayRect(layer->visible_layer_rect()); |
| 104 break; | 104 break; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool InvalidationBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { | 109 bool InvalidationBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { |
| 110 base::DictionaryValue* message = nullptr; | 110 base::DictionaryValue* message = nullptr; |
| 111 value->GetAsDictionary(&message); | 111 value->GetAsDictionary(&message); |
| 112 if (!message) | 112 if (!message) |
| 113 return false; | 113 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 126 // high quality, but they need to be identical in each run. Therefore, we use a | 126 // high quality, but they need to be identical in each run. Therefore, we use a |
| 127 // LCG and keep the state locally in the benchmark. | 127 // LCG and keep the state locally in the benchmark. |
| 128 float InvalidationBenchmark::LCGRandom() { | 128 float InvalidationBenchmark::LCGRandom() { |
| 129 const uint32 a = 1664525; | 129 const uint32 a = 1664525; |
| 130 const uint32 c = 1013904223; | 130 const uint32 c = 1013904223; |
| 131 seed_ = a * seed_ + c; | 131 seed_ = a * seed_ + c; |
| 132 return static_cast<float>(seed_) / std::numeric_limits<uint32>::max(); | 132 return static_cast<float>(seed_) / std::numeric_limits<uint32>::max(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 } // namespace cc | 135 } // namespace cc |
| OLD | NEW |