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