reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Copyright 2016 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "Benchmark.h" |
| 10 | #include "SkString.h" |
| 11 | #include "SkXfer4f.h" |
| 12 | |
| 13 | #define INNER_LOOPS 100 |
| 14 | |
| 15 | // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode. |
| 16 | class Xfer4fBench : public Benchmark { |
| 17 | public: |
| 18 | Xfer4fBench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t flags) : fDoN(doN) { |
| 19 | fProc1 = SkPM4fXfer1ProcFactory(mode, flags); |
| 20 | fProcN = SkPM4fXferNProcFactory(mode, flags); |
| 21 | fName.printf("xfer4f_%s_%c_%s_%s", name, fDoN ? 'N' : '1', |
| 22 | (flags & kSrcIsOpaque_SkXfer4fFlag) ? "opaque" : "alpha", |
| 23 | (flags & kDstIsSRGB_SkXfer4fFlag) ? "srgb" : "linear"); |
| 24 | |
| 25 | SkPM4f c; |
| 26 | c.fVec[0] = 1; c.fVec[1] = 1; c.fVec[2] = 1; c.fVec[3] = 1; |
| 27 | for (int i = 0; i < N; ++i) { |
| 28 | fSrc[i] = c; |
| 29 | fDst[i] = 0; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | protected: |
| 34 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 35 | |
| 36 | const char* onGetName() override { return fName.c_str(); } |
| 37 | |
| 38 | void onDraw(int loops, SkCanvas*) override { |
| 39 | for (int i = 0; i < loops; ++i) { |
| 40 | for (int j = 0; j < INNER_LOOPS; ++j) { |
| 41 | if (fDoN) { |
| 42 | fProcN(fDst, fSrc, N); |
| 43 | } else { |
| 44 | fProc1(fDst, fSrc[0], N); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | SkString fName; |
| 52 | SkPM4fXfer1Proc fProc1; |
| 53 | SkPM4fXferNProc fProcN; |
| 54 | bool fDoN; |
| 55 | |
| 56 | enum { |
| 57 | N = 1000, |
| 58 | }; |
| 59 | SkPM4f fSrc[N]; |
| 60 | SkPMColor fDst[N]; |
| 61 | |
| 62 | typedef Benchmark INHERITED; |
| 63 | }; |
| 64 | |
| 65 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, kDstIsSRGB_SkXfer4fFlag); ) |
| 66 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, 0); ) |
| 67 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, kDstIsSRGB_SkXfer4fFlag | kSrcIsOpaque_SkXfer4fFlag); ) |
| 68 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, kSrcIsOpaque_SkXfer4fFlag); ) |
| 69 | |
| 70 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, kDstIsSRGB_SkXfer4fFlag); ) |
| 71 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, 0); ) |
| 72 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, kDstIsSRGB_SkXfer4fFlag | kSrcIsOpaque_SkXfer4fFlag); ) |
| 73 | DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, kSrcIsOpaque_SkXfer4fFlag); ) |