blob: 8250c9e17c5385a8b9d27542b35e8c9f01edc181 [file] [log] [blame]
mtkleina2f4be72015-02-23 10:04:34 -08001#include "Benchmark.h"
2#include "SkPMFloat.h"
3#include "SkRandom.h"
4
5struct 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};
24DEF_BENCH(return new PMFloatBench( true);)
25DEF_BENCH(return new PMFloatBench(false);)