aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/DrawLatticeBench.cpp
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-08-02 08:05:56 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-02 08:05:56 -0700
commitc573a40ed5024b463e47088d307e3164a486dba5 (patch)
tree17969315cf64ce827395c4b8ad9273cc6f96886d /bench/DrawLatticeBench.cpp
parent7d0e3bc785fc5aaf2ed0aa8f37a2bc85c2f82da0 (diff)
Add drawImageLattice() and drawBitmapLattice() APIs
The specified image/bitmap is divided into rects, which can be draw stretched, shrunk, or at a fixed size. Will be used by Android to draw 9patch (which are acutally N-patch) images. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1992283002 Review-Url: https://codereview.chromium.org/1992283002
Diffstat (limited to 'bench/DrawLatticeBench.cpp')
-rw-r--r--bench/DrawLatticeBench.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/bench/DrawLatticeBench.cpp b/bench/DrawLatticeBench.cpp
new file mode 100644
index 0000000000..4c03ca1dfa
--- /dev/null
+++ b/bench/DrawLatticeBench.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 DrawLatticeBench : public Benchmark {
+public:
+ DrawLatticeBench(int* xDivs, int xCount, int* yDivs, int yCount, const SkISize& srcSize,
+ const SkRect& dst, const char* desc)
+ : fSrcSize(srcSize)
+ , fDst(dst)
+ {
+ fLattice.fXDivs = xDivs;
+ fLattice.fXCount = xCount;
+ fLattice.fYDivs = yDivs;
+ fLattice.fYCount = yCount;
+
+ fName = SkStringPrintf("DrawLattice_%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->drawBitmapLattice(fBitmap, fLattice, fDst);
+ }
+ }
+
+private:
+ SkISize fSrcSize;
+ SkCanvas::Lattice fLattice;
+ SkRect fDst;
+ SkString fName;
+ SkBitmap fBitmap;
+
+ typedef Benchmark INHERITED;
+};
+
+static int gDivs[2] = { 250, 750, };
+DEF_BENCH(return new DrawLatticeBench(gDivs, 2, gDivs, 2, SkISize::Make(1000, 1000),
+ SkRect::MakeWH(4000.0f, 4000.0f), "StandardNine");)