Index: content/public/renderer/all_rendering_benchmarks.cc |
diff --git a/content/public/renderer/all_rendering_benchmarks.cc b/content/public/renderer/all_rendering_benchmarks.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4a584f3f404de70785f115428cacada1c8f9260f |
--- /dev/null |
+++ b/content/public/renderer/all_rendering_benchmarks.cc |
@@ -0,0 +1,129 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
nduca
2012/07/18 06:06:17
why is this in public/renderer? It should be in co
dmurph
2012/07/18 16:31:41
This stuff had to be public so the old benchmarkin
|
+// found in the LICENSE file. |
+ |
+#include "content/public/renderer/all_rendering_benchmarks.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/time.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" |
+ |
+using WebKit::WebSize; |
+using WebKit::WebCanvas; |
+using WebKit::WebViewBenchmarkSupport; |
+ |
+namespace { |
+typedef base::Callback<WebCanvas*(const WebSize&)> CanvasCallback; |
+ |
+class WebCanvasFromFunctor |
nduca
2012/07/17 18:54:56
Why not just have every benchmark implement this i
dmurph
2012/07/18 16:31:41
Yes, well, it'll have multiple inheritance, but th
|
+ : public WebViewBenchmarkSupport::PaintingController { |
+ public: |
+ WebCanvasFromFunctor( |
+ const CanvasCallback& create_canvas_callback) |
+ : create_canvas_callback_(create_canvas_callback) {} |
+ virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { |
+ return create_canvas_callback_.Run(size); |
+ } |
+ private: |
+ const CanvasCallback create_canvas_callback_; |
+}; |
+ |
+class CustomPaintBenchmark : public content::RenderingBenchmark { |
+ public: |
+ CustomPaintBenchmark( |
+ const std::string& name, |
+ WebViewBenchmarkSupport::PaintMode paint_mode, |
+ content::RenderingBenchmarkResults* results, |
+ const CanvasCallback& create_canvas_callback) |
+ : content::RenderingBenchmark(name, results), |
+ canvas_factory_(create_canvas_callback), |
+ paint_mode_(paint_mode) { } |
+ |
+ virtual void Run(WebViewBenchmarkSupport* support) { |
+ double paintTime = support->paint( |
+ canvas_factory_, |
+ paint_mode_); |
+ RecordResult("paint", "s", paintTime); |
+ } |
+ |
+ private: |
+ WebCanvasFromFunctor canvas_factory_; |
+ 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( |
+ RenderingBenchmarkResults* results, |
+ const std::string& filter) |
+ : RenderingBenchmark("AllRenderingBenchmarks", results), |
+ name_filter_(filter), |
+ benchmark_count_(3) { |
+ benchmarks_ = new RenderingBenchmark*[benchmark_count_]; |
+ benchmarks_[0] = new CustomPaintBenchmark( |
+ "PaintEverythingToOpaqueBitmap", |
+ WebViewBenchmarkSupport::PaintModeEverything, |
+ results, |
+ base::Bind(&createOpaqueBitmapCanvas)); |
+ benchmarks_[1] = new CustomPaintBenchmark( |
+ "PaintEverythingToTransparentBitmap", |
+ WebViewBenchmarkSupport::PaintModeEverything, |
+ results, |
+ base::Bind(&createTransparentBitmapCanvas)); |
+ benchmarks_[2] = new CustomPaintBenchmark( |
+ "PaintEverythingToNullCanvas", |
+ WebViewBenchmarkSupport::PaintModeEverything, |
+ results, |
+ base::Bind(&createNullCanvas)); |
+} |
+ |
+AllRenderingBenchmarks::~AllRenderingBenchmarks() { |
+ for (int i = 0; i < benchmark_count_; i++) |
+ delete benchmarks_[i]; |
+ delete[] benchmarks_; |
+} |
+ |
+void AllRenderingBenchmarks::Run( |
+ WebViewBenchmarkSupport* support) { |
+ for (int i = 0; i < benchmark_count_; i++) { |
nduca
2012/07/18 06:06:17
Return a vector here with all the benchmarks in it
dmurph
2012/07/18 16:31:41
Ok, just fyi, you had previously requested to have
|
+ RenderingBenchmark* benchmark = benchmarks_[i]; |
+ const std::string& name = benchmark->name(); |
+ if (strcmp(name_filter_.c_str(), "") != 0 && |
+ std::string::npos == name.find(name_filter_)) { |
+ continue; |
+ } |
+ benchmarks_[i]->SetUp(support); |
+ benchmarks_[i]->Run(support); |
+ benchmarks_[i]->TearDown(support); |
+ } |
+} |
+} // namespace content |