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> |
| 23 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | |
| 27 | class Interpolator { |
| 28 | public: |
| 29 | virtual ~Interpolator() {} |
| 30 | |
| 31 | virtual float interpolate(float input) = 0; |
| 32 | |
| 33 | static Interpolator* createDefaultInterpolator(); |
| 34 | |
| 35 | protected: |
| 36 | Interpolator() {} |
| 37 | }; |
| 38 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 39 | class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 40 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 41 | virtual float interpolate(float input) override; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 44 | class ANDROID_API AccelerateInterpolator : public Interpolator { |
| 45 | public: |
| 46 | AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor*2) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 47 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 48 | private: |
| 49 | const float mFactor; |
| 50 | const float mDoubleFactor; |
| 51 | }; |
| 52 | |
| 53 | class ANDROID_API AnticipateInterpolator : public Interpolator { |
| 54 | public: |
| 55 | AnticipateInterpolator(float tension) : mTension(tension) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 56 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 57 | private: |
| 58 | const float mTension; |
| 59 | }; |
| 60 | |
| 61 | class ANDROID_API AnticipateOvershootInterpolator : public Interpolator { |
| 62 | public: |
| 63 | AnticipateOvershootInterpolator(float tension) : mTension(tension) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 64 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 65 | private: |
| 66 | const float mTension; |
| 67 | }; |
| 68 | |
| 69 | class ANDROID_API BounceInterpolator : public Interpolator { |
| 70 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 71 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | class ANDROID_API CycleInterpolator : public Interpolator { |
| 75 | public: |
| 76 | CycleInterpolator(float cycles) : mCycles(cycles) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 77 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 78 | private: |
| 79 | const float mCycles; |
| 80 | }; |
| 81 | |
| 82 | class ANDROID_API DecelerateInterpolator : public Interpolator { |
| 83 | public: |
| 84 | DecelerateInterpolator(float factor) : mFactor(factor) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 85 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 86 | private: |
| 87 | const float mFactor; |
| 88 | }; |
| 89 | |
| 90 | class ANDROID_API LinearInterpolator : public Interpolator { |
| 91 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 92 | virtual float interpolate(float input) override { return input; } |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | class ANDROID_API OvershootInterpolator : public Interpolator { |
| 96 | public: |
| 97 | OvershootInterpolator(float tension) : mTension(tension) {} |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 98 | virtual float interpolate(float input) override; |
John Reck | c8ac775 | 2014-05-12 16:39:41 -0700 | [diff] [blame] | 99 | private: |
| 100 | const float mTension; |
| 101 | }; |
| 102 | |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 103 | class ANDROID_API LUTInterpolator : public Interpolator { |
| 104 | public: |
| 105 | LUTInterpolator(float* values, size_t size); |
| 106 | ~LUTInterpolator(); |
| 107 | |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 108 | virtual float interpolate(float input) override; |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 109 | |
| 110 | private: |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 111 | std::unique_ptr<float[]> mValues; |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 112 | size_t mSize; |
| 113 | }; |
| 114 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 115 | } /* namespace uirenderer */ |
| 116 | } /* namespace android */ |
| 117 | |
| 118 | #endif /* INTERPOLATOR_H */ |