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; |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 24 | fLattice.fFlags = nullptr; |
msarett | f656631 | 2016-09-30 13:09:01 -0700 | [diff] [blame] | 25 | fLattice.fBounds = nullptr; |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 26 | |
| 27 | fName = SkStringPrintf("DrawLattice_%s", desc); |
| 28 | } |
| 29 | |
| 30 | const char* onGetName() override { |
| 31 | return fName.c_str(); |
| 32 | } |
| 33 | |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 34 | SkIPoint onGetSize() override { |
| 35 | return SkIPoint::Make(1000, 1000); |
| 36 | } |
| 37 | |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 38 | bool isSuitableFor(Backend backend) override { |
| 39 | return kRaster_Backend == backend || kGPU_Backend == backend; |
| 40 | } |
| 41 | |
| 42 | void onDelayedSetup() override { |
| 43 | fBitmap.allocN32Pixels(fSrcSize.width(), fSrcSize.height()); |
| 44 | fBitmap.eraseColor(0x880000FF); |
| 45 | } |
| 46 | |
| 47 | void onDraw(int loops, SkCanvas* canvas) override { |
| 48 | for (int i = 0; i < loops; i++) { |
| 49 | canvas->drawBitmapLattice(fBitmap, fLattice, fDst); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | SkISize fSrcSize; |
| 55 | SkCanvas::Lattice fLattice; |
| 56 | SkRect fDst; |
| 57 | SkString fName; |
| 58 | SkBitmap fBitmap; |
| 59 | |
| 60 | typedef Benchmark INHERITED; |
| 61 | }; |
| 62 | |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 63 | static int gDivs9[2] = { 25, 75, }; |
| 64 | DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100), |
| 65 | SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects9");) |
| 66 | DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100), |
| 67 | SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects9");) |
| 68 | DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100), |
| 69 | SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects9");) |
| 70 | static int gDivs15[4] = { 15, 45, 55, 85, }; |
| 71 | DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100), |
| 72 | SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects15");) |
| 73 | DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100), |
| 74 | SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects15");) |
| 75 | DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100), |
| 76 | SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects15");) |