| 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/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/layer_tree_host_common.h" | 18 #include "cc/trees/layer_tree_host_common.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const char* kDefaultInvalidationMode = "viewport"; | 25 const char* kDefaultInvalidationMode = "viewport"; |
| 25 | 26 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 62 |
| 62 InvalidationBenchmark::~InvalidationBenchmark() { | 63 InvalidationBenchmark::~InvalidationBenchmark() { |
| 63 } | 64 } |
| 64 | 65 |
| 65 void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) { | 66 void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
| 66 LayerTreeHostCommon::CallFunctionForEveryLayer( | 67 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 67 host, [this](Layer* layer) { layer->RunMicroBenchmark(this); }); | 68 host, [this](Layer* layer) { layer->RunMicroBenchmark(this); }); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) { | 71 void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) { |
| 72 PropertyTrees* property_trees = layer->layer_tree_host()->property_trees(); |
| 73 LayerList update_list; |
| 74 update_list.push_back(layer); |
| 75 draw_property_utils::ComputeVisibleRectsForTesting( |
| 76 property_trees, property_trees->non_root_surfaces_enabled, &update_list); |
| 77 gfx::Rect visible_layer_rect = layer->visible_layer_rect_for_testing(); |
| 71 switch (mode_) { | 78 switch (mode_) { |
| 72 case FIXED_SIZE: { | 79 case FIXED_SIZE: { |
| 73 // Invalidation with a random position and fixed size. | 80 // Invalidation with a random position and fixed size. |
| 74 gfx::Rect visible_layer_rect = layer->visible_layer_rect_for_testing(); | |
| 75 int x = LCGRandom() * (visible_layer_rect.width() - width_); | 81 int x = LCGRandom() * (visible_layer_rect.width() - width_); |
| 76 int y = LCGRandom() * (visible_layer_rect.height() - height_); | 82 int y = LCGRandom() * (visible_layer_rect.height() - height_); |
| 77 gfx::Rect invalidation_rect(x, y, width_, height_); | 83 gfx::Rect invalidation_rect(x, y, width_, height_); |
| 78 layer->SetNeedsDisplayRect(invalidation_rect); | 84 layer->SetNeedsDisplayRect(invalidation_rect); |
| 79 break; | 85 break; |
| 80 } | 86 } |
| 81 case LAYER: { | 87 case LAYER: { |
| 82 // Invalidate entire layer. | 88 // Invalidate entire layer. |
| 83 layer->SetNeedsDisplay(); | 89 layer->SetNeedsDisplay(); |
| 84 break; | 90 break; |
| 85 } | 91 } |
| 86 case RANDOM: { | 92 case RANDOM: { |
| 87 // Random invalidation inside the viewport. | 93 // Random invalidation inside the viewport. |
| 88 gfx::Rect visible_layer_rect = layer->visible_layer_rect_for_testing(); | |
| 89 int x_min = LCGRandom() * visible_layer_rect.width(); | 94 int x_min = LCGRandom() * visible_layer_rect.width(); |
| 90 int x_max = LCGRandom() * visible_layer_rect.width(); | 95 int x_max = LCGRandom() * visible_layer_rect.width(); |
| 91 int y_min = LCGRandom() * visible_layer_rect.height(); | 96 int y_min = LCGRandom() * visible_layer_rect.height(); |
| 92 int y_max = LCGRandom() * visible_layer_rect.height(); | 97 int y_max = LCGRandom() * visible_layer_rect.height(); |
| 93 if (x_min > x_max) | 98 if (x_min > x_max) |
| 94 std::swap(x_min, x_max); | 99 std::swap(x_min, x_max); |
| 95 if (y_min > y_max) | 100 if (y_min > y_max) |
| 96 std::swap(y_min, y_max); | 101 std::swap(y_min, y_max); |
| 97 gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min); | 102 gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min); |
| 98 layer->SetNeedsDisplayRect(invalidation_rect); | 103 layer->SetNeedsDisplayRect(invalidation_rect); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 126 // 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 |
| 127 // LCG and keep the state locally in the benchmark. | 132 // LCG and keep the state locally in the benchmark. |
| 128 float InvalidationBenchmark::LCGRandom() { | 133 float InvalidationBenchmark::LCGRandom() { |
| 129 const uint32_t a = 1664525; | 134 const uint32_t a = 1664525; |
| 130 const uint32_t c = 1013904223; | 135 const uint32_t c = 1013904223; |
| 131 seed_ = a * seed_ + c; | 136 seed_ = a * seed_ + c; |
| 132 return static_cast<float>(seed_) / std::numeric_limits<uint32_t>::max(); | 137 return static_cast<float>(seed_) / std::numeric_limits<uint32_t>::max(); |
| 133 } | 138 } |
| 134 | 139 |
| 135 } // namespace cc | 140 } // namespace cc |
| OLD | NEW |