mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame^] | 1 | #include "Benchmark.h" |
| 2 | #include "SkPMFloat.h" |
| 3 | #include "SkRandom.h" |
| 4 | |
| 5 | struct PMFloatBench : public Benchmark { |
| 6 | explicit PMFloatBench(bool clamp) : fClamp(clamp) {} |
| 7 | |
| 8 | const char* onGetName() SK_OVERRIDE { return fClamp ? "SkPMFloat_clamp" : "SkPMFloat_get"; } |
| 9 | bool isSuitableFor(Backend backend) SK_OVERRIDE { return backend == kNonRendering_Backend; } |
| 10 | |
| 11 | void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 12 | SkRandom rand; |
| 13 | for (int i = 0; i < loops; i++) { |
| 14 | SkPMColor c = SkPreMultiplyColor(rand.nextU()); |
| 15 | SkPMFloat pmf; |
| 16 | pmf.set(c); |
| 17 | SkPMColor back = fClamp ? pmf.clamped() : pmf.get(); |
| 18 | if (c != back) { SkFAIL("no joy"); } // This conditional makes this not compile away. |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | bool fClamp; |
| 23 | }; |
| 24 | DEF_BENCH(return new PMFloatBench( true);) |
| 25 | DEF_BENCH(return new PMFloatBench(false);) |