reed | d2ed622 | 2016-02-09 09:14: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 | d2ed622 | 2016-02-09 09:14:59 -0800 | [diff] [blame] | 10 | #include "SkString.h" |
| 11 | #include "SkXfermode.h" |
| 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 XferU64Bench : public Benchmark { |
| 19 | public: |
| 20 | XferU64Bench(bool doN, uint32_t flags) |
| 21 | : fDoN(doN) |
| 22 | , fFlags(flags & ~USE_AA) |
| 23 | { |
| 24 | SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode; |
| 25 | |
| 26 | fProc1 = SkXfermode::GetU64Proc1(mode, fFlags); |
| 27 | fProcN = SkXfermode::GetU64ProcN(mode, fFlags); |
| 28 | fName.printf("xferu64_%s_%c_%s_%s", |
| 29 | (flags & USE_AA) ? "aa" : "bw", |
| 30 | fDoN ? 'N' : '1', |
| 31 | (flags & SkXfermode::kSrcIsOpaque_U64Flag) ? "opaque" : "alpha", |
| 32 | (flags & SkXfermode::kDstIsFloat16_U64Flag) ? "f16" : "u16"); |
| 33 | |
| 34 | for (int i = 0; i < N; ++i) { |
| 35 | fSrc[i] = {{ 1, 1, 1, 1 }}; |
| 36 | fDst[i] = 0; |
| 37 | fAAStorage[i] = i * 255 / (N - 1); |
| 38 | } |
| 39 | |
| 40 | if (flags & USE_AA) { |
| 41 | fAA = fAAStorage; |
| 42 | } else { |
| 43 | fAA = nullptr; |
| 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 { |
| 53 | const SkXfermode::U64State state{ nullptr, fFlags }; |
| 54 | |
| 55 | for (int i = 0; i < loops * INNER_LOOPS; ++i) { |
| 56 | if (fDoN) { |
| 57 | fProcN(state, fDst, fSrc, N, fAA); |
| 58 | } else { |
| 59 | fProc1(state, fDst, fSrc[0], N, fAA); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | SkString fName; |
| 66 | SkXfermode::U64Proc1 fProc1; |
| 67 | SkXfermode::U64ProcN fProcN; |
| 68 | const SkAlpha* fAA; |
| 69 | bool fDoN; |
| 70 | uint32_t fFlags; |
| 71 | |
| 72 | enum { |
| 73 | N = 1000, |
| 74 | }; |
| 75 | SkPM4f fSrc[N]; |
| 76 | uint64_t fDst[N]; |
| 77 | uint8_t fAAStorage[N]; |
| 78 | |
| 79 | typedef Benchmark INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #define F00 0 |
| 83 | #define F01 (SkXfermode::kSrcIsOpaque_U64Flag) |
| 84 | #define F10 (SkXfermode::kDstIsFloat16_U64Flag) |
| 85 | #define F11 (SkXfermode::kDstIsFloat16_U64Flag | SkXfermode::kSrcIsOpaque_U64Flag) |
| 86 | |
| 87 | #if 0 |
| 88 | DEF_BENCH( return new XferU64Bench(true, F10 | USE_AA); ) |
| 89 | DEF_BENCH( return new XferU64Bench(true, F11 | USE_AA); ) |
| 90 | DEF_BENCH( return new XferU64Bench(true, F10); ) |
| 91 | DEF_BENCH( return new XferU64Bench(true, F11); ) |
| 92 | |
| 93 | DEF_BENCH( return new XferU64Bench(true, F00 | USE_AA); ) |
| 94 | DEF_BENCH( return new XferU64Bench(true, F01 | USE_AA); ) |
| 95 | DEF_BENCH( return new XferU64Bench(true, F00); ) |
| 96 | DEF_BENCH( return new XferU64Bench(true, F01); ) |
| 97 | #endif |
| 98 | |
| 99 | DEF_BENCH( return new XferU64Bench(false, F10 | USE_AA); ) |
| 100 | DEF_BENCH( return new XferU64Bench(false, F11 | USE_AA); ) |
| 101 | DEF_BENCH( return new XferU64Bench(false, F10); ) |
| 102 | DEF_BENCH( return new XferU64Bench(false, F11); ) |
| 103 | |
| 104 | DEF_BENCH( return new XferU64Bench(false, F00 | USE_AA); ) |
| 105 | DEF_BENCH( return new XferU64Bench(false, F01 | USE_AA); ) |
| 106 | DEF_BENCH( return new XferU64Bench(false, F00); ) |
| 107 | DEF_BENCH( return new XferU64Bench(false, F01); ) |