blob: 89c9a369a080559c411902d9cd8919335cb463e2 [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
mtklein92007582014-08-01 07:46:52 -070031protected:
mtklein36352bf2015-03-25 18:17:31 -070032 const char* onGetName() override;
33 const char* onGetUniqueName() override;
34 void onPerCanvasPreDraw(SkCanvas*) override;
35 void onPerCanvasPostDraw(SkCanvas*) override;
36 bool isSuitableFor(Backend backend) override;
mtkleina1ebeb22015-10-01 09:43:39 -070037 void onDraw(int loops, SkCanvas* canvas) override;
mtklein36352bf2015-03-25 18:17:31 -070038 SkIPoint onGetSize() override;
mtklein92007582014-08-01 07:46:52 -070039
joshualitt261c3ad2015-04-27 09:16:57 -070040 virtual void drawMPDPicture();
41 virtual void drawPicture();
42
43 const SkPicture* picture() const { return fPic; }
44 const SkTDArray<SkSurface*>& surfaces() const { return fSurfaces; }
45 const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
46
mtklein92007582014-08-01 07:46:52 -070047private:
48 SkAutoTUnref<const SkPicture> fPic;
49 const SkIRect fClip;
50 const SkScalar fScale;
51 SkString fName;
mtklein96289052014-09-10 12:05:59 -070052 SkString fUniqueName;
mtklein92007582014-08-01 07:46:52 -070053
robertphillips5b693772014-11-21 06:19:36 -080054 const bool fUseMultiPictureDraw;
55 SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw
56 SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw
57
cdaltonb4022962015-06-25 10:51:56 -070058 const bool fDoLooping;
59
mtklein92007582014-08-01 07:46:52 -070060 typedef Benchmark INHERITED;
61};
62
63#endif