John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef INTERPOLATOR_H |
| 17 | #define INTERPOLATOR_H |
| 18 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 19 | #include <stddef.h> |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 20 | #include <memory> |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 21 | |
| 22 | #include <cutils/compiler.h> |
Doris Liu | 9e9eeee | 2016-11-29 14:48:25 -0800 | [diff] [blame] | 23 | #include <vector> |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 24 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | class Interpolator { |
| 29 | public: |
| 30 | virtual ~Interpolator() {} |
| 31 | |
| 32 | virtual float interpolate(float input) = 0; |
| 33 | |
| 34 | static Interpolator* createDefaultInterpolator(); |
| 35 | |
| 36 | protected: |
| 37 | Interpolator() {} |
| 38 | }; |
| 39 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 40 | class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 41 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 42 | virtual float interpolate(float input) override; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 45 | class ANDROID_API AccelerateInterpolator : public Interpolator { |
| 46 | public: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 47 | explicit AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor*2) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 48 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 49 | private: |
| 50 | const float mFactor; |
| 51 | const float mDoubleFactor; |
| 52 | }; |
| 53 | |
| 54 | class ANDROID_API AnticipateInterpolator : public Interpolator { |
| 55 | public: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 56 | explicit AnticipateInterpolator(float tension) : mTension(tension) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 57 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 58 | private: |
| 59 | const float mTension; |
| 60 | }; |
| 61 | |
| 62 | class ANDROID_API AnticipateOvershootInterpolator : public Interpolator { |
| 63 | public: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 64 | explicit AnticipateOvershootInterpolator(float tension) : mTension(tension) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 65 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 66 | private: |
| 67 | const float mTension; |
| 68 | }; |
| 69 | |
| 70 | class ANDROID_API BounceInterpolator : public Interpolator { |
| 71 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 72 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | class ANDROID_API CycleInterpolator : public Interpolator { |
| 76 | public: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 77 | explicit CycleInterpolator(float cycles) : mCycles(cycles) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 78 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 79 | private: |
| 80 | const float mCycles; |
| 81 | }; |
| 82 | |
| 83 | class ANDROID_API DecelerateInterpolator : public Interpolator { |
| 84 | public: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 85 | explicit DecelerateInterpolator(float factor) : mFactor(factor) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 86 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 87 | private: |
| 88 | const float mFactor; |
| 89 | }; |
| 90 | |
| 91 | class ANDROID_API LinearInterpolator : public Interpolator { |
| 92 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 93 | virtual float interpolate(float input) override { return input; } |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | class ANDROID_API OvershootInterpolator : public Interpolator { |
| 97 | public: |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 98 | explicit OvershootInterpolator(float tension) : mTension(tension) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 99 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 100 | private: |
| 101 | const float mTension; |
| 102 | }; |
| 103 | |
Doris Liu | 9e9eeee | 2016-11-29 14:48:25 -0800 | [diff] [blame] | 104 | class ANDROID_API PathInterpolator : public Interpolator { |
| 105 | public: |
| 106 | explicit PathInterpolator(std::vector<float>&& x, std::vector<float>&& y) |
| 107 | : mX (x), mY(y) {} |
| 108 | virtual float interpolate(float input) override; |
| 109 | private: |
| 110 | std::vector<float> mX; |
| 111 | std::vector<float> mY; |
| 112 | }; |
| 113 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 114 | class ANDROID_API LUTInterpolator : public Interpolator { |
| 115 | public: |
| 116 | LUTInterpolator(float* values, size_t size); |
| 117 | ~LUTInterpolator(); |
| 118 | |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 119 | virtual float interpolate(float input) override; |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 120 | |
| 121 | private: |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 122 | std::unique_ptr<float[]> mValues; |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 123 | size_t mSize; |
| 124 | }; |
| 125 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 126 | } /* namespace uirenderer */ |
| 127 | } /* namespace android */ |
| 128 | |
| 129 | #endif /* INTERPOLATOR_H */ |