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

Side by Side Diff: bench/XferU64Bench.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 | « bench/Xfer4fBench.cpp ('k') | gm/SkLinearBitmapPipelineGM.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 XferU64Bench : public Benchmark { 18 class XferD64Bench : public Benchmark {
19 public: 19 public:
20 XferU64Bench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t fl ags) 20 XferD64Bench(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 fXfer.reset(SkXfermode::Create(mode)); 24 fXfer.reset(SkXfermode::Create(mode));
25 25
26 fProc1 = SkXfermode::GetU64Proc1(mode, fFlags); 26 fProc1 = SkXfermode::GetD64Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle _D64Flag);
27 fProcN = SkXfermode::GetU64ProcN(mode, fFlags); 27 fProcN = SkXfermode::GetD64Proc(fXfer, fFlags);
28 fName.printf("xferu64_%s_%s_%c_%s_%s", 28 fName.printf("xferu64_%s_%s_%c_%s_%s",
29 name, 29 name,
30 (flags & USE_AA) ? "aa" : "bw", 30 (flags & USE_AA) ? "aa" : "bw",
31 fDoN ? 'N' : '1', 31 fDoN ? 'N' : '1',
32 (flags & SkXfermode::kSrcIsOpaque_U64Flag) ? "opaque" : "al pha", 32 (flags & SkXfermode::kSrcIsOpaque_D64Flag) ? "opaque" : "al pha",
33 (flags & SkXfermode::kDstIsFloat16_U64Flag) ? "f16" : "u16" ); 33 (flags & SkXfermode::kDstIsFloat16_D64Flag) ? "f16" : "u16" );
34 34
35 for (int i = 0; i < N; ++i) { 35 for (int i = 0; i < N; ++i) {
36 fSrc[i] = {{ 1, 1, 1, 1 }}; 36 fSrc[i] = {{ 1, 1, 1, 1 }};
37 fDst[i] = 0; 37 fDst[i] = 0;
38 fAAStorage[i] = i * 255 / (N - 1); 38 fAAStorage[i] = i * 255 / (N - 1);
39 } 39 }
40 40
41 if (flags & USE_AA) { 41 if (flags & USE_AA) {
42 fAA = fAAStorage; 42 fAA = fAAStorage;
43 } else { 43 } else {
44 fAA = nullptr; 44 fAA = nullptr;
45 } 45 }
46 } 46 }
47 47
48 protected: 48 protected:
49 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 49 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
50 50
51 const char* onGetName() override { return fName.c_str(); } 51 const char* onGetName() override { return fName.c_str(); }
52 52
53 void onDraw(int loops, SkCanvas*) override { 53 void onDraw(int loops, SkCanvas*) override {
54 const SkXfermode::U64State state{ fXfer, fFlags };
55
56 for (int i = 0; i < loops * INNER_LOOPS; ++i) { 54 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
57 if (fDoN) { 55 if (fDoN) {
58 fProcN(state, fDst, fSrc, N, fAA); 56 fProcN(fXfer, fDst, fSrc, N, fAA);
59 } else { 57 } else {
60 fProc1(state, fDst, fSrc[0], N, fAA); 58 fProc1(fXfer, fDst, fSrc, N, fAA);
61 } 59 }
62 } 60 }
63 } 61 }
64 62
65 private: 63 private:
66 SkAutoTUnref<SkXfermode> fXfer; 64 SkAutoTUnref<SkXfermode> fXfer;
67 SkString fName; 65 SkString fName;
68 SkXfermode::U64Proc1 fProc1; 66 SkXfermode::D64Proc fProc1;
69 SkXfermode::U64ProcN fProcN; 67 SkXfermode::D64Proc fProcN;
70 const SkAlpha* fAA; 68 const SkAlpha* fAA;
71 bool fDoN; 69 bool fDoN;
72 uint32_t fFlags; 70 uint32_t fFlags;
73 71
74 enum { 72 enum {
75 N = 1000, 73 N = 1000,
76 }; 74 };
77 SkPM4f fSrc[N]; 75 SkPM4f fSrc[N];
78 uint64_t fDst[N]; 76 uint64_t fDst[N];
79 uint8_t fAAStorage[N]; 77 uint8_t fAAStorage[N];
80 78
81 typedef Benchmark INHERITED; 79 typedef Benchmark INHERITED;
82 }; 80 };
83 81
84 #define F00 0 82 #define F00 0
85 #define F01 (SkXfermode::kSrcIsOpaque_U64Flag) 83 #define F01 (SkXfermode::kSrcIsOpaque_D64Flag)
86 #define F10 (SkXfermode::kDstIsFloat16_U64Flag) 84 #define F10 (SkXfermode::kDstIsFloat16_D64Flag)
87 #define F11 (SkXfermode::kDstIsFloat16_U64Flag | SkXfermode::kSrcIsOpaque_U64Fla g) 85 #define F11 (SkXfermode::kDstIsFloat16_D64Flag | SkXfermode::kSrcIsOpaque_D64Fla g)
88 86
89 #define MODE SkXfermode::kSrcOver_Mode 87 #define MODE SkXfermode::kSrcOver_Mode
90 #define NAME "srcover" 88 #define NAME "srcover"
91 89
92 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F10 | USE_AA); ) 90 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F10 | USE_AA); )
93 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F11 | USE_AA); ) 91 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F11 | USE_AA); )
94 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F10); ) 92 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F10); )
95 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F11); ) 93 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F11); )
96 94
97 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F00 | USE_AA); ) 95 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F00 | USE_AA); )
98 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F01 | USE_AA); ) 96 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F01 | USE_AA); )
99 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F00); ) 97 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F00); )
100 DEF_BENCH( return new XferU64Bench(MODE, NAME, true, F01); ) 98 DEF_BENCH( return new XferD64Bench(MODE, NAME, true, F01); )
101 99
102 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F10 | USE_AA); ) 100 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F10 | USE_AA); )
103 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F11 | USE_AA); ) 101 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F11 | USE_AA); )
104 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F10); ) 102 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F10); )
105 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F11); ) 103 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F11); )
106 104
107 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F00 | USE_AA); ) 105 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F00 | USE_AA); )
108 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F01 | USE_AA); ) 106 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F01 | USE_AA); )
109 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F00); ) 107 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F00); )
110 DEF_BENCH( return new XferU64Bench(MODE, NAME, false, F01); ) 108 DEF_BENCH( return new XferD64Bench(MODE, NAME, false, F01); )
OLDNEW
« no previous file with comments | « bench/Xfer4fBench.cpp ('k') | gm/SkLinearBitmapPipelineGM.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698