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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkString.h" |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 12 | |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 13 | // Time variants of write-pixels |
| 14 | // [ colortype ][ alphatype ][ colorspace ] |
| 15 | // Different combinations can trigger fast or slow paths in the impls |
| 16 | // |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 17 | class WritePixelsBench : public Benchmark { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 18 | public: |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 19 | WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 20 | : fColorType(ct) |
| 21 | , fAlphaType(at) |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 22 | , fCS(cs) |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 23 | { |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 24 | fName.printf("writepix_%s_%s_%s", |
| 25 | at == kPremul_SkAlphaType ? "pm" : "um", |
| 26 | ct == kRGBA_8888_SkColorType ? "rgba" : "bgra", |
| 27 | cs ? "srgb" : "null"); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 31 | const char* onGetName() override { |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 32 | return fName.c_str(); |
| 33 | } |
| 34 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 35 | void onDraw(int loops, SkCanvas* canvas) override { |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 36 | SkISize size = canvas->getBaseLayerSize(); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 37 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 38 | SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fCS); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 39 | SkBitmap bmp; |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 40 | bmp.allocPixels(info); |
| 41 | bmp.eraseColor(SK_ColorBLACK); |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 42 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 43 | for (int loop = 0; loop < loops; ++loop) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 44 | canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | private: |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 49 | SkColorType fColorType; |
| 50 | SkAlphaType fAlphaType; |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 51 | sk_sp<SkColorSpace> fCS; |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 52 | SkString fName; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 53 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 54 | using INHERITED = Benchmark; |
commit-bot@chromium.org | 8f42697 | 2013-08-16 00:40:34 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | ////////////////////////////////////////////////////////////////////////////// |
| 58 | |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 59 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);) |
| 60 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);) |
| 61 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());) |
| 62 | DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());) |
| 63 | |
| 64 | DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);) |
| 65 | DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);) |
| 66 | DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());) |
| 67 | DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());) |