reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [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" |
| 9 | #include "SkPM4f.h" |
| 10 | #include "SkString.h" |
Mike Reed | d470673 | 2016-11-15 16:44:34 -0500 | [diff] [blame] | 11 | #include "SkXfermodePriv.h" |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 12 | |
| 13 | #define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict |
| 14 | |
| 15 | #define INNER_LOOPS 1000 |
| 16 | |
| 17 | // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode. |
| 18 | class XferF16Bench : public Benchmark { |
| 19 | public: |
Mike Reed | 6a01554 | 2016-11-09 10:38:09 -0500 | [diff] [blame] | 20 | XferF16Bench(SkBlendMode mode, const char name[], bool doN, uint32_t flags) |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 21 | : fDoN(doN) |
| 22 | , fFlags(flags & ~USE_AA) |
| 23 | { |
Mike Reed | 6a01554 | 2016-11-09 10:38:09 -0500 | [diff] [blame] | 24 | fMode = mode; |
| 25 | fProc1 = SkXfermode::GetF16Proc(mode, fFlags | SkXfermode::kSrcIsSingle_F16Flag); |
| 26 | fProcN = SkXfermode::GetF16Proc(mode, fFlags); |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 27 | fName.printf("xferF16_%s_%s_%c_%s", |
| 28 | name, |
| 29 | (flags & USE_AA) ? "aa" : "bw", |
| 30 | fDoN ? 'N' : '1', |
| 31 | (flags & SkXfermode::kSrcIsOpaque_F16Flag) ? "opaque" : "alpha"); |
| 32 | |
| 33 | for (int i = 0; i < N; ++i) { |
| 34 | fSrc[i] = {{ 1, 1, 1, 1 }}; |
| 35 | fDst[i] = 0; |
| 36 | fAAStorage[i] = i * 255 / (N - 1); |
| 37 | } |
| 38 | |
| 39 | if (flags & USE_AA) { |
| 40 | fAA = fAAStorage; |
| 41 | } else { |
| 42 | fAA = nullptr; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | protected: |
| 47 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 48 | |
| 49 | const char* onGetName() override { return fName.c_str(); } |
| 50 | |
| 51 | void onDraw(int loops, SkCanvas*) override { |
| 52 | for (int i = 0; i < loops * INNER_LOOPS; ++i) { |
| 53 | if (fDoN) { |
Mike Reed | 6a01554 | 2016-11-09 10:38:09 -0500 | [diff] [blame] | 54 | fProcN(fMode, fDst, fSrc, N, fAA); |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 55 | } else { |
Mike Reed | 6a01554 | 2016-11-09 10:38:09 -0500 | [diff] [blame] | 56 | fProc1(fMode, fDst, fSrc, N, fAA); |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | private: |
Mike Reed | 6a01554 | 2016-11-09 10:38:09 -0500 | [diff] [blame] | 62 | SkBlendMode fMode; |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 63 | SkString fName; |
| 64 | SkXfermode::F16Proc fProc1; |
| 65 | SkXfermode::F16Proc fProcN; |
| 66 | const SkAlpha* fAA; |
| 67 | bool fDoN; |
| 68 | uint32_t fFlags; |
| 69 | |
| 70 | enum { |
| 71 | N = 1000, |
| 72 | }; |
| 73 | SkPM4f fSrc[N]; |
| 74 | uint64_t fDst[N]; |
| 75 | uint8_t fAAStorage[N]; |
| 76 | |
| 77 | typedef Benchmark INHERITED; |
| 78 | }; |
| 79 | |
| 80 | #define F00 0 |
| 81 | #define F01 (SkXfermode::kSrcIsOpaque_F16Flag) |
| 82 | |
Mike Reed | 6a01554 | 2016-11-09 10:38:09 -0500 | [diff] [blame] | 83 | #define MODE SkBlendMode::kSrcOver |
reed | 3dc6aac | 2016-04-14 09:02:14 -0700 | [diff] [blame] | 84 | #define NAME "srcover" |
| 85 | |
| 86 | DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F00 | USE_AA); ) |
| 87 | DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F01 | USE_AA); ) |
| 88 | DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F00); ) |
| 89 | DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F01); ) |
| 90 | |
| 91 | DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F00 | USE_AA); ) |
| 92 | DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F01 | USE_AA); ) |
| 93 | DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F00); ) |
| 94 | DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F01); ) |