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