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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..253c8d6132bb1b7aae03c82e215a7afc28cb67ad |
| --- /dev/null |
| +++ b/content/renderer/all_rendering_benchmarks.cc |
| @@ -0,0 +1,113 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/all_rendering_benchmarks.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.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 "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" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h" |
| + |
| +using base::TimeDelta; |
| +using base::TimeTicks; |
| +using WebKit::WebSize; |
| +using WebKit::WebCanvas; |
| +using WebKit::WebViewBenchmarkSupport; |
| + |
| +namespace { |
| +typedef base::Callback<WebCanvas*(const WebSize&)> CanvasCallback; |
| + |
| +class CustomPaintBenchmark |
| + : public content::RenderingBenchmark, |
| + public WebViewBenchmarkSupport::PaintClient { |
| + public: |
| + CustomPaintBenchmark( |
| + const std::string& name, |
| + WebViewBenchmarkSupport::PaintMode paint_mode, |
| + const CanvasCallback& create_canvas_callback) |
| + : content::RenderingBenchmark(name), |
| + create_canvas_callback_(create_canvas_callback), |
| + paint_mode_(paint_mode) { } |
| + |
| + virtual void willPaint(const WebCanvas& /* canvas */) { |
| + beforeTime = TimeTicks::Now(); |
| + } |
| + |
| + virtual void didPaint(const WebCanvas& /* canvas */) { |
| + paintTimeTotal += (TimeTicks::Now() - beforeTime); |
| + } |
| + |
| + virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { |
| + return create_canvas_callback_.Run(size); |
| + } |
| + |
| + virtual void Run(content::RenderingBenchmarkResults* results, |
| + WebViewBenchmarkSupport* support) { |
| + paintTimeTotal = TimeDelta(); |
| + support->paint(this, paint_mode_); |
| + results->addResult(name(), "paintTime", "s", paintTimeTotal.InSecondsF()); |
| + } |
| + |
| + private: |
| + TimeTicks beforeTime; |
| + TimeDelta paintTimeTotal; |
| + const CanvasCallback create_canvas_callback_; |
| + const WebViewBenchmarkSupport::PaintMode paint_mode_; |
| +}; |
| + |
| +WebCanvas* createNullCanvas(const WebSize& size) { |
| + return SkCreateNullCanvas(); |
| +} |
| + |
| +WebCanvas* createOpaqueBitmapCanvas(const WebSize& size) { |
| + SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, |
| + size.width, |
| + size.height, |
| + true); |
| + WebCanvas* canvas = new WebCanvas(device); |
| + device->unref(); |
| + return canvas; |
| +} |
| + |
| +WebCanvas* createTransparentBitmapCanvas(const WebSize& size) { |
| + SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, |
| + size.width, |
| + size.height, |
| + false); |
| + WebCanvas* canvas = new WebCanvas(device); |
| + device->unref(); |
| + return canvas; |
| +} |
| +} // anonymous namespace |
| + |
| +namespace content { |
| + |
| +AllRenderingBenchmarks::AllRenderingBenchmarks() { |
| + benchmarks_.push_back(new CustomPaintBenchmark( |
| + "PaintEverythingToOpaqueBitmap", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + base::Bind(&createOpaqueBitmapCanvas))); |
| + benchmarks_.push_back(new CustomPaintBenchmark( |
|
nduca
2012/07/19 08:39:08
Not sure we need this case.... or rather, there's
dmurph
2012/07/20 20:20:36
I'll just do the one transparent then.
|
| + "PaintEverythingToTransparentBitmap", |
|
nduca
2012/07/19 08:39:08
Pending whether we need this transparent vs opaque
dmurph
2012/07/20 20:20:36
Sounds good, done.
|
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + base::Bind(&createTransparentBitmapCanvas))); |
| + benchmarks_.push_back(new CustomPaintBenchmark( |
| + "PaintEverythingToNullCanvas", |
| + WebViewBenchmarkSupport::PaintModeEverything, |
| + base::Bind(&createNullCanvas))); |
| +} |
| +AllRenderingBenchmarks::~AllRenderingBenchmarks() {} |
| + |
| +const std::vector<RenderingBenchmark*>& AllRenderingBenchmarks::benchmarks() { |
| + return benchmarks_.get(); |
| +} |
| + |
| +} // namespace content |