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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "bench/Benchmark.h" |
| 12 | #include "include/core/SkCanvas.h" |
| 13 | #include "include/core/SkPicture.h" |
| 14 | #include "include/private/SkTDArray.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 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, |
Brian Salomon | 626349b | 2020-08-27 10:54:36 -0400 | [diff] [blame] | 24 | 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; |
Chris Dalton | 5dfb3f4 | 2021-04-30 17:16:12 -0600 | [diff] [blame] | 32 | bool getDMSAAStats(GrRecordingContext*) override; |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 33 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 34 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 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; |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 40 | void onDraw(int loops, SkCanvas* canvas) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 41 | SkIPoint onGetSize() override; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 42 | |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 43 | virtual void drawMPDPicture(); |
| 44 | virtual void drawPicture(); |
| 45 | |
Hal Canary | 2db8361 | 2016-11-04 13:02:54 -0400 | [diff] [blame] | 46 | const SkPicture* picture() const { return fPic.get(); } |
Brian Salomon | 343553a | 2018-09-05 15:41:23 -0400 | [diff] [blame] | 47 | const SkTArray<sk_sp<SkSurface>>& surfaces() const { return fSurfaces; } |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 48 | const SkTDArray<SkIRect>& tileRects() const { return fTileRects; } |
| 49 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 50 | private: |
Hal Canary | 2db8361 | 2016-11-04 13:02:54 -0400 | [diff] [blame] | 51 | sk_sp<const SkPicture> fPic; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 52 | const SkIRect fClip; |
| 53 | const SkScalar fScale; |
| 54 | SkString fName; |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 55 | SkString fUniqueName; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 56 | |
Brian Salomon | 343553a | 2018-09-05 15:41:23 -0400 | [diff] [blame] | 57 | SkTArray<sk_sp<SkSurface>> 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 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 62 | using INHERITED = Benchmark; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif |