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