blob: 44ebc6fd85b42b1f23932a0905c3e46f2ddd845f [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
11#include "Benchmark.h"
12#include "SkCanvas.h"
13#include "SkPicture.h"
bungemand3ebb482015-08-05 13:57:49 -070014#include "SkTDArray.h"
15
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,
cdaltonb4022962015-06-25 10:51:56 -070024 bool useMultiPictureDraw, 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;
32
mtklein92007582014-08-01 07:46:52 -070033protected:
mtklein36352bf2015-03-25 18:17:31 -070034 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;
mtkleina1ebeb22015-10-01 09:43:39 -070039 void onDraw(int loops, SkCanvas* canvas) override;
mtklein36352bf2015-03-25 18:17:31 -070040 SkIPoint onGetSize() override;
mtklein92007582014-08-01 07:46:52 -070041
joshualitt261c3ad2015-04-27 09:16:57 -070042 virtual void drawMPDPicture();
43 virtual void drawPicture();
44
Hal Canary2db83612016-11-04 13:02:54 -040045 const SkPicture* picture() const { return fPic.get(); }
Ben Wagner9ec70c62018-07-12 13:30:47 -040046 const SkTArray<sk_sp<SkSurface>, true>& surfaces() const { return fSurfaces; }
joshualitt261c3ad2015-04-27 09:16:57 -070047 const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
48
mtklein92007582014-08-01 07:46:52 -070049private:
Hal Canary2db83612016-11-04 13:02:54 -040050 sk_sp<const SkPicture> fPic;
mtklein92007582014-08-01 07:46:52 -070051 const SkIRect fClip;
52 const SkScalar fScale;
53 SkString fName;
mtklein96289052014-09-10 12:05:59 -070054 SkString fUniqueName;
mtklein92007582014-08-01 07:46:52 -070055
robertphillips5b693772014-11-21 06:19:36 -080056 const bool fUseMultiPictureDraw;
Ben Wagner9ec70c62018-07-12 13:30:47 -040057 SkTArray<sk_sp<SkSurface>, true> 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
mtklein92007582014-08-01 07:46:52 -070062 typedef Benchmark INHERITED;
63};
64
65#endif