blob: bd44effd0597d3d4f340bb05cc57cae60f324406 [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"
Mike Reedd4706732016-11-15 16:44:34 -050011#include "SkXfermodePriv.h"
reed3dc6aac2016-04-14 09:02:14 -070012
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:
Mike Reed6a015542016-11-09 10:38:09 -050020 XferF16Bench(SkBlendMode mode, const char name[], bool doN, uint32_t flags)
reed3dc6aac2016-04-14 09:02:14 -070021 : fDoN(doN)
22 , fFlags(flags & ~USE_AA)
23 {
Mike Reed6a015542016-11-09 10:38:09 -050024 fMode = mode;
25 fProc1 = SkXfermode::GetF16Proc(mode, fFlags | SkXfermode::kSrcIsSingle_F16Flag);
26 fProcN = SkXfermode::GetF16Proc(mode, fFlags);
reed3dc6aac2016-04-14 09:02:14 -070027 fName.printf("xferF16_%s_%s_%c_%s",
28 name,
29 (flags & USE_AA) ? "aa" : "bw",
30 fDoN ? 'N' : '1',
31 (flags & SkXfermode::kSrcIsOpaque_F16Flag) ? "opaque" : "alpha");
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 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
53 if (fDoN) {
Mike Reed6a015542016-11-09 10:38:09 -050054 fProcN(fMode, fDst, fSrc, N, fAA);
reed3dc6aac2016-04-14 09:02:14 -070055 } else {
Mike Reed6a015542016-11-09 10:38:09 -050056 fProc1(fMode, fDst, fSrc, N, fAA);
reed3dc6aac2016-04-14 09:02:14 -070057 }
58 }
59 }
60
61private:
Mike Reed6a015542016-11-09 10:38:09 -050062 SkBlendMode fMode;
reed3dc6aac2016-04-14 09:02:14 -070063 SkString fName;
64 SkXfermode::F16Proc fProc1;
65 SkXfermode::F16Proc fProcN;
66 const SkAlpha* fAA;
67 bool fDoN;
68 uint32_t fFlags;
69
70 enum {
71 N = 1000,
72 };
73 SkPM4f fSrc[N];
74 uint64_t fDst[N];
75 uint8_t fAAStorage[N];
76
77 typedef Benchmark INHERITED;
78};
79
80#define F00 0
81#define F01 (SkXfermode::kSrcIsOpaque_F16Flag)
82
Mike Reed6a015542016-11-09 10:38:09 -050083#define MODE SkBlendMode::kSrcOver
reed3dc6aac2016-04-14 09:02:14 -070084#define NAME "srcover"
85
86DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F00 | USE_AA); )
87DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F01 | USE_AA); )
88DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F00); )
89DEF_BENCH( return new XferF16Bench(MODE, NAME, true, F01); )
90
91DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F00 | USE_AA); )
92DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F01 | USE_AA); )
93DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F00); )
94DEF_BENCH( return new XferF16Bench(MODE, NAME, false, F01); )