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