OLD | NEW |
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 XferD32Bench : public Benchmark { | 18 class XferD32Bench : public Benchmark { |
19 public: | 19 public: |
20 XferD32Bench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t fl
ags) | 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 fXfer.reset(SkXfermode::Create(mode)); | 24 fXfer = SkXfermode::Make(mode); |
25 | |
26 fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle
_D32Flag); | 25 fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle
_D32Flag); |
27 fProcN = SkXfermode::GetD32Proc(fXfer, fFlags); | 26 fProcN = SkXfermode::GetD32Proc(fXfer, fFlags); |
28 fName.printf("xfer4f_%s_%s_%c_%s_%s", | 27 fName.printf("xfer4f_%s_%s_%c_%s_%s", |
29 name, | 28 name, |
30 (flags & USE_AA) ? "aa" : "bw", | 29 (flags & USE_AA) ? "aa" : "bw", |
31 fDoN ? 'N' : '1', | 30 fDoN ? 'N' : '1', |
32 (flags & SkXfermode::kSrcIsOpaque_D32Flag) ? "opaque" : "al
pha", | 31 (flags & SkXfermode::kSrcIsOpaque_D32Flag) ? "opaque" : "al
pha", |
33 (flags & SkXfermode::kDstIsSRGB_D32Flag) ? "srgb" : "linear
"); | 32 (flags & SkXfermode::kDstIsSRGB_D32Flag) ? "srgb" : "linear
"); |
34 | 33 |
35 for (int i = 0; i < N; ++i) { | 34 for (int i = 0; i < N; ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
46 } | 45 } |
47 | 46 |
48 protected: | 47 protected: |
49 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } | 48 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
50 | 49 |
51 const char* onGetName() override { return fName.c_str(); } | 50 const char* onGetName() override { return fName.c_str(); } |
52 | 51 |
53 void onDraw(int loops, SkCanvas*) override { | 52 void onDraw(int loops, SkCanvas*) override { |
54 for (int i = 0; i < loops * INNER_LOOPS; ++i) { | 53 for (int i = 0; i < loops * INNER_LOOPS; ++i) { |
55 if (fDoN) { | 54 if (fDoN) { |
56 fProcN(fXfer, fDst, fSrc, N, fAA); | 55 fProcN(fXfer.get(), fDst, fSrc, N, fAA); |
57 } else { | 56 } else { |
58 fProc1(fXfer, fDst, fSrc, N, fAA); | 57 fProc1(fXfer.get(), fDst, fSrc, N, fAA); |
59 } | 58 } |
60 } | 59 } |
61 } | 60 } |
62 | 61 |
63 private: | 62 private: |
64 SkAutoTUnref<SkXfermode> fXfer; | 63 sk_sp<SkXfermode> fXfer; |
65 SkString fName; | 64 SkString fName; |
66 SkXfermode::D32Proc fProc1; | 65 SkXfermode::D32Proc fProc1; |
67 SkXfermode::D32Proc fProcN; | 66 SkXfermode::D32Proc fProcN; |
68 const SkAlpha* fAA; | 67 const SkAlpha* fAA; |
69 bool fDoN; | 68 bool fDoN; |
70 uint32_t fFlags; | 69 uint32_t fFlags; |
71 | 70 |
72 enum { | 71 enum { |
73 N = 1000, | 72 N = 1000, |
74 }; | 73 }; |
(...skipping 21 matching lines...) Expand all Loading... |
96 | 95 |
97 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F10 | USE_AA); ) | 96 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F10 | USE_AA); ) |
98 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F00 | USE_AA); ) | 97 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F00 | USE_AA); ) |
99 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F11 | USE_AA); ) | 98 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F11 | USE_AA); ) |
100 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F01 | USE_AA); ) | 99 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", false,
F01 | USE_AA); ) |
101 | 100 |
102 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F10 | USE_AA); ) | 101 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F10 | USE_AA); ) |
103 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F00 | USE_AA); ) | 102 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F00 | USE_AA); ) |
104 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F11 | USE_AA); ) | 103 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F11 | USE_AA); ) |
105 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F01 | USE_AA); ) | 104 DEF_BENCH( return new XferD32Bench(SkXfermode::kSrcOver_Mode, "srcover", true,
F01 | USE_AA); ) |
OLD | NEW |