blob: 153f1fdfdd877385a24308bd45beebc48a1135d4 [file] [log] [blame]
joshualitt261c3ad2015-04-27 09:16:57 -07001/*
2 * Copyright 2015 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 SKPAnimationBench_DEFINED
9#define SKPAnimationBench_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "bench/SKPBench.h"
Ben Wagneracf98df2019-07-12 12:51:44 -040012#include "include/utils/SkRandom.h"
Mike Klein52337de2019-07-25 09:00:52 -050013#include "tools/timer/Timer.h"
joshualitt261c3ad2015-04-27 09:16:57 -070014
15/**
16 * Runs an SkPicture as a benchmark by repeatedly drawing it, first centering the picture and
17 * for each step it concats the passed in matrix
18 */
19class SKPAnimationBench : public SKPBench {
20public:
cdalton63a82852015-06-29 14:06:10 -070021 class Animation : public SkRefCnt {
22 public:
23 virtual const char* getTag() = 0;
24 virtual void preConcatFrameMatrix(double animationTimeMs, const SkIRect& devBounds,
25 SkMatrix* drawMatrix) = 0;
26 virtual ~Animation() {}
27 };
28
Ben Wagneracf98df2019-07-12 12:51:44 -040029 SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, sk_sp<Animation>,
cdalton63a82852015-06-29 14:06:10 -070030 bool doLooping);
31
Ben Wagneracf98df2019-07-12 12:51:44 -040032 static sk_sp<Animation> MakeZoomAnimation(SkScalar zoomMax, double zoomPeriodMs);
joshualitt261c3ad2015-04-27 09:16:57 -070033
34protected:
joshualitt261c3ad2015-04-27 09:16:57 -070035 const char* onGetUniqueName() override;
36 void onPerCanvasPreDraw(SkCanvas* canvas) override;
37
38 void drawMPDPicture() override {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040039 SK_ABORT("MPD not supported\n");
joshualitt261c3ad2015-04-27 09:16:57 -070040 }
41 void drawPicture() override;
42
43private:
Hal Canary2db83612016-11-04 13:02:54 -040044 sk_sp<Animation> fAnimation;
Ben Wagneracf98df2019-07-12 12:51:44 -040045 SkRandom fAnimationTime;
Hal Canary2db83612016-11-04 13:02:54 -040046 SkString fUniqueName;
47 SkIRect fDevBounds;
joshualitt261c3ad2015-04-27 09:16:57 -070048
49 typedef SKPBench INHERITED;
50};
51
52#endif