• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkRect.h"
12 #include "SkString.h"
13 
14 class DrawLatticeBench : public Benchmark {
15 public:
DrawLatticeBench(int * xDivs,int xCount,int * yDivs,int yCount,const SkISize & srcSize,const SkRect & dst,const char * desc)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;
25         fLattice.fRectTypes = nullptr;
26         fLattice.fBounds = nullptr;
27         fLattice.fColors = nullptr;
28 
29         fName = SkStringPrintf("DrawLattice_%s", desc);
30     }
31 
onGetName()32     const char* onGetName() override {
33         return fName.c_str();
34     }
35 
onGetSize()36     SkIPoint onGetSize() override {
37         return SkIPoint::Make(1000, 1000);
38     }
39 
isSuitableFor(Backend backend)40     bool isSuitableFor(Backend backend) override {
41         return kRaster_Backend == backend || kGPU_Backend == backend;
42     }
43 
onDelayedSetup()44     void onDelayedSetup() override {
45         fBitmap.allocN32Pixels(fSrcSize.width(), fSrcSize.height());
46         fBitmap.eraseColor(0x880000FF);
47     }
48 
onDraw(int loops,SkCanvas * canvas)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 
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");)
79