blob: 75aada60d7aed86480c2a7bb525945e5238d3307 [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"
reeddd9ffea2016-02-18 12:39:14 -08009#include "SkPM4f.h"
reedd2ed6222016-02-09 09:14:59 -080010#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.
18class XferU64Bench : public Benchmark {
19public:
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
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 {
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
64private:
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
88DEF_BENCH( return new XferU64Bench(true, F10 | USE_AA); )
89DEF_BENCH( return new XferU64Bench(true, F11 | USE_AA); )
90DEF_BENCH( return new XferU64Bench(true, F10); )
91DEF_BENCH( return new XferU64Bench(true, F11); )
92
93DEF_BENCH( return new XferU64Bench(true, F00 | USE_AA); )
94DEF_BENCH( return new XferU64Bench(true, F01 | USE_AA); )
95DEF_BENCH( return new XferU64Bench(true, F00); )
96DEF_BENCH( return new XferU64Bench(true, F01); )
97#endif
98
99DEF_BENCH( return new XferU64Bench(false, F10 | USE_AA); )
100DEF_BENCH( return new XferU64Bench(false, F11 | USE_AA); )
101DEF_BENCH( return new XferU64Bench(false, F10); )
102DEF_BENCH( return new XferU64Bench(false, F11); )
103
104DEF_BENCH( return new XferU64Bench(false, F00 | USE_AA); )
105DEF_BENCH( return new XferU64Bench(false, F01 | USE_AA); )
106DEF_BENCH( return new XferU64Bench(false, F00); )
107DEF_BENCH( return new XferU64Bench(false, F01); )