blob: d3c595d9525a6a449d04c0c3cb2286fe5591582e [file] [log] [blame]
mtklein92007582014-08-01 07:46:52 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "bench/Benchmark.h"
12#include "include/core/SkCanvas.h"
13#include "include/core/SkPicture.h"
14#include "include/private/SkTDArray.h"
bungemand3ebb482015-08-05 13:57:49 -070015
16class SkSurface;
mtklein92007582014-08-01 07:46:52 -070017
18/**
19 * Runs an SkPicture as a benchmark by repeatedly drawing it scaled inside a device clip.
20 */
21class SKPBench : public Benchmark {
22public:
robertphillips5b693772014-11-21 06:19:36 -080023 SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale,
Brian Salomon626349b2020-08-27 10:54:36 -040024 bool doLooping);
mtklein36352bf2015-03-25 18:17:31 -070025 ~SKPBench() override;
mtklein92007582014-08-01 07:46:52 -070026
cdaltonb4022962015-06-25 10:51:56 -070027 int calculateLoops(int defaultLoops) const override {
28 return fDoLooping ? defaultLoops : 1;
29 }
30
joshualitte45c81c2015-12-02 09:05:37 -080031 void getGpuStats(SkCanvas*, SkTArray<SkString>* keys, SkTArray<double>* values) override;
Chris Dalton5dfb3f42021-04-30 17:16:12 -060032 bool getDMSAAStats(GrRecordingContext*) override;
joshualitte45c81c2015-12-02 09:05:37 -080033
mtklein92007582014-08-01 07:46:52 -070034protected:
mtklein36352bf2015-03-25 18:17:31 -070035 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;
mtkleina1ebeb22015-10-01 09:43:39 -070040 void onDraw(int loops, SkCanvas* canvas) override;
mtklein36352bf2015-03-25 18:17:31 -070041 SkIPoint onGetSize() override;
mtklein92007582014-08-01 07:46:52 -070042
joshualitt261c3ad2015-04-27 09:16:57 -070043 virtual void drawMPDPicture();
44 virtual void drawPicture();
45
Hal Canary2db83612016-11-04 13:02:54 -040046 const SkPicture* picture() const { return fPic.get(); }
Brian Salomon343553a2018-09-05 15:41:23 -040047 const SkTArray<sk_sp<SkSurface>>& surfaces() const { return fSurfaces; }
joshualitt261c3ad2015-04-27 09:16:57 -070048 const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
49
mtklein92007582014-08-01 07:46:52 -070050private:
Hal Canary2db83612016-11-04 13:02:54 -040051 sk_sp<const SkPicture> fPic;
mtklein92007582014-08-01 07:46:52 -070052 const SkIRect fClip;
53 const SkScalar fScale;
54 SkString fName;
mtklein96289052014-09-10 12:05:59 -070055 SkString fUniqueName;
mtklein92007582014-08-01 07:46:52 -070056
Brian Salomon343553a2018-09-05 15:41:23 -040057 SkTArray<sk_sp<SkSurface>> fSurfaces; // for MultiPictureDraw
robertphillips5b693772014-11-21 06:19:36 -080058 SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw
59
cdaltonb4022962015-06-25 10:51:56 -070060 const bool fDoLooping;
61
John Stiles7571f9e2020-09-02 22:42:33 -040062 using INHERITED = Benchmark;
mtklein92007582014-08-01 07:46:52 -070063};
64
65#endif