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: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 44 | const char* onGetName() override { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 45 | return fName.c_str(); |
| 46 | } |
| 47 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 48 | void onDraw(int loops, SkCanvas* canvas) 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 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 57 | SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType); |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 58 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 59 | for (int loop = 0; loop < loops; ++loop) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 60 | canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | private: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 65 | SkColorType fColorType; |
| 66 | SkAlphaType fAlphaType; |
| 67 | SkString fName; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 68 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 69 | typedef Benchmark INHERITED; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | ////////////////////////////////////////////////////////////////////////////// |
| 73 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 74 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType);) |
| 75 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);) |