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" |
Florin Malita | ab244f0 | 2017-05-03 19:16:58 +0000 | [diff] [blame] | 9 | #include "SkBitmap.h" |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 11 | #include "SkString.h" |
| 12 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 13 | class WritePixelsBench : public Benchmark { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 14 | public: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 15 | WritePixelsBench(SkColorType ct, SkAlphaType at) |
| 16 | : fColorType(ct) |
| 17 | , fAlphaType(at) |
| 18 | , fName("writepix") |
| 19 | { |
| 20 | switch (ct) { |
| 21 | case kRGBA_8888_SkColorType: |
| 22 | fName.append("_RGBA"); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 23 | break; |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 24 | case kBGRA_8888_SkColorType: |
| 25 | fName.append("_BGRA"); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 26 | break; |
skia.committer@gmail.com | c9917c0 | 2013-08-16 07:01:49 +0000 | [diff] [blame] | 27 | default: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 28 | SkASSERT(0); |
| 29 | break; |
| 30 | } |
| 31 | switch (at) { |
| 32 | case kPremul_SkAlphaType: |
| 33 | fName.append("_PM"); |
| 34 | break; |
| 35 | case kUnpremul_SkAlphaType: |
| 36 | fName.append("_UPM"); |
| 37 | break; |
| 38 | default: |
| 39 | SkASSERT(0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 40 | break; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 45 | const char* onGetName() override { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 46 | return fName.c_str(); |
| 47 | } |
| 48 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 49 | void onDraw(int loops, SkCanvas* canvas) override { |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 50 | SkISize size = canvas->getBaseLayerSize(); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 51 | |
| 52 | canvas->clear(0xFFFF0000); |
| 53 | |
| 54 | SkBitmap bmp; |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 55 | bmp.allocN32Pixels(size.width(), size.height()); |
Mike Reed | 12e946b | 2017-04-17 10:53:29 -0400 | [diff] [blame] | 56 | canvas->readPixels(bmp, 0, 0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 57 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 58 | SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType); |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 59 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 60 | for (int loop = 0; loop < loops; ++loop) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 61 | canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | private: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 66 | SkColorType fColorType; |
| 67 | SkAlphaType fAlphaType; |
| 68 | SkString fName; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 69 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 70 | typedef Benchmark INHERITED; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | ////////////////////////////////////////////////////////////////////////////// |
| 74 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 75 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType);) |
| 76 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);) |