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..9aeade7b8f38af49f9463739729699814b6578e1 100644 |
| --- a/content/renderer/all_rendering_benchmarks.cc |
| +++ b/content/renderer/all_rendering_benchmarks.cc |
| @@ -4,18 +4,21 @@ |
| #include "content/renderer/all_rendering_benchmarks.h" |
| +#include <algorithm> |
| #include <string> |
| +#include <vector> |
| #include "base/bind.h" |
| #include "base/callback.h" |
| #include "base/compiler_specific.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/time.h" |
| #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 "skia/ext/platform_canvas.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/WebRect.h" |
| #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h" |
| @@ -24,9 +27,13 @@ using base::TimeTicks; |
| using WebKit::WebSize; |
| using WebKit::WebCanvas; |
| using WebKit::WebViewBenchmarkSupport; |
| +using WebKit::WebRect; |
| +using std::vector; |
| namespace { |
| +// This is a base class for timing the painting of the current webpage to |
| +// custom WebCanvases. |
| class CustomPaintBenchmark |
| : public content::RenderingBenchmark, |
| public WebViewBenchmarkSupport::PaintClient { |
| @@ -48,7 +55,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(), |
| @@ -73,13 +80,7 @@ class BitmapCanvasPaintBenchmark : public CustomPaintBenchmark { |
| private: |
| virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { |
| - SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, |
| - size.width, |
| - size.height, |
| - false); |
| - WebCanvas* canvas = new WebCanvas(device); |
| - device->unref(); |
| - return canvas; |
| + return skia::CreateBitmapCanvas(size.width, size.height, false); |
| } |
| }; |
| @@ -87,13 +88,150 @@ 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 { |
| + canvas_count_ = 0; |
| + CustomPaintBenchmark::Run(results, support); |
| + results->AddResult(name(), |
| + "canvasCount", |
| + "i", |
| + 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 { |
| + DCHECK(picture_.getRecordingCanvas() == canvas); |
| + picture_.endRecording(); |
| + CustomPaintBenchmark::didPaint(NULL); |
| + } |
| + |
| + private: |
| + virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { |
| + return picture_.beginRecording(size.width, size.height); |
| + } |
| + |
| + SkPicture picture_; |
| +}; |
| + |
| +// Base class for timing the replaying of the SkPicture into canvases. |
| +class TiledReplayBenchmark |
| + : public content::RenderingBenchmark, |
| + public WebViewBenchmarkSupport::PaintClient { |
| + public: |
| + TiledReplayBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode) |
| + : RenderingBenchmark(name), |
| + paint_mode_(paint_mode) {} |
| + |
| + virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE { |
| + return picture_.beginRecording(size.width, size.height); |
| + } |
| + |
| + virtual void didPaint(WebCanvas* canvas) OVERRIDE { |
| + DCHECK(picture_.getRecordingCanvas() == canvas); |
| + picture_.endRecording(); |
| + |
| + const vector<WebRect> repaint_tiles = GetRepaintTiles( |
| + WebSize(picture_.width(), picture_.height())); |
| + |
| + vector<WebRect>::const_iterator it; |
| + TimeTicks before_time = TimeTicks::Now(); |
| + for (it = repaint_tiles.begin(); it != repaint_tiles.end(); ++it) { |
| + WebRect tile = *it; |
| + scoped_ptr<WebCanvas> canvas( |
|
nduca
2012/08/15 17:36:48
is your intent to measure the canvas creation cost
dmurph
2012/08/15 19:12:07
Done.
|
| + skia::CreateBitmapCanvas(tile.width, tile.height, false)); |
| + canvas->translate(-tile.x, -tile.y); |
| + picture_.draw(canvas.get()); |
| + } |
| + paint_time_total_ += (TimeTicks::Now() - before_time); |
| + } |
| + |
| + 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()); |
| + } |
| + |
| + private: |
| + virtual vector<WebRect> GetRepaintTiles(const WebSize& layer_size) const = 0; |
| + |
| + TimeDelta paint_time_total_; |
| + SkPicture picture_; |
| + const WebViewBenchmarkSupport::PaintMode paint_mode_; |
| }; |
| + |
| +class SquareTiledReplayBenchmark : public TiledReplayBenchmark { |
| + public: |
| + SquareTiledReplayBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode, |
| + int tile_size) |
| + : TiledReplayBenchmark(name, paint_mode), |
| + tile_size_(tile_size) { |
| + CHECK_GT(tile_size, 0); |
| + } |
| + |
| + private: |
| + virtual vector<WebRect> GetRepaintTiles( |
| + const WebSize& layer_size) const OVERRIDE { |
| + vector<WebRect> tiles; |
| + for (int x = 0; x < layer_size.width; x += tile_size_) { |
| + for (int y = 0; y < layer_size.height; y += tile_size_) { |
| + int width = std::min(layer_size.width - x, tile_size_); |
| + int height = std::min(layer_size.height - y, tile_size_); |
| + tiles.push_back(WebRect(x, y, width, height)); |
| + } |
| + } |
| + return tiles; |
| + } |
| + |
| + int tile_size_; |
| +}; |
| + |
| +class LayerWidthTiledReplayBenchmark : public TiledReplayBenchmark { |
| + public: |
| + LayerWidthTiledReplayBenchmark(const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode, |
| + int tile_height) |
| + : TiledReplayBenchmark(name, paint_mode), |
| + tile_height_(tile_height) { |
| + CHECK_GT(tile_height, 0); |
| + } |
| + |
| + private: |
| + virtual vector<WebRect> GetRepaintTiles( |
| + const WebSize& layer_size) const OVERRIDE { |
| + vector<WebRect> tiles; |
| + for (int y = 0; y < layer_size.height; y += tile_height_) { |
| + int height = std::min(layer_size.height - y, tile_height_); |
| + tiles.push_back(WebRect(0, y, layer_size.width, height)); |
| + } |
| + return tiles; |
| + } |
| + |
| + int tile_height_; |
| +}; |
| + |
| } // anonymous namespace |
| namespace content { |
| @@ -106,6 +244,37 @@ 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, |
| + 256)); |
| + benchmarks.push_back(new SquareTiledReplayBenchmark( |
| + "RepaintEverythingTo128x128Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + 128)); |
| + benchmarks.push_back(new SquareTiledReplayBenchmark( |
| + "RepaintEverythingTo512x512Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + 512)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx256Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + 256)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx128Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + 128)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx64Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + 64)); |
| + benchmarks.push_back(new LayerWidthTiledReplayBenchmark( |
| + "RepaintEverythingToLayerWidthx512Bitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + 512)); |
| return benchmarks.Pass(); |
| } |