1 /*
2  * Copyright 2014 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 #ifndef SKPBench_DEFINED
9 #define SKPBench_DEFINED
10 
11 #include "Benchmark.h"
12 #include "SkCanvas.h"
13 #include "SkPicture.h"
14 
15 /**
16  * Runs an SkPicture as a benchmark by repeatedly drawing it scaled inside a device clip.
17  */
18 class SKPBench : public Benchmark {
19 public:
20     SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale,
21              bool useMultiPictureDraw);
22     ~SKPBench() override;
23 
24 protected:
25     const char* onGetName() override;
26     const char* onGetUniqueName() override;
27     void onPerCanvasPreDraw(SkCanvas*) override;
28     void onPerCanvasPostDraw(SkCanvas*) override;
29     bool isSuitableFor(Backend backend) override;
30     void onDraw(const int loops, SkCanvas* canvas) override;
31     SkIPoint onGetSize() override;
32 
33     virtual void drawMPDPicture();
34     virtual void drawPicture();
35 
picture()36     const SkPicture* picture() const { return fPic; }
surfaces()37     const SkTDArray<SkSurface*>& surfaces() const { return fSurfaces; }
tileRects()38     const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
39 
40 private:
41     SkAutoTUnref<const SkPicture> fPic;
42     const SkIRect fClip;
43     const SkScalar fScale;
44     SkString fName;
45     SkString fUniqueName;
46 
47     const bool fUseMultiPictureDraw;
48     SkTDArray<SkSurface*> fSurfaces;   // for MultiPictureDraw
49     SkTDArray<SkIRect> fTileRects;     // for MultiPictureDraw
50 
51     typedef Benchmark INHERITED;
52 };
53 
54 #endif
55