Replicate sandbox flags for OOPIF (Chromium part 2).
[chromium-blink-merge.git] / cc / debug / picture_record_benchmark.cc
blobd0d031d2c13b2b00f31025781144fa0b71c86c22
1 // Copyright 2013 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.
5 #include "cc/debug/picture_record_benchmark.h"
7 #include <algorithm>
9 #include "base/basictypes.h"
10 #include "base/values.h"
11 #include "cc/layers/layer.h"
12 #include "cc/layers/picture_layer.h"
13 #include "cc/resources/picture.h"
14 #include "cc/trees/layer_tree_host.h"
15 #include "cc/trees/layer_tree_host_common.h"
16 #include "ui/gfx/geometry/rect.h"
18 namespace cc {
20 namespace {
22 const int kPositionIncrement = 100;
23 const int kTileGridSize = 512;
25 } // namespace
27 PictureRecordBenchmark::PictureRecordBenchmark(
28 scoped_ptr<base::Value> value,
29 const MicroBenchmark::DoneCallback& callback)
30 : MicroBenchmark(callback) {
31 if (!value)
32 return;
34 base::ListValue* list = nullptr;
35 value->GetAsList(&list);
36 if (!list)
37 return;
39 for (base::ListValue::iterator it = list->begin(); it != list->end(); ++it) {
40 base::DictionaryValue* dictionary = nullptr;
41 (*it)->GetAsDictionary(&dictionary);
42 if (!dictionary ||
43 !dictionary->HasKey("width") ||
44 !dictionary->HasKey("height"))
45 continue;
47 int width, height;
48 dictionary->GetInteger("width", &width);
49 dictionary->GetInteger("height", &height);
51 dimensions_.push_back(std::make_pair(width, height));
55 PictureRecordBenchmark::~PictureRecordBenchmark() {}
57 void PictureRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) {
58 LayerTreeHostCommon::CallFunctionForSubtree(
59 host->root_layer(),
60 base::Bind(&PictureRecordBenchmark::Run, base::Unretained(this)));
62 scoped_ptr<base::ListValue> results(new base::ListValue());
63 for (std::map<std::pair<int, int>, TotalTime>::iterator it = times_.begin();
64 it != times_.end();
65 ++it) {
66 std::pair<int, int> dimensions = it->first;
67 base::TimeDelta total_time = it->second.first;
68 unsigned total_count = it->second.second;
70 double average_time = 0.0;
71 if (total_count > 0)
72 average_time = total_time.InMillisecondsF() / total_count;
74 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
75 result->SetInteger("width", dimensions.first);
76 result->SetInteger("height", dimensions.second);
77 result->SetInteger("samples_count", total_count);
78 result->SetDouble("time_ms", average_time);
80 results->Append(result.release());
83 NotifyDone(results.Pass());
86 void PictureRecordBenchmark::Run(Layer* layer) {
87 layer->RunMicroBenchmark(this);
90 void PictureRecordBenchmark::RunOnLayer(PictureLayer* layer) {
91 ContentLayerClient* painter = layer->client();
92 gfx::Size content_bounds = layer->content_bounds();
94 gfx::Size tile_grid_size(kTileGridSize, kTileGridSize);
96 for (size_t i = 0; i < dimensions_.size(); ++i) {
97 std::pair<int, int> dimensions = dimensions_[i];
98 int width = dimensions.first;
99 int height = dimensions.second;
101 int y_limit = std::max(1, content_bounds.height() - height);
102 int x_limit = std::max(1, content_bounds.width() - width);
103 for (int y = 0; y < y_limit; y += kPositionIncrement) {
104 for (int x = 0; x < x_limit; x += kPositionIncrement) {
105 gfx::Rect rect = gfx::Rect(x, y, width, height);
107 base::TimeTicks start = base::TimeTicks::Now();
109 scoped_refptr<Picture> picture = Picture::Create(
110 rect, painter, tile_grid_size, false, Picture::RECORD_NORMALLY);
112 base::TimeTicks end = base::TimeTicks::Now();
113 base::TimeDelta duration = end - start;
114 TotalTime& total_time = times_[dimensions];
115 total_time.first += duration;
116 total_time.second++;
122 } // namespace cc