blob: 84333225a7c3cd67238eec5ea6b341e99f21c7b8 [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;
cdalton63a82852015-06-29 14:06:10 -070026 };
27
Ben Wagneracf98df2019-07-12 12:51:44 -040028 SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, sk_sp<Animation>,
cdalton63a82852015-06-29 14:06:10 -070029 bool doLooping);
30
Ben Wagneracf98df2019-07-12 12:51:44 -040031 static sk_sp<Animation> MakeZoomAnimation(SkScalar zoomMax, double zoomPeriodMs);
joshualitt261c3ad2015-04-27 09:16:57 -070032
33protected:
joshualitt261c3ad2015-04-27 09:16:57 -070034 const char* onGetUniqueName() override;
35 void onPerCanvasPreDraw(SkCanvas* canvas) override;
36
37 void drawMPDPicture() override {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040038 SK_ABORT("MPD not supported\n");
joshualitt261c3ad2015-04-27 09:16:57 -070039 }
40 void drawPicture() override;
41
42private:
Hal Canary2db83612016-11-04 13:02:54 -040043 sk_sp<Animation> fAnimation;
Ben Wagneracf98df2019-07-12 12:51:44 -040044 SkRandom fAnimationTime;
Hal Canary2db83612016-11-04 13:02:54 -040045 SkString fUniqueName;
46 SkIRect fDevBounds;
joshualitt261c3ad2015-04-27 09:16:57 -070047
John Stiles7571f9e2020-09-02 22:42:33 -040048 using INHERITED = SKPBench;
joshualitt261c3ad2015-04-27 09:16:57 -070049};
50
51#endif