• 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/base/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 
shouldLoop()27     bool shouldLoop() const override {
28         return fDoLooping;
29     }
30 
31     void getGpuStats(SkCanvas*,
32                      skia_private::TArray<SkString>* keys,
33                      skia_private::TArray<double>* values) override;
34     bool getDMSAAStats(GrRecordingContext*) override;
35 
36 protected:
37     const char* onGetName() override;
38     const char* onGetUniqueName() override;
39     void onPerCanvasPreDraw(SkCanvas*) override;
40     void onPerCanvasPostDraw(SkCanvas*) override;
41     bool isSuitableFor(Backend backend) override;
onDraw(int loops,SkCanvas *)42     void onDraw(int loops, SkCanvas*) override { SkASSERT(false); }
43     void onDrawFrame(int loops, SkCanvas*, std::function<void()> submitFrame) override;
44     SkISize onGetSize() override;
45 
46     virtual void drawMPDPicture();
47     virtual void drawPicture();
48 
picture()49     const SkPicture* picture() const { return fPic.get(); }
surfaces()50     const skia_private::TArray<sk_sp<SkSurface>>& surfaces() const { return fSurfaces; }
tileRects()51     const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
52 
53 private:
submitsInternalFrames()54     bool submitsInternalFrames() override { return true; }
55 
56     sk_sp<const SkPicture> fPic;
57     const SkIRect fClip;
58     const SkScalar fScale;
59     SkString fName;
60     SkString fUniqueName;
61 
62     skia_private::TArray<sk_sp<SkSurface>> fSurfaces;   // for MultiPictureDraw
63     SkTDArray<SkIRect> fTileRects;     // for MultiPictureDraw
64 
65     const bool fDoLooping;
66 
67     using INHERITED = Benchmark;
68 };
69 
70 #endif
71