OLD | NEW |
1 #include "SkBenchmark.h" | 1 #include "SkBenchmark.h" |
2 #include "SkColorPriv.h" | 2 #include "SkColorPriv.h" |
3 #include "SkRandom.h" | 3 #include "SkRandom.h" |
4 #include "SkString.h" | 4 #include "SkString.h" |
5 | 5 |
6 template <bool kFast, bool kScale> | 6 template <bool kFast, bool kScale> |
7 class FourByteInterpBench : public SkBenchmark { | 7 class FourByteInterpBench : public SkBenchmark { |
8 public: | 8 public: |
9 FourByteInterpBench() { | 9 FourByteInterpBench() { |
10 fName.set("four_byte_interp"); | 10 fName.set("four_byte_interp"); |
11 fName.append(kFast ? "_fast" : "_slow"); | 11 fName.append(kFast ? "_fast" : "_slow"); |
12 fName.append(kScale ? "_255" : "_256"); | 12 fName.append(kScale ? "_255" : "_256"); |
13 | 13 |
14 // We'll exhaustively test all scales instead of using random numbers. | 14 // We'll exhaustively test all scales instead of using random numbers. |
15 for (int i = 0; i <= 256; i++) { | 15 for (int i = 0; i <= 256; i++) { |
16 fScales[i] = i; | 16 fScales[i] = i; |
17 } | 17 } |
18 if (kScale) fScales[256] = 255; // We'll just do 255 twice if we're lim
ited to [0,255]. | 18 if (kScale) fScales[256] = 255; // We'll just do 255 twice if we're lim
ited to [0,255]. |
19 } | 19 } |
20 | 20 |
21 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 21 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
22 return backend == kNonRendering_Backend; | 22 return backend == kNonRendering_Backend; |
23 } | 23 } |
24 | 24 |
25 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } | 25 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } |
26 | 26 |
27 virtual void onDraw(SkCanvas*) SK_OVERRIDE { | 27 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { |
28 const SkPMColor src = 0xAB998877, dst = 0x66334455; | 28 const SkPMColor src = 0xAB998877, dst = 0x66334455; |
29 volatile SkPMColor junk = 0; | 29 volatile SkPMColor junk = 0; |
30 for (int i = 0; i < 10*this->getLoops(); ++i) { | 30 for (int i = 0; i < 10*loops; ++i) { |
31 for (size_t j = 0; j <= 256; j++) { | 31 for (size_t j = 0; j <= 256; j++) { |
32 const unsigned scale = fScales[j]; | 32 const unsigned scale = fScales[j]; |
33 if (kFast && kScale) { | 33 if (kFast && kScale) { |
34 junk ^= SkFastFourByteInterp(src, dst, scale); | 34 junk ^= SkFastFourByteInterp(src, dst, scale); |
35 } else if (kFast) { | 35 } else if (kFast) { |
36 junk ^= SkFastFourByteInterp256(src, dst, scale); | 36 junk ^= SkFastFourByteInterp256(src, dst, scale); |
37 } else if (kScale) { | 37 } else if (kScale) { |
38 junk ^= SkFourByteInterp(src, dst, scale); | 38 junk ^= SkFourByteInterp(src, dst, scale); |
39 } else { | 39 } else { |
40 junk ^= SkFourByteInterp256(src, dst, scale); | 40 junk ^= SkFourByteInterp256(src, dst, scale); |
41 } | 41 } |
42 } | 42 } |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 private: | 46 private: |
47 SkString fName; | 47 SkString fName; |
48 unsigned fScales[257]; // We need space for [0, 256]. | 48 unsigned fScales[257]; // We need space for [0, 256]. |
49 }; | 49 }; |
50 | 50 |
51 #define COMMA , | 51 #define COMMA , |
52 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA true>); ) | 52 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA true>); ) |
53 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA false>); ) | 53 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA false>); ) |
54 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA true>); ) | 54 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA true>); ) |
55 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA false>); ) | 55 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA false>); ) |
56 #undef COMMA | 56 #undef COMMA |
OLD | NEW |