joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "bench/SKPBench.h" |
Ben Wagner | acf98df | 2019-07-12 12:51:44 -0400 | [diff] [blame] | 12 | #include "include/utils/SkRandom.h" |
Mike Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 13 | #include "tools/timer/Timer.h" |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 14 | |
| 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 | */ |
| 19 | class SKPAnimationBench : public SKPBench { |
| 20 | public: |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 21 | 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 Wagner | acf98df | 2019-07-12 12:51:44 -0400 | [diff] [blame] | 29 | SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, sk_sp<Animation>, |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 30 | bool doLooping); |
| 31 | |
Ben Wagner | acf98df | 2019-07-12 12:51:44 -0400 | [diff] [blame] | 32 | static sk_sp<Animation> MakeZoomAnimation(SkScalar zoomMax, double zoomPeriodMs); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 33 | |
| 34 | protected: |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 35 | const char* onGetUniqueName() override; |
| 36 | void onPerCanvasPreDraw(SkCanvas* canvas) override; |
| 37 | |
| 38 | void drawMPDPicture() override { |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 39 | SK_ABORT("MPD not supported\n"); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 40 | } |
| 41 | void drawPicture() override; |
| 42 | |
| 43 | private: |
Hal Canary | 2db8361 | 2016-11-04 13:02:54 -0400 | [diff] [blame] | 44 | sk_sp<Animation> fAnimation; |
Ben Wagner | acf98df | 2019-07-12 12:51:44 -0400 | [diff] [blame] | 45 | SkRandom fAnimationTime; |
Hal Canary | 2db8361 | 2016-11-04 13:02:54 -0400 | [diff] [blame] | 46 | SkString fUniqueName; |
| 47 | SkIRect fDevBounds; |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 48 | |
| 49 | typedef SKPBench INHERITED; |
| 50 | }; |
| 51 | |
| 52 | #endif |