commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 10 | #include "SkString.h" |
| 11 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 12 | class WritePixelsBench : public Benchmark { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 13 | public: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 14 | WritePixelsBench(SkColorType ct, SkAlphaType at) |
| 15 | : fColorType(ct) |
| 16 | , fAlphaType(at) |
| 17 | , fName("writepix") |
| 18 | { |
| 19 | switch (ct) { |
| 20 | case kRGBA_8888_SkColorType: |
| 21 | fName.append("_RGBA"); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 22 | break; |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 23 | case kBGRA_8888_SkColorType: |
| 24 | fName.append("_BGRA"); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 25 | break; |
skia.committer@gmail.com | c9917c0 | 2013-08-16 07:01:49 +0000 | [diff] [blame] | 26 | default: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 27 | SkASSERT(0); |
| 28 | break; |
| 29 | } |
| 30 | switch (at) { |
| 31 | case kPremul_SkAlphaType: |
| 32 | fName.append("_PM"); |
| 33 | break; |
| 34 | case kUnpremul_SkAlphaType: |
| 35 | fName.append("_UPM"); |
| 36 | break; |
| 37 | default: |
| 38 | SkASSERT(0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 39 | break; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | protected: |
| 44 | virtual const char* onGetName() SK_OVERRIDE { |
| 45 | return fName.c_str(); |
| 46 | } |
| 47 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 48 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 49 | SkISize size = canvas->getDeviceSize(); |
| 50 | |
| 51 | canvas->clear(0xFFFF0000); |
| 52 | |
| 53 | SkBitmap bmp; |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 54 | bmp.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 55 | canvas->readPixels(&bmp, 0, 0); |
| 56 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 57 | SkImageInfo info = bmp.info(); |
| 58 | info.fColorType = fColorType; |
| 59 | info.fAlphaType = fAlphaType; |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 60 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 61 | for (int loop = 0; loop < loops; ++loop) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 62 | canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
| 66 | private: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 67 | SkColorType fColorType; |
| 68 | SkAlphaType fAlphaType; |
| 69 | SkString fName; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 70 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 71 | typedef Benchmark INHERITED; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | ////////////////////////////////////////////////////////////////////////////// |
| 75 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 76 | DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kPremul_SkAlphaType)); ) |
| 77 | DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kUnpremul_SkAlphaType)); ) |