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

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

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 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/picture_record_benchmark.h ('k') | cc/debug/rasterize_and_record_benchmark.h » ('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 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.
4
5 #include "cc/debug/picture_record_benchmark.h"
6
7 #include <algorithm>
8
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"
17
18 namespace cc {
19
20 namespace {
21
22 const int kPositionIncrement = 100;
23 const int kTileGridSize = 512;
24
25 } // namespace
26
27 PictureRecordBenchmark::PictureRecordBenchmark(
28 scoped_ptr<base::Value> value,
29 const MicroBenchmark::DoneCallback& callback)
30 : MicroBenchmark(callback) {
31 if (!value)
32 return;
33
34 base::ListValue* list = nullptr;
35 value->GetAsList(&list);
36 if (!list)
37 return;
38
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;
46
47 int width, height;
48 dictionary->GetInteger("width", &width);
49 dictionary->GetInteger("height", &height);
50
51 dimensions_.push_back(std::make_pair(width, height));
52 }
53 }
54
55 PictureRecordBenchmark::~PictureRecordBenchmark() {}
56
57 void PictureRecordBenchmark::DidUpdateLayers(LayerTreeHost* host) {
58 LayerTreeHostCommon::CallFunctionForSubtree(
59 host->root_layer(),
60 [this](Layer* layer) { layer->RunMicroBenchmark(this); });
61
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;
69
70 double average_time = 0.0;
71 if (total_count > 0)
72 average_time = total_time.InMillisecondsF() / total_count;
73
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);
79
80 results->Append(result.release());
81 }
82
83 NotifyDone(results.Pass());
84 }
85
86 void PictureRecordBenchmark::RunOnLayer(PictureLayer* layer) {
87 ContentLayerClient* painter = layer->client();
88 gfx::Size content_bounds = layer->content_bounds();
89
90 gfx::Size tile_grid_size(kTileGridSize, kTileGridSize);
91
92 for (size_t i = 0; i < dimensions_.size(); ++i) {
93 std::pair<int, int> dimensions = dimensions_[i];
94 int width = dimensions.first;
95 int height = dimensions.second;
96
97 int y_limit = std::max(1, content_bounds.height() - height);
98 int x_limit = std::max(1, content_bounds.width() - width);
99 for (int y = 0; y < y_limit; y += kPositionIncrement) {
100 for (int x = 0; x < x_limit; x += kPositionIncrement) {
101 gfx::Rect rect = gfx::Rect(x, y, width, height);
102
103 base::TimeTicks start = base::TimeTicks::Now();
104
105 scoped_refptr<Picture> picture =
106 Picture::Create(rect, painter, tile_grid_size, false,
107 RecordingSource::RECORD_NORMALLY);
108
109 base::TimeTicks end = base::TimeTicks::Now();
110 base::TimeDelta duration = end - start;
111 TotalTime& total_time = times_[dimensions];
112 total_time.first += duration;
113 total_time.second++;
114 }
115 }
116 }
117 }
118
119 } // namespace cc
OLDNEW
« no previous file with comments | « cc/debug/picture_record_benchmark.h ('k') | cc/debug/rasterize_and_record_benchmark.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698