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