Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: bench/Xfer4fBench.cpp

Issue 1721223002: simplify/unify xferproc api (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | bench/XferU64Bench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkPM4f.h" 9 #include "SkPM4f.h"
10 #include "SkString.h" 10 #include "SkString.h"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 12
13 #define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict 13 #define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict
14 14
15 #define INNER_LOOPS 1000 15 #define INNER_LOOPS 1000
16 16
17 // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode. 17 // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
18 class Xfer4fBench : public Benchmark { 18 class XferD32Bench : public Benchmark {
19 public: 19 public:
20 Xfer4fBench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t fla gs) 20 XferD32Bench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t fl ags)
21 : fDoN(doN) 21 : fDoN(doN)
22 , fFlags(flags & ~USE_AA) 22 , fFlags(flags & ~USE_AA)
23 { 23 {
24 fProc1 = SkXfermode::GetPM4fProc1(mode, fFlags); 24 fXfer.reset(SkXfermode::Create(mode));
25 fProcN = SkXfermode::GetPM4fProcN(mode, fFlags); 25
26 fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle _D32Flag);
27 fProcN = SkXfermode::GetD32Proc(fXfer, fFlags);
26 fName.printf("xfer4f_%s_%s_%c_%s_%s", 28 fName.printf("xfer4f_%s_%s_%c_%s_%s",
27 name, 29 name,
28 (flags & USE_AA) ? "aa" : "bw", 30 (flags & USE_AA) ? "aa" : "bw",
29 fDoN ? 'N' : '1', 31 fDoN ? 'N' : '1',
30 (flags & SkXfermode::kSrcIsOpaque_PM4fFlag) ? "opaque" : "a lpha", 32 (flags & SkXfermode::kSrcIsOpaque_D32Flag) ? "opaque" : "al pha",
31 (flags & SkXfermode::kDstIsSRGB_PM4fFlag) ? "srgb" : "linea r"); 33 (flags & SkXfermode::kDstIsSRGB_D32Flag) ? "srgb" : "linear ");
32 34
33 for (int i = 0; i < N; ++i) { 35 for (int i = 0; i < N; ++i) {
34 fSrc[i] = {{ 1, 1, 1, 1 }}; 36 fSrc[i] = {{ 1, 1, 1, 1 }};
35 fDst[i] = 0; 37 fDst[i] = 0;
36 fAAStorage[i] = i * 255 / (N - 1); 38 fAAStorage[i] = i * 255 / (N - 1);
37 } 39 }
38 40
39 if (flags & USE_AA) { 41 if (flags & USE_AA) {
40 fAA = fAAStorage; 42 fAA = fAAStorage;
41 } else { 43 } else {
42 fAA = nullptr; 44 fAA = nullptr;
43 } 45 }
44 } 46 }
45 47
46 protected: 48 protected:
47 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 49 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
48 50
49 const char* onGetName() override { return fName.c_str(); } 51 const char* onGetName() override { return fName.c_str(); }
50 52
51 void onDraw(int loops, SkCanvas*) override { 53 void onDraw(int loops, SkCanvas*) override {
52 const SkXfermode::PM4fState state{ nullptr, fFlags };
53
54 for (int i = 0; i < loops * INNER_LOOPS; ++i) { 54 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
55 if (fDoN) { 55 if (fDoN) {
56 fProcN(state, fDst, fSrc, N, fAA); 56 fProcN(fXfer, fDst, fSrc, N, fAA);
57 } else { 57 } else {
58 fProc1(state, fDst, fSrc[0], N, fAA); 58 fProc1(fXfer, fDst, fSrc, N, fAA);
59 } 59 }
60 } 60 }
61 } 61 }
62 62
63 private: 63 private:
64 SkString fName; 64 SkAutoTUnref<SkXfermode> fXfer;
65 SkXfermode::PM4fProc1 fProc1; 65 SkString fName;
66 SkXfermode::PM4fProcN fProcN; 66 SkXfermode::D32Proc fProc1;
67 const SkAlpha* fAA; 67 SkXfermode::D32Proc fProcN;
68 bool fDoN; 68 const SkAlpha* fAA;
69 uint32_t fFlags; 69 bool fDoN;
70 uint32_t fFlags;
70 71
71 enum { 72 enum {
72 N = 1000, 73 N = 1000,
73 }; 74 };
74 SkPM4f fSrc[N]; 75 SkPM4f fSrc[N];
75 SkPMColor fDst[N]; 76 SkPMColor fDst[N];
76 uint8_t fAAStorage[N]; 77 uint8_t fAAStorage[N];
77 78
78 typedef Benchmark INHERITED; 79 typedef Benchmark INHERITED;
79 }; 80 };
80 81
81 #define F00 0 82 #define F00 0
82 #define F01 (SkXfermode::kSrcIsOpaque_PM4fFlag) 83 #define F01 (SkXfermode::kSrcIsOpaque_D32Flag)
83 #define F10 (SkXfermode::kDstIsSRGB_PM4fFlag) 84 #define F10 (SkXfermode::kDstIsSRGB_D32Flag)
84 #define F11 (SkXfermode::kSrcIsOpaque_PM4fFlag | SkXfermode::kDstIsSRGB_PM4fFlag ) 85 #define F11 (SkXfermode::kSrcIsOpaque_D32Flag | SkXfermode::kDstIsSRGB_D32Flag)
85 86
86 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 10); ) 87 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F10); )
87 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 00); ) 88 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F00); )
88 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 11); ) 89 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F11); )
89 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 01); ) 90 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F01); )
90 91
91 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 10); ) 92 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F10); )
92 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 00); ) 93 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F00); )
93 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 11); ) 94 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F11); )
94 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 01); ) 95 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F01); )
95 96
96 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 10 | USE_AA); ) 97 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F10 | USE_AA); )
97 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 00 | USE_AA); ) 98 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F00 | USE_AA); )
98 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 11 | USE_AA); ) 99 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F11 | USE_AA); )
99 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, F 01 | USE_AA); ) 100 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false, F01 | USE_AA); )
100 101
101 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 10 | USE_AA); ) 102 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F10 | USE_AA); )
102 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 00 | USE_AA); ) 103 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F00 | USE_AA); )
103 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 11 | USE_AA); ) 104 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F11 | USE_AA); )
104 DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, F 01 | USE_AA); ) 105 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true, F01 | USE_AA); )
OLDNEW
« no previous file with comments | « no previous file | bench/XferU64Bench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698