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

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

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/rasterize_and_record_benchmark.h ('k') | cc/debug/rendering_stats.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/debug/rasterize_and_record_benchmark.h" 5 #include "cc/debug/rasterize_and_record_benchmark.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "cc/debug/lap_timer.h" 14 #include "cc/debug/lap_timer.h"
15 #include "cc/debug/rasterize_and_record_benchmark_impl.h" 15 #include "cc/debug/rasterize_and_record_benchmark_impl.h"
16 #include "cc/layers/content_layer_client.h"
16 #include "cc/layers/layer.h" 17 #include "cc/layers/layer.h"
17 #include "cc/layers/picture_layer.h" 18 #include "cc/layers/picture_layer.h"
19 #include "cc/resources/display_item_list.h"
18 #include "cc/resources/picture_pile.h" 20 #include "cc/resources/picture_pile.h"
19 #include "cc/trees/layer_tree_host.h" 21 #include "cc/trees/layer_tree_host.h"
20 #include "cc/trees/layer_tree_host_common.h" 22 #include "cc/trees/layer_tree_host_common.h"
21 #include "third_party/skia/include/utils/SkPictureUtils.h" 23 #include "third_party/skia/include/utils/SkPictureUtils.h"
22 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
23 25
24 namespace cc { 26 namespace cc {
25 27
26 namespace { 28 namespace {
27 29
28 const int kDefaultRecordRepeatCount = 100; 30 const int kDefaultRecordRepeatCount = 100;
29 31
32 // Parameters for LapTimer.
33 const int kTimeLimitMillis = 1;
34 const int kWarmupRuns = 0;
35 const int kTimeCheckInterval = 1;
36
30 const char* kModeSuffixes[Picture::RECORDING_MODE_COUNT] = { 37 const char* kModeSuffixes[Picture::RECORDING_MODE_COUNT] = {
31 "", 38 "",
32 "_sk_null_canvas", 39 "_sk_null_canvas",
33 "_painting_disabled"}; 40 "_painting_disabled"};
34 41
35 } // namespace 42 } // namespace
36 43
37 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( 44 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark(
38 scoped_ptr<base::Value> value, 45 scoped_ptr<base::Value> value,
39 const MicroBenchmark::DoneCallback& callback) 46 const MicroBenchmark::DoneCallback& callback)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 settings_.get(), 102 settings_.get(),
96 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults, 103 base::Bind(&RasterizeAndRecordBenchmark::RecordRasterResults,
97 weak_ptr_factory_.GetWeakPtr()))); 104 weak_ptr_factory_.GetWeakPtr())));
98 } 105 }
99 106
100 void RasterizeAndRecordBenchmark::Run(Layer* layer) { 107 void RasterizeAndRecordBenchmark::Run(Layer* layer) {
101 layer->RunMicroBenchmark(this); 108 layer->RunMicroBenchmark(this);
102 } 109 }
103 110
104 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { 111 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) {
105 ContentLayerClient* painter = layer->client();
106 gfx::Size content_bounds = layer->content_bounds();
107
108 DCHECK(host_); 112 DCHECK(host_);
109 gfx::Size tile_grid_size = host_->settings().default_tile_size;
110 113
111 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( 114 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect(
112 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); 115 layer->visible_content_rect(), 1.f / layer->contents_scale_x());
113 if (visible_content_rect.IsEmpty()) 116 if (visible_content_rect.IsEmpty())
114 return; 117 return;
115 118
119 if (host_->settings().use_display_lists) {
120 RunOnDisplayListLayer(layer, visible_content_rect);
121 } else {
122 RunOnPictureLayer(layer, visible_content_rect);
123 }
124 }
125
126 void RasterizeAndRecordBenchmark::RunOnPictureLayer(
127 PictureLayer* layer,
128 const gfx::Rect& visible_content_rect) {
129 ContentLayerClient* painter = layer->client();
130
131 DCHECK(host_ && !host_->settings().use_display_lists);
132
133 gfx::Size tile_grid_size = host_->settings().default_tile_size;
134
116 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT; 135 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT;
117 mode_index++) { 136 mode_index++) {
118 Picture::RecordingMode mode = 137 Picture::RecordingMode mode =
119 static_cast<Picture::RecordingMode>(mode_index); 138 static_cast<Picture::RecordingMode>(mode_index);
120 base::TimeDelta min_time = base::TimeDelta::Max(); 139 base::TimeDelta min_time = base::TimeDelta::Max();
121 size_t memory_used = 0; 140 size_t memory_used = 0;
122 141
123 // Parameters for LapTimer.
124 const int kTimeLimitMillis = 1;
125 const int kWarmupRuns = 0;
126 const int kTimeCheckInterval = 1;
127
128 for (int i = 0; i < record_repeat_count_; ++i) { 142 for (int i = 0; i < record_repeat_count_; ++i) {
129 // Run for a minimum amount of time to avoid problems with timer 143 // Run for a minimum amount of time to avoid problems with timer
130 // quantization when the layer is very small. 144 // quantization when the layer is very small.
131 LapTimer timer(kWarmupRuns, 145 LapTimer timer(kWarmupRuns,
132 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), 146 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
133 kTimeCheckInterval); 147 kTimeCheckInterval);
134 scoped_refptr<Picture> picture; 148 scoped_refptr<Picture> picture;
135 do { 149 do {
136 picture = Picture::Create(visible_content_rect, painter, tile_grid_size, 150 picture = Picture::Create(visible_content_rect, painter, tile_grid_size,
137 false, mode); 151 false, mode);
152 if (memory_used) {
153 // Verify we are recording the same thing each time.
154 DCHECK(memory_used == picture->ApproximateMemoryUsage());
155 } else {
156 memory_used = picture->ApproximateMemoryUsage();
157 }
158
138 timer.NextLap(); 159 timer.NextLap();
139 } while (!timer.HasTimeLimitExpired()); 160 } while (!timer.HasTimeLimitExpired());
140 base::TimeDelta duration = 161 base::TimeDelta duration =
141 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); 162 base::TimeDelta::FromMillisecondsD(timer.MsPerLap());
142 if (duration < min_time) 163 if (duration < min_time)
143 min_time = duration; 164 min_time = duration;
144 memory_used = picture->ApproximateMemoryUsage();
145 } 165 }
146 166
147 if (mode == Picture::RECORD_NORMALLY) { 167 if (mode == Picture::RECORD_NORMALLY) {
148 record_results_.bytes_used += memory_used; 168 record_results_.bytes_used += memory_used;
149 record_results_.pixels_recorded += 169 record_results_.pixels_recorded +=
150 visible_content_rect.width() * visible_content_rect.height(); 170 visible_content_rect.width() * visible_content_rect.height();
151 } 171 }
152 record_results_.total_best_time[mode_index] += min_time; 172 record_results_.total_best_time[mode_index] += min_time;
153 } 173 }
154 } 174 }
155 175
176 void RasterizeAndRecordBenchmark::RunOnDisplayListLayer(
177 PictureLayer* layer,
178 const gfx::Rect& visible_content_rect) {
179 ContentLayerClient* painter = layer->client();
180
181 DCHECK(host_ && host_->settings().use_display_lists);
182
183 base::TimeDelta min_time = base::TimeDelta::Max();
184 size_t memory_used = 0;
185
186 // TODO(schenney): What are the corresponding Picture::RecordingMode modes
187 // for Slimming Paint. We could disable SkPicture creation in
188 // DrawingDisplayItems, or we could only generate the display list and not
189 // do any work on it in the compositor, or something else, or all of the
190 // above.
191 scoped_refptr<DisplayItemList> display_list;
192 for (int i = 0; i < record_repeat_count_; ++i) {
193 // Run for a minimum amount of time to avoid problems with timer
194 // quantization when the layer is very small.
195 LapTimer timer(kWarmupRuns,
196 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
197 kTimeCheckInterval);
198
199 do {
200 // TODO(schenney): Cached content will not be regenerated, which skews
201 // the results significantly in favor of Slimming Paint (or should).
202 // Add a flag or API call to disable caching, and maybe run the test
203 // twice, without and with caching.
204 display_list = painter->PaintContentsToDisplayList(
205 visible_content_rect, ContentLayerClient::GRAPHICS_CONTEXT_ENABLED);
206
207 if (memory_used) {
208 // Verify we are recording the same thing each time.
209 DCHECK(memory_used == display_list->PictureMemoryUsage());
210 } else {
211 memory_used = display_list->PictureMemoryUsage();
212 }
213
214 timer.NextLap();
215 } while (!timer.HasTimeLimitExpired());
216 base::TimeDelta duration =
217 base::TimeDelta::FromMillisecondsD(timer.MsPerLap());
218 if (duration < min_time)
219 min_time = duration;
220 }
221
222 record_results_.bytes_used += memory_used;
223 record_results_.pixels_recorded +=
224 visible_content_rect.width() * visible_content_rect.height();
225 record_results_.total_best_time[Picture::RECORD_NORMALLY] += min_time;
226 }
227
156 RasterizeAndRecordBenchmark::RecordResults::RecordResults() 228 RasterizeAndRecordBenchmark::RecordResults::RecordResults()
157 : pixels_recorded(0), bytes_used(0) { 229 : pixels_recorded(0), bytes_used(0) {
158 } 230 }
159 231
160 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} 232 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {}
161 233
162 } // namespace cc 234 } // namespace cc
OLDNEW
« no previous file with comments | « cc/debug/rasterize_and_record_benchmark.h ('k') | cc/debug/rendering_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698