blob: 1f34a003b283c4a26fc54c4cae3b983ec702f207 [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
45 const SkPicture* picture() const { return fPic; }
46 const SkTDArray<SkSurface*>& surfaces() const { return fSurfaces; }
47 const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
48
mtklein92007582014-08-01 07:46:52 -070049private:
50 SkAutoTUnref<const SkPicture> fPic;
51 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;
57 SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw
58 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