Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: cc/debug/invalidation_benchmark.cc

Issue 298723013: cc: Add invalidation micro benchmark. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/debug/invalidation_benchmark.h ('k') | cc/debug/micro_benchmark_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
9 #include "base/basictypes.h"
10 #include "base/rand_util.h"
11 #include "base/values.h"
12 #include "cc/layers/layer.h"
13 #include "cc/layers/picture_layer.h"
14 #include "cc/trees/layer_tree_host.h"
15 #include "cc/trees/layer_tree_host_common.h"
16 #include "ui/gfx/rect.h"
17
18 namespace cc {
19
20 namespace {
21
22 const char* kDefaultInvalidationMode = "viewport";
23
24 } // namespace
25
26 InvalidationBenchmark::InvalidationBenchmark(
27 scoped_ptr<base::Value> value,
28 const MicroBenchmark::DoneCallback& callback)
29 : MicroBenchmark(callback), mode_(kDefaultInvalidationMode) {
30 base::DictionaryValue* settings = NULL;
31 value->GetAsDictionary(&settings);
32 if (!settings)
33 return;
34
35 if (settings->HasKey("mode"))
36 settings->GetString("mode", &mode_);
37 }
38
39 InvalidationBenchmark::~InvalidationBenchmark() {
40 }
41
42 void InvalidationBenchmark::DidUpdateLayers(LayerTreeHost* host) {
43 LayerTreeHostCommon::CallFunctionForSubtree(
44 host->root_layer(),
45 base::Bind(&InvalidationBenchmark::Run, base::Unretained(this)));
46 }
47
48 void InvalidationBenchmark::Run(Layer* layer) {
49 layer->RunMicroBenchmark(this);
50 }
51
52 void InvalidationBenchmark::RunOnLayer(PictureLayer* layer) {
53 if (mode_ == "layer") {
54 // Invalidate entire layer.
55 layer->SetNeedsDisplay();
56 } else if (mode_ == "random") {
57 // Random invalidation inside the viewport.
58 gfx::Rect visible_content_rect = layer->visible_content_rect();
59 int x_min = base::RandInt(0, visible_content_rect.width());
60 int x_max = base::RandInt(0, visible_content_rect.width());
61 int y_min = base::RandInt(0, visible_content_rect.height());
62 int y_max = base::RandInt(0, visible_content_rect.height());
63 if (x_min > x_max)
64 std::swap(x_min, x_max);
65 if (y_min > y_max)
66 std::swap(y_min, y_max);
67 gfx::Rect invalidation_rect(x_min, y_min, x_max - x_min, y_max - y_min);
68 layer->SetNeedsDisplayRect(invalidation_rect);
69 } else if (mode_ == "viewport") {
70 // Invalidate entire viewport.
71 layer->SetNeedsDisplayRect(layer->visible_content_rect());
72 } else {
73 NOTREACHED();
vmpstr 2014/05/27 18:29:22 can you NOTREACHED() << "Invalid mode: " << mode_
ernstm 2014/05/27 21:17:07 Done.
74 }
75 }
76
77 } // namespace cc
OLDNEW
« no previous file with comments | « cc/debug/invalidation_benchmark.h ('k') | cc/debug/micro_benchmark_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698