blob: 5e679a826e8338d6cef8775a899c06deeb6c2b2e [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"
Mike Reedd4706732016-11-15 16:44:34 -050011#include "SkXfermodePriv.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:
Mike Reed6a015542016-11-09 10:38:09 -050020 XferD32Bench(SkBlendMode 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 {
Mike Reed6a015542016-11-09 10:38:09 -050024 fMode = mode;
25 fProc1 = SkXfermode::GetD32Proc(fMode, fFlags | SkXfermode::kSrcIsSingle_D32Flag);
26 fProcN = SkXfermode::GetD32Proc(fMode, 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) {
Mike Reed6a015542016-11-09 10:38:09 -050055 fProcN(fMode, fDst, fSrc, N, fAA);
reed395eabe2016-01-30 18:52:31 -080056 } else {
Mike Reed6a015542016-11-09 10:38:09 -050057 fProc1(fMode, fDst, fSrc, N, fAA);
reedfbc1e292016-01-29 05:22:59 -080058 }
59 }
60 }
61
62private:
Mike Reed6a015542016-11-09 10:38:09 -050063 SkBlendMode fMode;
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
Mike Reed6a015542016-11-09 10:38:09 -050086DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F10); )
87DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F00); )
88DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F11); )
89DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F01); )
reed395eabe2016-01-30 18:52:31 -080090
Mike Reed6a015542016-11-09 10:38:09 -050091DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F10); )
92DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F00); )
93DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F11); )
94DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F01); )
reedef5252e2016-02-03 09:47:46 -080095
Mike Reed6a015542016-11-09 10:38:09 -050096DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F10 | USE_AA); )
97DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F00 | USE_AA); )
98DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F11 | USE_AA); )
99DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F01 | USE_AA); )
reedef5252e2016-02-03 09:47:46 -0800100
Mike Reed6a015542016-11-09 10:38:09 -0500101DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F10 | USE_AA); )
102DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F00 | USE_AA); )
103DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F11 | USE_AA); )
104DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F01 | USE_AA); )