blob: 6ea7a4f7e2a253505f49994a872e0af341b4cc20 [file] [log] [blame]
reedfbc1e292016-01-29 05:22:59 -08001/*
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"
reeddd9ffea2016-02-18 12:39:14 -08009#include "SkPM4f.h"
reedfbc1e292016-01-29 05:22:59 -080010#include "SkString.h"
reed395eabe2016-01-30 18:52:31 -080011#include "SkXfermode.h"
reedfbc1e292016-01-29 05:22:59 -080012
reedef5252e2016-02-03 09:47:46 -080013#define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict
14
reedf46d8a62016-02-02 09:27:35 -080015#define INNER_LOOPS 1000
reedfbc1e292016-01-29 05:22:59 -080016
17// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
reed8f7b0b22016-02-24 06:21:36 -080018class XferD32Bench : public Benchmark {
reedfbc1e292016-01-29 05:22:59 -080019public:
reed8f7b0b22016-02-24 06:21:36 -080020 XferD32Bench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t flags)
reed395eabe2016-01-30 18:52:31 -080021 : fDoN(doN)
reedef5252e2016-02-03 09:47:46 -080022 , fFlags(flags & ~USE_AA)
reed395eabe2016-01-30 18:52:31 -080023 {
reedcfb6bdf2016-03-29 11:32:50 -070024 fXfer = SkXfermode::Make(mode);
reed8f7b0b22016-02-24 06:21:36 -080025 fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle_D32Flag);
26 fProcN = SkXfermode::GetD32Proc(fXfer, fFlags);
reedef5252e2016-02-03 09:47:46 -080027 fName.printf("xfer4f_%s_%s_%c_%s_%s",
28 name,
29 (flags & USE_AA) ? "aa" : "bw",
30 fDoN ? 'N' : '1',
reed8f7b0b22016-02-24 06:21:36 -080031 (flags & SkXfermode::kSrcIsOpaque_D32Flag) ? "opaque" : "alpha",
32 (flags & SkXfermode::kDstIsSRGB_D32Flag) ? "srgb" : "linear");
reedfbc1e292016-01-29 05:22:59 -080033
reedfbc1e292016-01-29 05:22:59 -080034 for (int i = 0; i < N; ++i) {
reed395eabe2016-01-30 18:52:31 -080035 fSrc[i] = {{ 1, 1, 1, 1 }};
reedfbc1e292016-01-29 05:22:59 -080036 fDst[i] = 0;
reedef5252e2016-02-03 09:47:46 -080037 fAAStorage[i] = i * 255 / (N - 1);
38 }
halcanary9d524f22016-03-29 09:03:52 -070039
reedef5252e2016-02-03 09:47:46 -080040 if (flags & USE_AA) {
41 fAA = fAAStorage;
42 } else {
43 fAA = nullptr;
reedfbc1e292016-01-29 05:22:59 -080044 }
45 }
46
47protected:
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 {
reed395eabe2016-01-30 18:52:31 -080053 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
54 if (fDoN) {
reedcfb6bdf2016-03-29 11:32:50 -070055 fProcN(fXfer.get(), fDst, fSrc, N, fAA);
reed395eabe2016-01-30 18:52:31 -080056 } else {
reedcfb6bdf2016-03-29 11:32:50 -070057 fProc1(fXfer.get(), fDst, fSrc, N, fAA);
reedfbc1e292016-01-29 05:22:59 -080058 }
59 }
60 }
61
62private:
reedcfb6bdf2016-03-29 11:32:50 -070063 sk_sp<SkXfermode> fXfer;
reed8f7b0b22016-02-24 06:21:36 -080064 SkString fName;
65 SkXfermode::D32Proc fProc1;
66 SkXfermode::D32Proc fProcN;
67 const SkAlpha* fAA;
68 bool fDoN;
69 uint32_t fFlags;
reedfbc1e292016-01-29 05:22:59 -080070
71 enum {
72 N = 1000,
73 };
74 SkPM4f fSrc[N];
75 SkPMColor fDst[N];
reedef5252e2016-02-03 09:47:46 -080076 uint8_t fAAStorage[N];
reedfbc1e292016-01-29 05:22:59 -080077
78 typedef Benchmark INHERITED;
79};
80
reed395eabe2016-01-30 18:52:31 -080081#define F00 0
reed8f7b0b22016-02-24 06:21:36 -080082#define F01 (SkXfermode::kSrcIsOpaque_D32Flag)
83#define F10 (SkXfermode::kDstIsSRGB_D32Flag)
84#define F11 (SkXfermode::kSrcIsOpaque_D32Flag | SkXfermode::kDstIsSRGB_D32Flag)
reedfbc1e292016-01-29 05:22:59 -080085
reed8f7b0b22016-02-24 06:21:36 -080086DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F10); )
87DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F00); )
88DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F11); )
89DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F01); )
reed395eabe2016-01-30 18:52:31 -080090
reed8f7b0b22016-02-24 06:21:36 -080091DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F10); )
92DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F00); )
93DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F11); )
94DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F01); )
reedef5252e2016-02-03 09:47:46 -080095
reed8f7b0b22016-02-24 06:21:36 -080096DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F10 | USE_AA); )
97DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F00 | USE_AA); )
98DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F11 | USE_AA); )
99DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F01 | USE_AA); )
reedef5252e2016-02-03 09:47:46 -0800100
reed8f7b0b22016-02-24 06:21:36 -0800101DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F10 | USE_AA); )
102DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F00 | USE_AA); )
103DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F11 | USE_AA); )
104DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F01 | USE_AA); )