msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Benchmark.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkRect.h" |
| 11 | #include "SkString.h" |
| 12 | |
| 13 | class DrawLatticeBench : public Benchmark { |
| 14 | public: |
| 15 | DrawLatticeBench(int* xDivs, int xCount, int* yDivs, int yCount, const SkISize& srcSize, |
| 16 | const SkRect& dst, const char* desc) |
| 17 | : fSrcSize(srcSize) |
| 18 | , fDst(dst) |
| 19 | { |
| 20 | fLattice.fXDivs = xDivs; |
| 21 | fLattice.fXCount = xCount; |
| 22 | fLattice.fYDivs = yDivs; |
| 23 | fLattice.fYCount = yCount; |
| 24 | |
| 25 | fName = SkStringPrintf("DrawLattice_%s", desc); |
| 26 | } |
| 27 | |
| 28 | const char* onGetName() override { |
| 29 | return fName.c_str(); |
| 30 | } |
| 31 | |
| 32 | bool isSuitableFor(Backend backend) override { |
| 33 | return kRaster_Backend == backend || kGPU_Backend == backend; |
| 34 | } |
| 35 | |
| 36 | void onDelayedSetup() override { |
| 37 | fBitmap.allocN32Pixels(fSrcSize.width(), fSrcSize.height()); |
| 38 | fBitmap.eraseColor(0x880000FF); |
| 39 | } |
| 40 | |
| 41 | void onDraw(int loops, SkCanvas* canvas) override { |
| 42 | for (int i = 0; i < loops; i++) { |
| 43 | canvas->drawBitmapLattice(fBitmap, fLattice, fDst); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | SkISize fSrcSize; |
| 49 | SkCanvas::Lattice fLattice; |
| 50 | SkRect fDst; |
| 51 | SkString fName; |
| 52 | SkBitmap fBitmap; |
| 53 | |
| 54 | typedef Benchmark INHERITED; |
| 55 | }; |
| 56 | |
| 57 | static int gDivs[2] = { 250, 750, }; |
| 58 | DEF_BENCH(return new DrawLatticeBench(gDivs, 2, gDivs, 2, SkISize::Make(1000, 1000), |
| 59 | SkRect::MakeWH(4000.0f, 4000.0f), "StandardNine");) |