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