commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "SkBenchmark.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkConfig8888.h" |
| 12 | #include "SkString.h" |
| 13 | |
| 14 | class WritePixelsBench : public SkBenchmark { |
| 15 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 16 | WritePixelsBench(SkCanvas::Config8888 config) |
| 17 | : fConfig(config) |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 18 | , fName("writepix") { |
| 19 | switch (config) { |
| 20 | case SkCanvas::kNative_Premul_Config8888: |
| 21 | fName.append("_native_PM"); |
| 22 | break; |
| 23 | case SkCanvas::kNative_Unpremul_Config8888: |
| 24 | fName.append("_native_UPM"); |
| 25 | break; |
| 26 | case SkCanvas::kBGRA_Premul_Config8888: |
| 27 | fName.append("_bgra_PM"); |
| 28 | break; |
| 29 | case SkCanvas::kBGRA_Unpremul_Config8888: |
| 30 | fName.append("_bgra_UPM"); |
| 31 | break; |
| 32 | case SkCanvas::kRGBA_Premul_Config8888: |
| 33 | fName.append("_rgba_PM"); |
| 34 | break; |
| 35 | case SkCanvas::kRGBA_Unpremul_Config8888: |
| 36 | fName.append("_rgba_UPM"); |
| 37 | break; |
skia.committer@gmail.com | c9917c0 | 2013-08-16 07:01:49 +0000 | [diff] [blame] | 38 | default: |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 39 | SK_CRASH(); |
| 40 | break; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | protected: |
| 45 | virtual const char* onGetName() SK_OVERRIDE { |
| 46 | return fName.c_str(); |
| 47 | } |
| 48 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 49 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 50 | SkISize size = canvas->getDeviceSize(); |
| 51 | |
| 52 | canvas->clear(0xFFFF0000); |
| 53 | |
| 54 | SkBitmap bmp; |
| 55 | bmp.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| 56 | canvas->readPixels(&bmp, 0, 0); |
| 57 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 58 | for (int loop = 0; loop < loops; ++loop) { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 59 | canvas->writePixels(bmp, 0, 0, fConfig); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | private: |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 64 | SkCanvas::Config8888 fConfig; |
| 65 | SkString fName; |
| 66 | |
| 67 | typedef SkBenchmark INHERITED; |
| 68 | }; |
| 69 | |
| 70 | ////////////////////////////////////////////////////////////////////////////// |
| 71 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 72 | DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Premul_Config8888)); ) |
| 73 | DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Unpremul_Config8888)); ) |