mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 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" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 14 | #include "SkTDArray.h" |
| 15 | |
| 16 | class SkSurface; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 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: |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 23 | SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale, |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 24 | bool useMultiPictureDraw, bool doLooping); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 25 | ~SKPBench() override; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 26 | |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 27 | int calculateLoops(int defaultLoops) const override { |
| 28 | return fDoLooping ? defaultLoops : 1; |
| 29 | } |
| 30 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 31 | void getGpuStats(SkCanvas*, SkTArray<SkString>* keys, SkTArray<double>* values) override; |
| 32 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 33 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 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; |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 39 | void onDraw(int loops, SkCanvas* canvas) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 40 | SkIPoint onGetSize() override; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 41 | |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 42 | virtual void drawMPDPicture(); |
| 43 | virtual void drawPicture(); |
| 44 | |
Hal Canary | 2db8361 | 2016-11-04 13:02:54 -0400 | [diff] [blame] | 45 | const SkPicture* picture() const { return fPic.get(); } |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 46 | const SkTArray<sk_sp<SkSurface>, true>& surfaces() const { return fSurfaces; } |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 47 | const SkTDArray<SkIRect>& tileRects() const { return fTileRects; } |
| 48 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 49 | private: |
Hal Canary | 2db8361 | 2016-11-04 13:02:54 -0400 | [diff] [blame] | 50 | sk_sp<const SkPicture> fPic; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 51 | const SkIRect fClip; |
| 52 | const SkScalar fScale; |
| 53 | SkString fName; |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 54 | SkString fUniqueName; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 55 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 56 | const bool fUseMultiPictureDraw; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 57 | SkTArray<sk_sp<SkSurface>, true> fSurfaces; // for MultiPictureDraw |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 58 | SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw |
| 59 | |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 60 | const bool fDoLooping; |
| 61 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 62 | typedef Benchmark INHERITED; |
| 63 | }; |
| 64 | |
| 65 | #endif |