blob: fbab2f7adb10b16d5cf510f9e16cf5d82941091c [file] [log] [blame]
msarettc573a402016-08-02 08:05:56 -07001/*
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 Malitaab244f02017-05-03 19:16:58 +00009#include "SkBitmap.h"
msarettc573a402016-08-02 08:05:56 -070010#include "SkCanvas.h"
11#include "SkRect.h"
12#include "SkString.h"
13
14class DrawLatticeBench : public Benchmark {
15public:
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 Ilievca8c0952017-12-11 13:01:58 -050025 fLattice.fRectTypes = nullptr;
msarettf6566312016-09-30 13:09:01 -070026 fLattice.fBounds = nullptr;
Stan Ilievca8c0952017-12-11 13:01:58 -050027 fLattice.fColors = nullptr;
msarettc573a402016-08-02 08:05:56 -070028
29 fName = SkStringPrintf("DrawLattice_%s", desc);
30 }
31
32 const char* onGetName() override {
33 return fName.c_str();
34 }
35
msarett10e3d9b2016-08-18 15:46:03 -070036 SkIPoint onGetSize() override {
37 return SkIPoint::Make(1000, 1000);
38 }
39
msarettc573a402016-08-02 08:05:56 -070040 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
55private:
56 SkISize fSrcSize;
57 SkCanvas::Lattice fLattice;
58 SkRect fDst;
59 SkString fName;
60 SkBitmap fBitmap;
61
62 typedef Benchmark INHERITED;
63};
64
msarett10e3d9b2016-08-18 15:46:03 -070065static int gDivs9[2] = { 25, 75, };
66DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
67 SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects9");)
68DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
69 SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects9");)
70DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
71 SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects9");)
72static int gDivs15[4] = { 15, 45, 55, 85, };
73DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
74 SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects15");)
75DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
76 SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects15");)
77DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
78 SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects15");)