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