Index: bench/Xfer4fBench.cpp |
diff --git a/bench/Xfer4fBench.cpp b/bench/Xfer4fBench.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2c281695ef02a8090834e476944135f47f8646db |
--- /dev/null |
+++ b/bench/Xfer4fBench.cpp |
@@ -0,0 +1,73 @@ |
+ |
+/* |
+ * Copyright 2016 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "Benchmark.h" |
+#include "SkString.h" |
+#include "SkXfer4f.h" |
+ |
+#define INNER_LOOPS 100 |
+ |
+// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode. |
+class Xfer4fBench : public Benchmark { |
+public: |
+ Xfer4fBench(SkXfermode::Mode mode, const char name[], bool doN, uint32_t flags) : fDoN(doN) { |
+ fProc1 = SkPM4fXfer1ProcFactory(mode, flags); |
+ fProcN = SkPM4fXferNProcFactory(mode, flags); |
+ fName.printf("xfer4f_%s_%c_%s_%s", name, fDoN ? 'N' : '1', |
+ (flags & kSrcIsOpaque_SkXfer4fFlag) ? "opaque" : "alpha", |
+ (flags & kDstIsSRGB_SkXfer4fFlag) ? "srgb" : "linear"); |
+ |
+ SkPM4f c; |
+ c.fVec[0] = 1; c.fVec[1] = 1; c.fVec[2] = 1; c.fVec[3] = 1; |
mtklein
2016/01/29 15:23:00
This can also be
SkPM4f c = {{ 1,1,1,1 }};
reed1
2016/01/29 22:35:27
Done.
|
+ for (int i = 0; i < N; ++i) { |
+ fSrc[i] = c; |
+ fDst[i] = 0; |
+ } |
+ } |
+ |
+protected: |
+ bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
+ |
+ const char* onGetName() override { return fName.c_str(); } |
+ |
+ void onDraw(int loops, SkCanvas*) override { |
+ for (int i = 0; i < loops; ++i) { |
mtklein
2016/01/29 15:23:00
Generally, you can also write
for (int i = 0; i
reed1
2016/01/29 22:35:27
Ah, so you never pass 0 for loops?
mtklein
2016/01/30 01:18:19
Um, it's true that nanobench happens to never pass
|
+ for (int j = 0; j < INNER_LOOPS; ++j) { |
+ if (fDoN) { |
+ fProcN(fDst, fSrc, N); |
+ } else { |
+ fProc1(fDst, fSrc[0], N); |
+ } |
+ } |
+ } |
+ } |
+ |
+private: |
+ SkString fName; |
+ SkPM4fXfer1Proc fProc1; |
+ SkPM4fXferNProc fProcN; |
+ bool fDoN; |
+ |
+ enum { |
+ N = 1000, |
+ }; |
+ SkPM4f fSrc[N]; |
+ SkPMColor fDst[N]; |
+ |
+ typedef Benchmark INHERITED; |
+}; |
+ |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, kDstIsSRGB_SkXfer4fFlag); ) |
mtklein
2016/01/29 15:23:00
Wanna throw in equal-pixel-count 8888 benchmarks h
|
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, 0); ) |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, kDstIsSRGB_SkXfer4fFlag | kSrcIsOpaque_SkXfer4fFlag); ) |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", false, kSrcIsOpaque_SkXfer4fFlag); ) |
+ |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, kDstIsSRGB_SkXfer4fFlag); ) |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, 0); ) |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, kDstIsSRGB_SkXfer4fFlag | kSrcIsOpaque_SkXfer4fFlag); ) |
+DEF_BENCH( return new Xfer4fBench(SkXfermode::kSrcOver_Mode, "srcover", true, kSrcIsOpaque_SkXfer4fFlag); ) |