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; 42 void onDraw(int loops, SkCanvas* canvas) override; 43 SkISize onGetSize() override; 44 45 virtual void drawMPDPicture(); 46 virtual void drawPicture(); 47 picture()48 const SkPicture* picture() const { return fPic.get(); } surfaces()49 const skia_private::TArray<sk_sp<SkSurface>>& surfaces() const { return fSurfaces; } tileRects()50 const SkTDArray<SkIRect>& tileRects() const { return fTileRects; } 51 52 private: 53 sk_sp<const SkPicture> fPic; 54 const SkIRect fClip; 55 const SkScalar fScale; 56 SkString fName; 57 SkString fUniqueName; 58 59 skia_private::TArray<sk_sp<SkSurface>> fSurfaces; // for MultiPictureDraw 60 SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw 61 62 const bool fDoLooping; 63 64 using INHERITED = Benchmark; 65 }; 66 67 #endif 68