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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/all_rendering_benchmarks.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/time.h" | |
| 10 #include "content/renderer/rendering_benchmark.h" | |
| 11 #include "content/renderer/rendering_benchmark_results.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | |
| 13 #include "third_party/skia/include/core/SkDevice.h" | |
| 14 #include "third_party/skia/include/utils/SkNullCanvas.h" | |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h" | |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" | |
| 18 | |
| 19 using base::TimeDelta; | |
| 20 using base::TimeTicks; | |
| 21 using WebKit::WebSize; | |
| 22 using WebKit::WebCanvas; | |
| 23 using WebKit::WebViewBenchmarkSupport; | |
| 24 | |
| 25 namespace { | |
| 26 typedef base::Callback<WebCanvas*(const WebSize&)> CanvasCallback; | |
| 27 | |
| 28 class CustomPaintBenchmark | |
| 29 : public content::RenderingBenchmark, | |
| 30 public WebViewBenchmarkSupport::PaintClient { | |
| 31 public: | |
| 32 CustomPaintBenchmark( | |
| 33 const std::string& name, | |
| 34 WebViewBenchmarkSupport::PaintMode paint_mode, | |
| 35 const CanvasCallback& create_canvas_callback) | |
| 36 : content::RenderingBenchmark(name), | |
| 37 create_canvas_callback_(create_canvas_callback), | |
| 38 paint_mode_(paint_mode) { } | |
| 39 | |
| 40 virtual void willPaint(const WebCanvas& /* canvas */) { | |
| 41 beforeTime = TimeTicks::Now(); | |
| 42 } | |
| 43 | |
| 44 virtual void didPaint(const WebCanvas& /* canvas */) { | |
| 45 paintTimeTotal += (TimeTicks::Now() - beforeTime); | |
| 46 } | |
| 47 | |
| 48 virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE { | |
| 49 return create_canvas_callback_.Run(size); | |
| 50 } | |
| 51 | |
| 52 virtual void Run(content::RenderingBenchmarkResults* results, | |
| 53 WebViewBenchmarkSupport* support) { | |
| 54 paintTimeTotal = TimeDelta(); | |
| 55 support->paint(this, paint_mode_); | |
| 56 results->addResult(name(), "paintTime", "s", paintTimeTotal.InSecondsF()); | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 TimeTicks beforeTime; | |
| 61 TimeDelta paintTimeTotal; | |
| 62 const CanvasCallback create_canvas_callback_; | |
| 63 const WebViewBenchmarkSupport::PaintMode paint_mode_; | |
| 64 }; | |
| 65 | |
| 66 WebCanvas* createNullCanvas(const WebSize& size) { | |
| 67 return SkCreateNullCanvas(); | |
| 68 } | |
| 69 | |
| 70 WebCanvas* createOpaqueBitmapCanvas(const WebSize& size) { | |
| 71 SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, | |
| 72 size.width, | |
| 73 size.height, | |
| 74 true); | |
| 75 WebCanvas* canvas = new WebCanvas(device); | |
| 76 device->unref(); | |
| 77 return canvas; | |
| 78 } | |
| 79 | |
| 80 WebCanvas* createTransparentBitmapCanvas(const WebSize& size) { | |
| 81 SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config, | |
| 82 size.width, | |
| 83 size.height, | |
| 84 false); | |
| 85 WebCanvas* canvas = new WebCanvas(device); | |
| 86 device->unref(); | |
| 87 return canvas; | |
| 88 } | |
| 89 } // anonymous namespace | |
| 90 | |
| 91 namespace content { | |
| 92 | |
| 93 AllRenderingBenchmarks::AllRenderingBenchmarks() { | |
| 94 benchmarks_.push_back(new CustomPaintBenchmark( | |
| 95 "PaintEverythingToOpaqueBitmap", | |
| 96 WebViewBenchmarkSupport::PaintModeEverything, | |
| 97 base::Bind(&createOpaqueBitmapCanvas))); | |
| 98 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.
| |
| 99 "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.
| |
| 100 WebViewBenchmarkSupport::PaintModeEverything, | |
| 101 base::Bind(&createTransparentBitmapCanvas))); | |
| 102 benchmarks_.push_back(new CustomPaintBenchmark( | |
| 103 "PaintEverythingToNullCanvas", | |
| 104 WebViewBenchmarkSupport::PaintModeEverything, | |
| 105 base::Bind(&createNullCanvas))); | |
| 106 } | |
| 107 AllRenderingBenchmarks::~AllRenderingBenchmarks() {} | |
| 108 | |
| 109 const std::vector<RenderingBenchmark*>& AllRenderingBenchmarks::benchmarks() { | |
| 110 return benchmarks_.get(); | |
| 111 } | |
| 112 | |
| 113 } // namespace content | |
| OLD | NEW |