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

Unified 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: highres time 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..efd799da2dc2124860b8e21dfaae5a23c05d9c0a 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 {
@@ -38,17 +45,17 @@ class CustomPaintBenchmark
virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE {
WebCanvas* canvas = createCanvas(size);
- before_time_ = TimeTicks::Now();
+ before_time_ = TimeTicks::HighResNow();
return canvas;
}
virtual void didPaint(WebCanvas* canvas) OVERRIDE {
- paint_time_total_ += (TimeTicks::Now() - before_time_);
+ paint_time_total_ += (TimeTicks::HighResNow() - before_time_);
delete canvas;
}
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;
+ for (it = repaint_tiles.begin(); it != repaint_tiles.end(); ++it) {
+ WebRect tile = *it;
+ scoped_ptr<WebCanvas> canvas(
+ skia::CreateBitmapCanvas(tile.width, tile.height, false));
+ TimeTicks before_time = TimeTicks::HighResNow();
+ canvas->translate(-tile.x, -tile.y);
+ picture_.draw(canvas.get());
+ paint_time_total_ += (TimeTicks::HighResNow() - 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();
}
« 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