• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bench/Benchmark.h"
12 #include "include/core/SkCanvas.h"
13 #include "include/core/SkPicture.h"
14 #include "include/private/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 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     bool getDMSAAStats(GrRecordingContext*) override;
33 
34 protected:
35     const char* onGetName() override;
36     const char* onGetUniqueName() override;
37     void onPerCanvasPreDraw(SkCanvas*) override;
38     void onPerCanvasPostDraw(SkCanvas*) override;
39     bool isSuitableFor(Backend backend) override;
40     void onDraw(int loops, SkCanvas* canvas) override;
41     SkIPoint onGetSize() override;
42 
43     virtual void drawMPDPicture();
44     virtual void drawPicture();
45 
picture()46     const SkPicture* picture() const { return fPic.get(); }
surfaces()47     const SkTArray<sk_sp<SkSurface>>& surfaces() const { return fSurfaces; }
tileRects()48     const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
49 
50 private:
51     sk_sp<const SkPicture> fPic;
52     const SkIRect fClip;
53     const SkScalar fScale;
54     SkString fName;
55     SkString fUniqueName;
56 
57     SkTArray<sk_sp<SkSurface>> fSurfaces;   // for MultiPictureDraw
58     SkTDArray<SkIRect> fTileRects;     // for MultiPictureDraw
59 
60     const bool fDoLooping;
61 
62     using INHERITED = Benchmark;
63 };
64 
65 #endif
66