reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 8 | #include "Benchmark.h" |
reed | dd9ffea | 2016-02-18 12:39:14 -0800 | [diff] [blame] | 9 | #include "SkPM4f.h" |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 10 | #include "SkString.h" |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 11 | #include "SkXfermode.h" |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 12 | |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 13 | #define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict |
| 14 | |
reed | f46d8a6 | 2016-02-02 09:27:35 -0800 | [diff] [blame] | 15 | #define INNER_LOOPS 1000 |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 16 | |
| 17 | // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode. |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 18 | class XferD32Bench : public Benchmark { |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 19 | public: |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 20 | XferD32Bench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t flags) |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 21 | : fDoN(doN) |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 22 | , fFlags(flags & ~USE_AA) |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 23 | { |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 24 | fXfer = SkXfermode::Make(mode); |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 25 | fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle_D32Flag); |
| 26 | fProcN = SkXfermode::GetD32Proc(fXfer, fFlags); |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 27 | fName.printf("xfer4f_%s_%s_%c_%s_%s", |
| 28 | name, |
| 29 | (flags & USE_AA) ? "aa" : "bw", |
| 30 | fDoN ? 'N' : '1', |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 31 | (flags & SkXfermode::kSrcIsOpaque_D32Flag) ? "opaque" : "alpha", |
| 32 | (flags & SkXfermode::kDstIsSRGB_D32Flag) ? "srgb" : "linear"); |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 33 | |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 34 | for (int i = 0; i < N; ++i) { |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 35 | fSrc[i] = {{ 1, 1, 1, 1 }}; |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 36 | fDst[i] = 0; |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 37 | fAAStorage[i] = i * 255 / (N - 1); |
| 38 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 39 | |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 40 | if (flags & USE_AA) { |
| 41 | fAA = fAAStorage; |
| 42 | } else { |
| 43 | fAA = nullptr; |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | protected: |
| 48 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 49 | |
| 50 | const char* onGetName() override { return fName.c_str(); } |
| 51 | |
| 52 | void onDraw(int loops, SkCanvas*) override { |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 53 | for (int i = 0; i < loops * INNER_LOOPS; ++i) { |
| 54 | if (fDoN) { |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 55 | fProcN(fXfer.get(), fDst, fSrc, N, fAA); |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 56 | } else { |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 57 | fProc1(fXfer.get(), fDst, fSrc, N, fAA); |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | private: |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 63 | sk_sp<SkXfermode> fXfer; |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 64 | SkString fName; |
| 65 | SkXfermode::D32Proc fProc1; |
| 66 | SkXfermode::D32Proc fProcN; |
| 67 | const SkAlpha* fAA; |
| 68 | bool fDoN; |
| 69 | uint32_t fFlags; |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 70 | |
| 71 | enum { |
| 72 | N = 1000, |
| 73 | }; |
| 74 | SkPM4f fSrc[N]; |
| 75 | SkPMColor fDst[N]; |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 76 | uint8_t fAAStorage[N]; |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 77 | |
| 78 | typedef Benchmark INHERITED; |
| 79 | }; |
| 80 | |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 81 | #define F00 0 |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 82 | #define F01 (SkXfermode::kSrcIsOpaque_D32Flag) |
| 83 | #define F10 (SkXfermode::kDstIsSRGB_D32Flag) |
| 84 | #define F11 (SkXfermode::kSrcIsOpaque_D32Flag | SkXfermode::kDstIsSRGB_D32Flag) |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 85 | |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 86 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F10); ) |
| 87 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F00); ) |
| 88 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F11); ) |
| 89 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F01); ) |
reed | 395eabe | 2016-01-30 18:52:31 -0800 | [diff] [blame] | 90 | |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 91 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F10); ) |
| 92 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F00); ) |
| 93 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F11); ) |
| 94 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F01); ) |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 95 | |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 96 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F10 | USE_AA); ) |
| 97 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F00 | USE_AA); ) |
| 98 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F11 | USE_AA); ) |
| 99 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F01 | USE_AA); ) |
reed | ef5252e | 2016-02-03 09:47:46 -0800 | [diff] [blame] | 100 | |
reed | 8f7b0b2 | 2016-02-24 06:21:36 -0800 | [diff] [blame] | 101 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F10 | USE_AA); ) |
| 102 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F00 | USE_AA); ) |
| 103 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F11 | USE_AA); ) |
| 104 | DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F01 | USE_AA); ) |