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

Side by Side Diff: content/renderer/all_rendering_benchmarks.cc

Issue 10837223: Tiled rendering microbenchmarks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed lint errors Created 8 years, 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/all_rendering_benchmarks.h" 5 #include "content/renderer/all_rendering_benchmarks.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/memory/scoped_ptr.h"
piman 2012/08/13 18:54:52 nit: alpha order please.
dmurph 2012/08/13 22:04:11 Done.
13 #include "content/renderer/rendering_benchmark.h" 14 #include "content/renderer/rendering_benchmark.h"
14 #include "content/renderer/rendering_benchmark_results.h" 15 #include "content/renderer/rendering_benchmark_results.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "third_party/skia/include/core/SkDevice.h" 17 #include "third_party/skia/include/core/SkDevice.h"
18 #include "third_party/skia/include/core/SkPicture.h"
17 #include "third_party/skia/include/utils/SkNullCanvas.h" 19 #include "third_party/skia/include/utils/SkNullCanvas.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h" 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h"
21 23
22 using base::TimeDelta; 24 using base::TimeDelta;
23 using base::TimeTicks; 25 using base::TimeTicks;
24 using WebKit::WebSize; 26 using WebKit::WebSize;
25 using WebKit::WebCanvas; 27 using WebKit::WebCanvas;
26 using WebKit::WebViewBenchmarkSupport; 28 using WebKit::WebViewBenchmarkSupport;
27 29
28 namespace { 30 namespace {
29 31
32 // Base class for timing the painting to custom WebCanvases
piman 2012/08/13 18:54:52 nit: comments end with a .
nduca 2012/08/13 19:05:03 complete sentences.
dmurph 2012/08/13 22:04:11 Done.
30 class CustomPaintBenchmark 33 class CustomPaintBenchmark
31 : public content::RenderingBenchmark, 34 : public content::RenderingBenchmark,
32 public WebViewBenchmarkSupport::PaintClient { 35 public WebViewBenchmarkSupport::PaintClient {
33 public: 36 public:
34 CustomPaintBenchmark(const std::string& name, 37 CustomPaintBenchmark(const std::string& name,
35 WebViewBenchmarkSupport::PaintMode paint_mode) 38 WebViewBenchmarkSupport::PaintMode paint_mode)
36 : content::RenderingBenchmark(name), 39 : content::RenderingBenchmark(name),
37 paint_mode_(paint_mode) { } 40 paint_mode_(paint_mode) { }
38 41
39 virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE { 42 virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE {
40 WebCanvas* canvas = createCanvas(size); 43 WebCanvas* canvas = createCanvas(size);
41 before_time_ = TimeTicks::Now(); 44 before_time_ = TimeTicks::Now();
42 return canvas; 45 return canvas;
43 } 46 }
44 47
45 virtual void didPaint(WebCanvas* canvas) OVERRIDE { 48 virtual void didPaint(WebCanvas* canvas) OVERRIDE {
46 paint_time_total_ += (TimeTicks::Now() - before_time_); 49 paint_time_total_ += (TimeTicks::Now() - before_time_);
47 delete canvas; 50 delete canvas;
48 } 51 }
49 52
50 virtual void Run(content::RenderingBenchmarkResults* results, 53 virtual void Run(content::RenderingBenchmarkResults* results,
51 WebViewBenchmarkSupport* support) { 54 WebViewBenchmarkSupport* support) OVERRIDE {
52 paint_time_total_ = TimeDelta(); 55 paint_time_total_ = TimeDelta();
53 support->paint(this, paint_mode_); 56 support->paint(this, paint_mode_);
54 results->AddResult(name(), 57 results->AddResult(name(),
55 "paintTime", 58 "paintTime",
56 "s", 59 "s",
57 paint_time_total_.InSecondsF()); 60 paint_time_total_.InSecondsF());
58 } 61 }
59 62
60 private: 63 private:
61 virtual WebCanvas* createCanvas(const WebSize& size) = 0; 64 virtual WebCanvas* createCanvas(const WebSize& size) = 0;
(...skipping 18 matching lines...) Expand all
80 WebCanvas* canvas = new WebCanvas(device); 83 WebCanvas* canvas = new WebCanvas(device);
81 device->unref(); 84 device->unref();
82 return canvas; 85 return canvas;
83 } 86 }
84 }; 87 };
85 88
86 class NullCanvasPaintBenchmark : public CustomPaintBenchmark { 89 class NullCanvasPaintBenchmark : public CustomPaintBenchmark {
87 public: 90 public:
88 NullCanvasPaintBenchmark(const std::string& name, 91 NullCanvasPaintBenchmark(const std::string& name,
89 WebViewBenchmarkSupport::PaintMode paint_mode) 92 WebViewBenchmarkSupport::PaintMode paint_mode)
90 : CustomPaintBenchmark(name, paint_mode) { } 93 : CustomPaintBenchmark(name, paint_mode),
94 canvas_count_(0) { }
95
96 virtual void Run(content::RenderingBenchmarkResults* results,
97 WebViewBenchmarkSupport* support) OVERRIDE {
piman 2012/08/13 18:54:52 nit: indentation
dmurph 2012/08/13 22:04:11 Done.
98 canvas_count_ = 0;
99 CustomPaintBenchmark::Run(results, support);
100 results->AddResult(name(),
101 "canvasCount",
102 "i",
nduca 2012/08/13 19:05:03 Lets merge these three strings into one. "resultNa
dmurph 2012/08/13 22:04:11 Ok, I'll do that in the next cl.
103 canvas_count_);
104 }
91 105
92 private: 106 private:
93 virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { 107 virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE {
108 ++canvas_count_;
94 return SkCreateNullCanvas(); 109 return SkCreateNullCanvas();
95 } 110 }
111
112 int canvas_count_;
96 }; 113 };
114
115 class SkPicturePaintBenchmark : public CustomPaintBenchmark {
116 public:
117 SkPicturePaintBenchmark(const std::string& name,
118 WebViewBenchmarkSupport::PaintMode paint_mode)
119 : CustomPaintBenchmark(name, paint_mode) { }
120
121 virtual void didPaint(WebCanvas* canvas) OVERRIDE {
122 CustomPaintBenchmark::didPaint(NULL);
123 DCHECK(picture_.getRecordingCanvas() == canvas);
124 picture_.endRecording();
nduca 2012/08/13 19:05:03 What if endRecording has costs? Make sure that the
dmurph 2012/08/13 22:04:11 Done.
125 }
126
127 private:
128 virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE {
129 return picture_.beginRecording(size.width, size.height);
130 }
131
132 SkPicture picture_;
133 };
134
135 // Base class for timing replaying
piman 2012/08/13 18:54:52 nit: .
dmurph 2012/08/13 22:04:11 Done.
136 class TiledReplayBenchmark
137 : public content::RenderingBenchmark,
138 public WebViewBenchmarkSupport::PaintClient {
139 public:
140 class CanvasProvider {
141 public:
nduca 2012/08/13 19:05:03 Do this with a pure method on the TiledREplayBench
dmurph 2012/08/13 22:04:11 I was under the impression that we would be using
142 virtual ~CanvasProvider() {}
143 virtual WebCanvas* createCanvas(const WebSize& size) const = 0;
144 };
145
146 TiledReplayBenchmark(const std::string& name,
147 WebViewBenchmarkSupport::PaintMode paint_mode,
148 CanvasProvider* canvas_provider)
149 : RenderingBenchmark(name),
150 canvas_provider_(canvas_provider),
151 paint_mode_(paint_mode) {}
152
153 virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE {
154 curr_layer_size_ = size;
155 return picture_.beginRecording(size.width, size.height);
nduca 2012/08/13 19:05:03 er, you're recording all the different canvases in
dmurph 2012/08/13 22:04:11 Not quite, I only time stuff on didPaint(), I'm no
156 }
157
158 virtual void didPaint(WebCanvas* canvas) OVERRIDE {
159 DCHECK(picture_.getRecordingCanvas() == canvas);
160 picture_.endRecording();
161 paint_time_total_ += timeTiledRepaint(&picture_, *canvas_provider_.get());
162 }
163
164 virtual void Run(content::RenderingBenchmarkResults* results,
165 WebViewBenchmarkSupport* support) {
166 paint_time_total_ = TimeDelta();
167 support->paint(this, paint_mode_);
168 results->AddResult(name(),
169 "repaintTime",
170 "s",
171 paint_time_total_.InSecondsF());
172 }
173
174 protected:
175 const WebSize& CurrLayerSize() {
piman 2012/08/13 18:54:52 nit: you can name this current_layer_size() since
dmurph 2012/08/13 22:04:11 Ended up being redundant, removed.
176 return curr_layer_size_;
177 }
178
179 private:
180 virtual TimeDelta timeTiledRepaint(SkPicture* picture,
181 const CanvasProvider& canvas_provider) = 0;
182
183 TimeDelta paint_time_total_;
184 WebSize curr_layer_size_;
piman 2012/08/13 18:54:52 nit: s/curr/current/ We tend to avoid abbreviatio
dmurph 2012/08/13 22:04:11 Ended up being redundant, removed.
185 SkPicture picture_;
186 const scoped_ptr<CanvasProvider> canvas_provider_;
187 const WebViewBenchmarkSupport::PaintMode paint_mode_;
188 };
189
190 class SquareTiledReplayBenchmark : public TiledReplayBenchmark {
191 public:
192 SquareTiledReplayBenchmark(const std::string& name,
193 WebViewBenchmarkSupport::PaintMode paint_mode,
194 CanvasProvider* canvas_provider,
195 int tile_size)
196 : TiledReplayBenchmark(name, paint_mode, canvas_provider),
197 tile_size_(tile_size) {
198 CHECK_GT(tile_size, 0);
199 }
200
201 private:
202 virtual TimeDelta timeTiledRepaint(
nduca 2012/08/13 19:05:03 why not factor this into a "get me a vector of rec
dmurph 2012/08/13 22:04:11 Yeah, that's much better.
203 SkPicture* picture,
204 const CanvasProvider& canvas_provider) OVERRIDE {
205 const WebSize canvas_size(tile_size_, tile_size_);
206 TimeDelta timeAccum;
piman 2012/08/13 18:54:52 nit: As ment'n abv, we don't <3 abbrevs. Also, nam
dmurph 2012/08/13 22:04:11 Done.
207 for (int x = 0; x < picture->width(); x += tile_size_) {
208 for (int y = 0; y < picture->height(); y += tile_size_) {
209 scoped_ptr<WebCanvas> canvas(canvas_provider.createCanvas(canvas_size));
piman 2012/08/13 18:54:52 It would be useful I think to clip the last column
dmurph 2012/08/13 22:04:11 Done.
210 canvas->translate(-x, -y);
211 TimeTicks before_time = TimeTicks::Now();
piman 2012/08/13 18:54:52 I'm not convinced that this benchmark accurately r
dmurph 2012/08/13 22:04:11 You're right, fixed.
212 picture->draw(canvas.get());
213 timeAccum += (TimeTicks::Now() - before_time);
214 }
215 }
216 return timeAccum;
217 }
218
219 int tile_size_;
220 };
221
222 class LayerWidthTiledReplayBenchmark : public TiledReplayBenchmark {
223 public:
224 LayerWidthTiledReplayBenchmark(const std::string& name,
225 WebViewBenchmarkSupport::PaintMode paint_mode,
226 CanvasProvider* canvas_provider,
227 int tile_height)
228 : TiledReplayBenchmark(name, paint_mode, canvas_provider),
229 tile_height_(tile_height) {
230 CHECK_GT(tile_height, 0);
231 }
232
233 private:
234 virtual TimeDelta timeTiledRepaint(
235 SkPicture* picture,
236 const CanvasProvider& canvas_provider) OVERRIDE {
237 const WebSize& layer_size = CurrLayerSize();
238 const WebSize canvas_size(layer_size.width, tile_height_);
239 TimeDelta timeAccum;
piman 2012/08/13 18:54:52 nit: style, abbrev.
dmurph 2012/08/13 22:04:11 Done.
240 for (int y = 0; y < picture->height(); y += tile_height_) {
piman 2012/08/13 18:54:52 same comments as in SquareTiledReplayBenchmark, yo
dmurph 2012/08/13 22:04:11 Done.
241 scoped_ptr<WebCanvas> canvas(canvas_provider.createCanvas(canvas_size));
242 canvas->translate(0, -y);
243 TimeTicks before_time = TimeTicks::Now();
244 picture->draw(canvas.get());
245 timeAccum += (TimeTicks::Now() - before_time);
246 }
247 return timeAccum;
248 }
249
250 int tile_height_;
251 };
252
253 class BitmapCanvasProvider : public TiledReplayBenchmark::CanvasProvider {
254 public:
255 virtual ~BitmapCanvasProvider() {}
256 virtual WebCanvas* createCanvas(const WebSize& size) const OVERRIDE {
257 SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config,
piman 2012/08/13 18:54:52 I think there's a SkTAutoUnref or something that c
dmurph 2012/08/13 22:04:11 Done.
258 size.width,
259 size.height,
260 false);
261 WebCanvas* canvas = new WebCanvas(device);
262 device->unref();
263 return canvas;
264 }
265 };
266
97 } // anonymous namespace 267 } // anonymous namespace
98 268
99 namespace content { 269 namespace content {
100 270
101 ScopedVector<RenderingBenchmark> AllRenderingBenchmarks() { 271 ScopedVector<RenderingBenchmark> AllRenderingBenchmarks() {
102 ScopedVector<RenderingBenchmark> benchmarks; 272 ScopedVector<RenderingBenchmark> benchmarks;
103 benchmarks.push_back(new BitmapCanvasPaintBenchmark( 273 benchmarks.push_back(new BitmapCanvasPaintBenchmark(
104 "PaintEverythingToBitmap", 274 "PaintEverythingToBitmap",
105 WebViewBenchmarkSupport::PaintModeEverything)); 275 WebViewBenchmarkSupport::PaintModeEverything));
106 benchmarks.push_back(new NullCanvasPaintBenchmark( 276 benchmarks.push_back(new NullCanvasPaintBenchmark(
107 "PaintEverythingToNullCanvas", 277 "PaintEverythingToNullCanvas",
108 WebViewBenchmarkSupport::PaintModeEverything)); 278 WebViewBenchmarkSupport::PaintModeEverything));
279 benchmarks.push_back(new SkPicturePaintBenchmark(
280 "PaintEverythingToSkPicture",
281 WebViewBenchmarkSupport::PaintModeEverything));
282 benchmarks.push_back(new SquareTiledReplayBenchmark(
283 "RepaintEverythingTo256x256Bitmap",
284 WebViewBenchmarkSupport::PaintModeEverything,
285 new BitmapCanvasProvider(),
286 256));
287 benchmarks.push_back(new SquareTiledReplayBenchmark(
288 "RepaintEverythingTo128x128Bitmap",
289 WebViewBenchmarkSupport::PaintModeEverything,
290 new BitmapCanvasProvider(),
291 128));
292 benchmarks.push_back(new SquareTiledReplayBenchmark(
293 "RepaintEverythingTo512x512Bitmap",
294 WebViewBenchmarkSupport::PaintModeEverything,
295 new BitmapCanvasProvider(),
296 512));
297 benchmarks.push_back(new LayerWidthTiledReplayBenchmark(
298 "RepaintEverythingToLayerWidthx256Bitmap",
299 WebViewBenchmarkSupport::PaintModeEverything,
300 new BitmapCanvasProvider(),
301 256));
302 benchmarks.push_back(new LayerWidthTiledReplayBenchmark(
303 "RepaintEverythingToLayerWidthx128Bitmap",
304 WebViewBenchmarkSupport::PaintModeEverything,
305 new BitmapCanvasProvider(),
306 128));
307 benchmarks.push_back(new LayerWidthTiledReplayBenchmark(
308 "RepaintEverythingToLayerWidthx64Bitmap",
309 WebViewBenchmarkSupport::PaintModeEverything,
310 new BitmapCanvasProvider(),
311 64));
312 benchmarks.push_back(new LayerWidthTiledReplayBenchmark(
313 "RepaintEverythingToLayerWidthx512Bitmap",
314 WebViewBenchmarkSupport::PaintModeEverything,
315 new BitmapCanvasProvider(),
316 512));
109 return benchmarks.Pass(); 317 return benchmarks.Pass();
110 } 318 }
111 319
112 } // namespace content 320 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698