Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // 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
| |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/public/renderer/all_rendering_benchmarks.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/time.h" | |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | |
| 11 #include "third_party/skia/include/core/SkDevice.h" | |
| 12 #include "third_party/skia/include/utils/SkNullCanvas.h" | |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h" | |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
| 15 | |
| 16 using WebKit::WebSize; | |
| 17 using WebKit::WebCanvas; | |
| 18 using WebKit::WebViewBenchmarkSupport; | |
| 19 | |
| 20 namespace { | |
| 21 typedef base::Callback<WebCanvas*(const WebSize&)> CanvasCallback; | |
| 22 | |
| 23 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
| |
| 24 : public WebViewBenchmarkSupport::PaintingController { | |
| 25 public: | |
| 26 WebCanvasFromFunctor( | |
| 27 const CanvasCallback& create_canvas_callback) | |
| 28 : create_canvas_callback_(create_canvas_callback) {} | |
| 29 virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { | |
| 30 return create_canvas_callback_.Run(size); | |
| 31 } | |
| 32 private: | |
| 33 const CanvasCallback create_canvas_callback_; | |
| 34 }; | |
| 35 | |
| 36 class CustomPaintBenchmark : public content::RenderingBenchmark { | |
| 37 public: | |
| 38 CustomPaintBenchmark( | |
| 39 const std::string& name, | |
| 40 WebViewBenchmarkSupport::PaintMode paint_mode, | |
| 41 content::RenderingBenchmarkResults* results, | |
| 42 const CanvasCallback& create_canvas_callback) | |
| 43 : content::RenderingBenchmark(name, results), | |
| 44 canvas_factory_(create_canvas_callback), | |
| 45 paint_mode_(paint_mode) { } | |
| 46 | |
| 47 virtual void Run(WebViewBenchmarkSupport* support) { | |
| 48 double paintTime = support->paint( | |
| 49 canvas_factory_, | |
| 50 paint_mode_); | |
| 51 RecordResult("paint", "s", paintTime); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 WebCanvasFromFunctor canvas_factory_; | |
| 56 const WebViewBenchmarkSupport::PaintMode paint_mode_; | |
| 57 }; | |
| 58 | |
| 59 WebCanvas* createNullCanvas(const WebSize& size) { | |
| 60 return SkCreateNullCanvas(); | |
| 61 } | |
| 62 | |
| 63 WebCanvas* createOpaqueBitmapCanvas(const WebSize& size) { | |
| 64 SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, | |
| 65 size.width, | |
| 66 size.height, | |
| 67 true); | |
| 68 WebCanvas* canvas = new WebCanvas(device); | |
| 69 device->unref(); | |
| 70 return canvas; | |
| 71 } | |
| 72 | |
| 73 WebCanvas* createTransparentBitmapCanvas(const WebSize& size) { | |
| 74 SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, | |
| 75 size.width, | |
| 76 size.height, | |
| 77 false); | |
| 78 WebCanvas* canvas = new WebCanvas(device); | |
| 79 device->unref(); | |
| 80 return canvas; | |
| 81 } | |
| 82 } // anonymous namespace | |
| 83 | |
| 84 namespace content { | |
| 85 AllRenderingBenchmarks::AllRenderingBenchmarks( | |
| 86 RenderingBenchmarkResults* results, | |
| 87 const std::string& filter) | |
| 88 : RenderingBenchmark("AllRenderingBenchmarks", results), | |
| 89 name_filter_(filter), | |
| 90 benchmark_count_(3) { | |
| 91 benchmarks_ = new RenderingBenchmark*[benchmark_count_]; | |
| 92 benchmarks_[0] = new CustomPaintBenchmark( | |
| 93 "PaintEverythingToOpaqueBitmap", | |
| 94 WebViewBenchmarkSupport::PaintModeEverything, | |
| 95 results, | |
| 96 base::Bind(&createOpaqueBitmapCanvas)); | |
| 97 benchmarks_[1] = new CustomPaintBenchmark( | |
| 98 "PaintEverythingToTransparentBitmap", | |
| 99 WebViewBenchmarkSupport::PaintModeEverything, | |
| 100 results, | |
| 101 base::Bind(&createTransparentBitmapCanvas)); | |
| 102 benchmarks_[2] = new CustomPaintBenchmark( | |
| 103 "PaintEverythingToNullCanvas", | |
| 104 WebViewBenchmarkSupport::PaintModeEverything, | |
| 105 results, | |
| 106 base::Bind(&createNullCanvas)); | |
| 107 } | |
| 108 | |
| 109 AllRenderingBenchmarks::~AllRenderingBenchmarks() { | |
| 110 for (int i = 0; i < benchmark_count_; i++) | |
| 111 delete benchmarks_[i]; | |
| 112 delete[] benchmarks_; | |
| 113 } | |
| 114 | |
| 115 void AllRenderingBenchmarks::Run( | |
| 116 WebViewBenchmarkSupport* support) { | |
| 117 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
| |
| 118 RenderingBenchmark* benchmark = benchmarks_[i]; | |
| 119 const std::string& name = benchmark->name(); | |
| 120 if (strcmp(name_filter_.c_str(), "") != 0 && | |
| 121 std::string::npos == name.find(name_filter_)) { | |
| 122 continue; | |
| 123 } | |
| 124 benchmarks_[i]->SetUp(support); | |
| 125 benchmarks_[i]->Run(support); | |
| 126 benchmarks_[i]->TearDown(support); | |
| 127 } | |
| 128 } | |
| 129 } // namespace content | |
| OLD | NEW |