blob: e1c66bf2ecfe5029ef0c4736872f5d9ddd3b70e7 [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"
14
15/**
16 * Runs an SkPicture as a benchmark by repeatedly drawing it scaled inside a device clip.
17 */
18class SKPBench : public Benchmark {
19public:
robertphillips5b693772014-11-21 06:19:36 -080020 SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale,
cdaltonb4022962015-06-25 10:51:56 -070021 bool useMultiPictureDraw, bool doLooping);
mtklein36352bf2015-03-25 18:17:31 -070022 ~SKPBench() override;
mtklein92007582014-08-01 07:46:52 -070023
cdaltonb4022962015-06-25 10:51:56 -070024 int calculateLoops(int defaultLoops) const override {
25 return fDoLooping ? defaultLoops : 1;
26 }
27
mtklein92007582014-08-01 07:46:52 -070028protected:
mtklein36352bf2015-03-25 18:17:31 -070029 const char* onGetName() override;
30 const char* onGetUniqueName() override;
31 void onPerCanvasPreDraw(SkCanvas*) override;
32 void onPerCanvasPostDraw(SkCanvas*) override;
33 bool isSuitableFor(Backend backend) override;
34 void onDraw(const int loops, SkCanvas* canvas) override;
35 SkIPoint onGetSize() override;
mtklein92007582014-08-01 07:46:52 -070036
joshualitt261c3ad2015-04-27 09:16:57 -070037 virtual void drawMPDPicture();
38 virtual void drawPicture();
39
40 const SkPicture* picture() const { return fPic; }
41 const SkTDArray<SkSurface*>& surfaces() const { return fSurfaces; }
42 const SkTDArray<SkIRect>& tileRects() const { return fTileRects; }
43
mtklein92007582014-08-01 07:46:52 -070044private:
45 SkAutoTUnref<const SkPicture> fPic;
46 const SkIRect fClip;
47 const SkScalar fScale;
48 SkString fName;
mtklein96289052014-09-10 12:05:59 -070049 SkString fUniqueName;
mtklein92007582014-08-01 07:46:52 -070050
robertphillips5b693772014-11-21 06:19:36 -080051 const bool fUseMultiPictureDraw;
52 SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw
53 SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw
54
cdaltonb4022962015-06-25 10:51:56 -070055 const bool fDoLooping;
56
mtklein92007582014-08-01 07:46:52 -070057 typedef Benchmark INHERITED;
58};
59
60#endif