blob: 0cc2ba131a65425afdf58a8f115f0cc21bf75985 [file] [log] [blame]
reedd2ed6222016-02-09 09:14: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"
9#include "SkString.h"
10#include "SkXfermode.h"
11
12#define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict
13
14#define INNER_LOOPS 1000
15
16// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
17class XferU64Bench : public Benchmark {
18public:
19 XferU64Bench(bool doN, uint32_t flags)
20 : fDoN(doN)
21 , fFlags(flags & ~USE_AA)
22 {
23 SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode;
24
25 fProc1 = SkXfermode::GetU64Proc1(mode, fFlags);
26 fProcN = SkXfermode::GetU64ProcN(mode, fFlags);
27 fName.printf("xferu64_%s_%c_%s_%s",
28 (flags & USE_AA) ? "aa" : "bw",
29 fDoN ? 'N' : '1',
30 (flags & SkXfermode::kSrcIsOpaque_U64Flag) ? "opaque" : "alpha",
31 (flags & SkXfermode::kDstIsFloat16_U64Flag) ? "f16" : "u16");
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
46protected:
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 const SkXfermode::U64State state{ nullptr, fFlags };
53
54 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
55 if (fDoN) {
56 fProcN(state, fDst, fSrc, N, fAA);
57 } else {
58 fProc1(state, fDst, fSrc[0], N, fAA);
59 }
60 }
61 }
62
63private:
64 SkString fName;
65 SkXfermode::U64Proc1 fProc1;
66 SkXfermode::U64ProcN fProcN;
67 const SkAlpha* fAA;
68 bool fDoN;
69 uint32_t fFlags;
70
71 enum {
72 N = 1000,
73 };
74 SkPM4f fSrc[N];
75 uint64_t fDst[N];
76 uint8_t fAAStorage[N];
77
78 typedef Benchmark INHERITED;
79};
80
81#define F00 0
82#define F01 (SkXfermode::kSrcIsOpaque_U64Flag)
83#define F10 (SkXfermode::kDstIsFloat16_U64Flag)
84#define F11 (SkXfermode::kDstIsFloat16_U64Flag | SkXfermode::kSrcIsOpaque_U64Flag)
85
86#if 0
87DEF_BENCH( return new XferU64Bench(true, F10 | USE_AA); )
88DEF_BENCH( return new XferU64Bench(true, F11 | USE_AA); )
89DEF_BENCH( return new XferU64Bench(true, F10); )
90DEF_BENCH( return new XferU64Bench(true, F11); )
91
92DEF_BENCH( return new XferU64Bench(true, F00 | USE_AA); )
93DEF_BENCH( return new XferU64Bench(true, F01 | USE_AA); )
94DEF_BENCH( return new XferU64Bench(true, F00); )
95DEF_BENCH( return new XferU64Bench(true, F01); )
96#endif
97
98DEF_BENCH( return new XferU64Bench(false, F10 | USE_AA); )
99DEF_BENCH( return new XferU64Bench(false, F11 | USE_AA); )
100DEF_BENCH( return new XferU64Bench(false, F10); )
101DEF_BENCH( return new XferU64Bench(false, F11); )
102
103DEF_BENCH( return new XferU64Bench(false, F00 | USE_AA); )
104DEF_BENCH( return new XferU64Bench(false, F01 | USE_AA); )
105DEF_BENCH( return new XferU64Bench(false, F00); )
106DEF_BENCH( return new XferU64Bench(false, F01); )