Chromium Code Reviews| Index: content/renderer/all_rendering_benchmarks.cc |
| diff --git a/content/renderer/all_rendering_benchmarks.cc b/content/renderer/all_rendering_benchmarks.cc |
| index 6039329c4d10942e5d621e1e756fb8300c4cb51b..d96c246340e85dd3b1552c5929280942f0969ec8 100644 |
| --- a/content/renderer/all_rendering_benchmarks.cc |
| +++ b/content/renderer/all_rendering_benchmarks.cc |
| @@ -10,10 +10,12 @@ |
| #include "base/callback.h" |
| #include "base/compiler_specific.h" |
| #include "base/time.h" |
| +#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.
|
| #include "content/renderer/rendering_benchmark.h" |
| #include "content/renderer/rendering_benchmark_results.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "third_party/skia/include/core/SkDevice.h" |
| +#include "third_party/skia/include/core/SkPicture.h" |
| #include "third_party/skia/include/utils/SkNullCanvas.h" |
| #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h" |
| #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| @@ -27,6 +29,7 @@ using WebKit::WebViewBenchmarkSupport; |
| namespace { |
| +// 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.
|
| class CustomPaintBenchmark |
| : public content::RenderingBenchmark, |
| public WebViewBenchmarkSupport::PaintClient { |
| @@ -48,7 +51,7 @@ class CustomPaintBenchmark |
| } |
| virtual void Run(content::RenderingBenchmarkResults* results, |
| - WebViewBenchmarkSupport* support) { |
| + WebViewBenchmarkSupport* support) OVERRIDE { |
| paint_time_total_ = TimeDelta(); |
| support->paint(this, paint_mode_); |
| results->AddResult(name(), |
| @@ -87,13 +90,180 @@ class NullCanvasPaintBenchmark : public CustomPaintBenchmark { |
| public: |
| NullCanvasPaintBenchmark(const std::string& name, |
| WebViewBenchmarkSupport::PaintMode paint_mode) |
| - : CustomPaintBenchmark(name, paint_mode) { } |
| + : CustomPaintBenchmark(name, paint_mode), |
| + canvas_count_(0) { } |
| + |
| + virtual void Run(content::RenderingBenchmarkResults* results, |
| + WebViewBenchmarkSupport* support) OVERRIDE { |
|
piman
2012/08/13 18:54:52
nit: indentation
dmurph
2012/08/13 22:04:11
Done.
|
| + canvas_count_ = 0; |
| + CustomPaintBenchmark::Run(results, support); |
| + results->AddResult(name(), |
| + "canvasCount", |
| + "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.
|
| + canvas_count_); |
| + } |
| private: |
| virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { |
| + ++canvas_count_; |
| return SkCreateNullCanvas(); |
| } |
| + |
| + int canvas_count_; |
| +}; |
| + |
| +class SkPicturePaintBenchmark : public CustomPaintBenchmark { |
| + public: |
| + SkPicturePaintBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode) |
| + : CustomPaintBenchmark(name, paint_mode) { } |
| + |
| + virtual void didPaint(WebCanvas* canvas) OVERRIDE { |
| + CustomPaintBenchmark::didPaint(NULL); |
| + DCHECK(picture_.getRecordingCanvas() == canvas); |
| + 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.
|
| + } |
| + |
| + private: |
| + virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { |
| + return picture_.beginRecording(size.width, size.height); |
| + } |
| + |
| + SkPicture picture_; |
| +}; |
| + |
| +// Base class for timing replaying |
|
piman
2012/08/13 18:54:52
nit: .
dmurph
2012/08/13 22:04:11
Done.
|
| +class TiledReplayBenchmark |
| + : public content::RenderingBenchmark, |
| + public WebViewBenchmarkSupport::PaintClient { |
| + public: |
| + class CanvasProvider { |
| + 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
|
| + virtual ~CanvasProvider() {} |
| + virtual WebCanvas* createCanvas(const WebSize& size) const = 0; |
| + }; |
| + |
| + TiledReplayBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode, |
| + CanvasProvider* canvas_provider) |
| + : RenderingBenchmark(name), |
| + canvas_provider_(canvas_provider), |
| + paint_mode_(paint_mode) {} |
| + |
| + virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE { |
| + curr_layer_size_ = size; |
| + 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
|
| + } |
| + |
| + virtual void didPaint(WebCanvas* canvas) OVERRIDE { |
| + DCHECK(picture_.getRecordingCanvas() == canvas); |
| + picture_.endRecording(); |
| + paint_time_total_ += timeTiledRepaint(&picture_, *canvas_provider_.get()); |
| + } |
| + |
| + virtual void Run(content::RenderingBenchmarkResults* results, |
| + WebViewBenchmarkSupport* support) { |
| + paint_time_total_ = TimeDelta(); |
| + support->paint(this, paint_mode_); |
| + results->AddResult(name(), |
| + "repaintTime", |
| + "s", |
| + paint_time_total_.InSecondsF()); |
| + } |
| + |
| + protected: |
| + 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.
|
| + return curr_layer_size_; |
| + } |
| + |
| + private: |
| + virtual TimeDelta timeTiledRepaint(SkPicture* picture, |
| + const CanvasProvider& canvas_provider) = 0; |
| + |
| + TimeDelta paint_time_total_; |
| + 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.
|
| + SkPicture picture_; |
| + const scoped_ptr<CanvasProvider> canvas_provider_; |
| + const WebViewBenchmarkSupport::PaintMode paint_mode_; |
| +}; |
| + |
| +class SquareTiledReplayBenchmark : public TiledReplayBenchmark { |
| + public: |
| + SquareTiledReplayBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode, |
| + CanvasProvider* canvas_provider, |
| + int tile_size) |
| + : TiledReplayBenchmark(name, paint_mode, canvas_provider), |
| + tile_size_(tile_size) { |
| + CHECK_GT(tile_size, 0); |
| + } |
| + |
| + private: |
| + 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.
|
| + SkPicture* picture, |
| + const CanvasProvider& canvas_provider) OVERRIDE { |
| + const WebSize canvas_size(tile_size_, tile_size_); |
| + 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.
|
| + for (int x = 0; x < picture->width(); x += tile_size_) { |
| + for (int y = 0; y < picture->height(); y += tile_size_) { |
| + 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.
|
| + canvas->translate(-x, -y); |
| + 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.
|
| + picture->draw(canvas.get()); |
| + timeAccum += (TimeTicks::Now() - before_time); |
| + } |
| + } |
| + return timeAccum; |
| + } |
| + |
| + int tile_size_; |
| +}; |
| + |
| +class LayerWidthTiledReplayBenchmark : public TiledReplayBenchmark { |
| + public: |
| + LayerWidthTiledReplayBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode, |
| + CanvasProvider* canvas_provider, |
| + int tile_height) |
| + : TiledReplayBenchmark(name, paint_mode, canvas_provider), |
| + tile_height_(tile_height) { |
| + CHECK_GT(tile_height, 0); |
| + } |
| + |
| + private: |
| + virtual TimeDelta timeTiledRepaint( |
| + SkPicture* picture, |
| + const CanvasProvider& canvas_provider) OVERRIDE { |
| + const WebSize& layer_size = CurrLayerSize(); |
| + const WebSize canvas_size(layer_size.width, tile_height_); |
| + TimeDelta timeAccum; |
|
piman
2012/08/13 18:54:52
nit: style, abbrev.
dmurph
2012/08/13 22:04:11
Done.
|
| + 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.
|
| + scoped_ptr<WebCanvas> canvas(canvas_provider.createCanvas(canvas_size)); |
| + canvas->translate(0, -y); |
| + TimeTicks before_time = TimeTicks::Now(); |
| + picture->draw(canvas.get()); |
| + timeAccum += (TimeTicks::Now() - before_time); |
| + } |
| + return timeAccum; |
| + } |
| + |
| + int tile_height_; |
| }; |
| + |
| +class BitmapCanvasProvider : public TiledReplayBenchmark::CanvasProvider { |
| + public: |
| + virtual ~BitmapCanvasProvider() {} |
| + virtual WebCanvas* createCanvas(const WebSize& size) const OVERRIDE { |
| + 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.
|
| + size.width, |
| + size.height, |
| + false); |
| + WebCanvas* canvas = new WebCanvas(device); |
| + device->unref(); |
| + return canvas; |
| + } |
| +}; |
| + |
| } // anonymous namespace |
| namespace content { |
| @@ -106,6 +276,44 @@ ScopedVector<RenderingBenchmark> AllRenderingBenchmarks() { |
| benchmarks.push_back(new NullCanvasPaintBenchmark( |
| "PaintEverythingToNullCanvas", |
| WebViewBenchmarkSupport::PaintModeEverything)); |
| + benchmarks.push_back(new SkPicturePaintBenchmark( |
| + "PaintEverythingToSkPicture", |
| + WebViewBenchmarkSupport::PaintModeEverything)); |
| + benchmarks.push_back(new SquareTiledReplayBenchmark( |
| + "RepaintEverythingTo256x256Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 256)); |
| + benchmarks.push_back(new SquareTiledReplayBenchmark( |
| + "RepaintEverythingTo128x128Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 128)); |
| + benchmarks.push_back(new SquareTiledReplayBenchmark( |
| + "RepaintEverythingTo512x512Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 512)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx256Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 256)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx128Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 128)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx64Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 64)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx512Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + new BitmapCanvasProvider(), |
| + 512)); |
| return benchmarks.Pass(); |
| } |