Index: bench/NinePatchBench.cpp |
diff --git a/bench/NinePatchBench.cpp b/bench/NinePatchBench.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2d5db619044af4dd28f65b3f61969c07f1edd612 |
--- /dev/null |
+++ b/bench/NinePatchBench.cpp |
@@ -0,0 +1,59 @@ |
+/* |
+* 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 "SkCanvas.h" |
+#include "SkRect.h" |
+#include "SkString.h" |
+ |
+class NinePatchBench : public Benchmark { |
+public: |
+ NinePatchBench(int* xDivs, int xCount, int* yDivs, int yCount, const SkISize& srcSize, |
+ const SkRect& dst, const char* desc) |
+ : fSrcSize(srcSize) |
+ , fDst(dst) |
+ { |
+ fDivs.fXDivs = xDivs; |
+ fDivs.fXCount = xCount; |
+ fDivs.fYDivs = yDivs; |
+ fDivs.fYCount = yCount; |
+ |
+ fName = SkStringPrintf("NinePatch_%s", desc); |
+ } |
+ |
+ const char* onGetName() override { |
+ return fName.c_str(); |
+ } |
+ |
+ bool isSuitableFor(Backend backend) override { |
+ return kRaster_Backend == backend || kGPU_Backend == backend; |
+ } |
+ |
+ void onDelayedSetup() override { |
+ fBitmap.allocN32Pixels(fSrcSize.width(), fSrcSize.height()); |
+ fBitmap.eraseColor(0x880000FF); |
+ } |
+ |
+ void onDraw(int loops, SkCanvas* canvas) override { |
+ for (int i = 0; i < loops; i++) { |
+ canvas->drawBitmapNine(fBitmap, fDivs, fDst); |
+ } |
+ } |
+ |
+private: |
+ SkISize fSrcSize; |
+ SkCanvas::NinePatchDivs fDivs; |
+ SkRect fDst; |
+ SkString fName; |
+ SkBitmap fBitmap; |
+ |
+ typedef Benchmark INHERITED; |
+}; |
+ |
+static int gDivs[2] = { 250, 750, }; |
+DEF_BENCH(return new NinePatchBench(gDivs, 2, gDivs, 2, SkISize::Make(1000, 1000), |
+ SkRect::MakeWH(4000.0f, 4000.0f), "StandardNine");) |