Index: cc/debug/invalidation_benchmark.cc |
diff --git a/cc/debug/invalidation_benchmark.cc b/cc/debug/invalidation_benchmark.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4063a4f9c7d7be22e19854ed45b17ec91ac5bce4 |
--- /dev/null |
+++ b/cc/debug/invalidation_benchmark.cc |
@@ -0,0 +1,77 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/debug/invalidation_benchmark.h" |
+ |
+#include <algorithm> |
+ |
+#include "base/basictypes.h" |
+#include "base/rand_util.h" |
+#include "base/values.h" |
+#include "cc/layers/layer.h" |
+#include "cc/layers/picture_layer.h" |
+#include "cc/trees/layer_tree_host.h" |
+#include "cc/trees/layer_tree_host_common.h" |
+#include "ui/gfx/rect.h" |
+ |
+namespace cc { |
+ |
+namespace { |
+ |
+const char* kDefaultInvalidationMode = "viewport"; |
+ |
+} // namespace |
+ |
+InvalidationBenchmark::InvalidationBenchmark( |
+ scoped_ptr<base::Value> value, |
+ const MicroBenchmark::DoneCallback& callback) |
+ : MicroBenchmark(callback), mode_(kDefaultInvalidationMode) { |
+ base::DictionaryValue* settings = NULL; |
+ value->GetAsDictionary(&settings); |
+ if (!settings) |
+ return; |
+ |
+ if (settings->HasKey("mode")) |
+ settings->GetString("mode", &mode_); |
+} |
+ |
+InvalidationBenchmark::~InvalidationBenchmark() { |
+} |
+ |
+void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
+ LayerTreeHostCommon::CallFunctionForSubtree( |
+ host->root_layer(), |
+ base::Bind(&InvalidationBenchmark::Run, base::Unretained(this))); |
+} |
+ |
+void InvalidationBenchmark::Run(Layer* layer) { |
+ layer->RunMicroBenchmark(this); |
+} |
+ |
+void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) { |
+ if (mode_ == "layer") { |
+ // Invalidate entire layer. |
+ layer->SetNeedsDisplay(); |
+ } else if (mode_ == "random") { |
+ // Random invalidation inside the viewport. |
+ gfx::Rect visible_content_rect = layer->visible_content_rect(); |
+ int x_min = base::RandInt(0, visible_content_rect.width()); |
+ int x_max = base::RandInt(0, visible_content_rect.width()); |
+ int y_min = base::RandInt(0, visible_content_rect.height()); |
+ int y_max = base::RandInt(0, visible_content_rect.height()); |
+ if (x_min > x_max) |
+ std::swap(x_min, x_max); |
+ if (y_min > y_max) |
+ std::swap(y_min, y_max); |
+ gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min); |
+ layer->SetNeedsDisplayRect(invalidation_rect); |
+ } else if (mode_ == "viewport") { |
+ // Invalidate entire viewport. |
+ layer->SetNeedsDisplayRect(layer->visible_content_rect()); |
+ } else { |
+ NOTREACHED(); |
vmpstr
2014/05/27 18:29:22
can you
NOTREACHED() << "Invalid mode: " << mode_
ernstm
2014/05/27 21:17:07
Done.
|
+ } |
+} |
+ |
+} // namespace cc |