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
120
|
// 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/rasterize_and_record_benchmark_impl.h"
#include <algorithm>
#include <limits>
#include "base/basictypes.h"
#include "base/values.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/picture_layer_impl.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "ui/gfx/rect.h"
namespace cc {
namespace {
const int kDefaultRasterizeRepeatCount = 100;
base::TimeTicks Now() {
return base::TimeTicks::IsThreadNowSupported()
? base::TimeTicks::ThreadNow()
: base::TimeTicks::HighResNow();
}
} // namespace
RasterizeAndRecordBenchmarkImpl::RasterizeAndRecordBenchmarkImpl(
scoped_refptr<base::MessageLoopProxy> origin_loop,
base::Value* value,
const MicroBenchmarkImpl::DoneCallback& callback)
: MicroBenchmarkImpl(callback, origin_loop),
rasterize_repeat_count_(kDefaultRasterizeRepeatCount) {
base::DictionaryValue* settings = NULL;
value->GetAsDictionary(&settings);
if (!settings)
return;
if (settings->HasKey("rasterize_repeat_count"))
settings->GetInteger("rasterize_repeat_count", &rasterize_repeat_count_);
}
RasterizeAndRecordBenchmarkImpl::~RasterizeAndRecordBenchmarkImpl() {}
void RasterizeAndRecordBenchmarkImpl::DidCompleteCommit(
LayerTreeHostImpl* host) {
LayerTreeHostCommon::CallFunctionForSubtree(
host->RootLayer(),
base::Bind(&RasterizeAndRecordBenchmarkImpl::Run,
base::Unretained(this)));
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
result->SetInteger("pixels_rasterized", rasterize_results_.pixels_rasterized);
result->SetDouble("rasterize_time_ms",
rasterize_results_.total_best_time.InMillisecondsF());
NotifyDone(result.PassAs<base::Value>());
}
void RasterizeAndRecordBenchmarkImpl::Run(LayerImpl* layer) {
layer->RunMicroBenchmark(this);
}
void RasterizeAndRecordBenchmarkImpl::RunOnLayer(PictureLayerImpl* layer) {
if (layer->visible_content_rect().IsEmpty())
return;
PictureLayerTilingSet tiling_set(layer, layer->content_bounds());
PictureLayerTiling* tiling = tiling_set.AddTiling(layer->contents_scale_x());
tiling->CreateAllTilesForTesting();
for (PictureLayerTiling::CoverageIterator it(
tiling, layer->contents_scale_x(), layer->visible_content_rect());
it;
++it) {
DCHECK(*it);
PicturePileImpl* picture_pile = (*it)->picture_pile();
gfx::Rect content_rect = (*it)->content_rect();
float contents_scale = (*it)->contents_scale();
base::TimeDelta min_time =
base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max());
for (int i = 0; i < rasterize_repeat_count_; ++i) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
content_rect.width(),
content_rect.height());
bitmap.allocPixels();
SkBitmapDevice device(bitmap);
SkCanvas canvas(&device);
PicturePileImpl::Analysis analysis;
base::TimeTicks start = Now();
picture_pile->AnalyzeInRect(
content_rect, contents_scale, &analysis, NULL);
picture_pile->RasterToBitmap(&canvas, content_rect, contents_scale, NULL);
base::TimeTicks end = Now();
base::TimeDelta duration = end - start;
if (duration < min_time)
min_time = duration;
}
rasterize_results_.pixels_rasterized +=
content_rect.width() * content_rect.height();
rasterize_results_.total_best_time += min_time;
}
}
RasterizeAndRecordBenchmarkImpl::RasterizeResults::RasterizeResults()
: pixels_rasterized(0) {}
RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {}
} // namespace cc
|