blob: 6a7d27a92672549925afa4480223cbbcf834aae1 [file] [log] [blame]
reed3dc6aac2016-04-14 09:02:14 -07001/*
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 "SkPM4f.h"
10#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 XferF16Bench : public Benchmark {
19public:
20 XferF16Bench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t flags)
21 : fDoN(doN)
22 , fFlags(flags & ~USE_AA)
23 {
24 fXfer = SkXfermode::Make(mode);
25
26 fProc1 = SkXfermode::GetF16Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle_F16Flag);
27 fProcN = SkXfermode::GetF16Proc(fXfer, fFlags);
28 fName.printf("xferF16_%s_%s_%c_%s",
29 name,
30 (flags & USE_AA) ? "aa" : "bw",
31 fDoN ? 'N' : '1',
32 (flags & SkXfermode::kSrcIsOpaque_F16Flag) ? "opaque" : "alpha");
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 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
54 if (fDoN) {
55 fProcN(fXfer.get(), fDst, fSrc, N, fAA);
56 } else {
57 fProc1(fXfer.get(), fDst, fSrc, N, fAA);
58 }
59 }
60 }
61
62private:
63 sk_sp<SkXfermode> fXfer;
64 SkString fName;
65 SkXfermode::F16Proc fProc1;
66 SkXfermode::F16Proc 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_F16Flag)
83
84#define MODE SkXfermode::kSrcOver_Mode
85#define NAME "srcover"
86
87DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F00 | USE_AA); )
88DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F01 | USE_AA); )
89DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F00); )
90DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F01); )
91
92DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F00 | USE_AA); )
93DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F01 | USE_AA); )
94DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F00); )
95DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F01); )