blob: 7a8cdf3b3a9c16095b6b6c20e4b1c68a5b763d2b [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;
msarett0764efe2016-09-02 11:24:30 -070025 fLattice.fFlags = nullptr;
msarettf6566312016-09-30 13:09:01 -070026 fLattice.fBounds = nullptr;
msarettc573a402016-08-02 08:05:56 -070027
28 fName = SkStringPrintf("DrawLattice_%s", desc);
29 }
30
31 const char* onGetName() override {
32 return fName.c_str();
33 }
34
msarett10e3d9b2016-08-18 15:46:03 -070035 SkIPoint onGetSize() override {
36 return SkIPoint::Make(1000, 1000);
37 }
38
msarettc573a402016-08-02 08:05:56 -070039 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
54private:
55 SkISize fSrcSize;
56 SkCanvas::Lattice fLattice;
57 SkRect fDst;
58 SkString fName;
59 SkBitmap fBitmap;
60
61 typedef Benchmark INHERITED;
62};
63
msarett10e3d9b2016-08-18 15:46:03 -070064static int gDivs9[2] = { 25, 75, };
65DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
66 SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects9");)
67DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
68 SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects9");)
69DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
70 SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects9");)
71static int gDivs15[4] = { 15, 45, 55, 85, };
72DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
73 SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects15");)
74DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
75 SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects15");)
76DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
77 SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects15");)