blob: 452988fc871120d40068607ee729492561021514 [file] [log] [blame]
John Recke45b1fd2014-04-15 09:50:16 -07001/*
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 Reck315c3292014-05-09 19:21:04 -070019#include <stddef.h>
Chris Craik51d6a3d2014-12-22 17:16:56 -080020#include <memory>
John Reck315c3292014-05-09 19:21:04 -070021
22#include <cutils/compiler.h>
Doris Liu9e9eeee2016-11-29 14:48:25 -080023#include <vector>
John Reck315c3292014-05-09 19:21:04 -070024
John Recke45b1fd2014-04-15 09:50:16 -070025namespace android {
26namespace uirenderer {
27
28class Interpolator {
29public:
30 virtual ~Interpolator() {}
31
32 virtual float interpolate(float input) = 0;
33
34 static Interpolator* createDefaultInterpolator();
35
36protected:
37 Interpolator() {}
38};
39
John Reck315c3292014-05-09 19:21:04 -070040class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator {
John Recke45b1fd2014-04-15 09:50:16 -070041public:
Chris Craikd41c4d82015-01-05 15:51:13 -080042 virtual float interpolate(float input) override;
John Recke45b1fd2014-04-15 09:50:16 -070043};
44
John Reckc8ac7752014-05-12 16:39:41 -070045class ANDROID_API AccelerateInterpolator : public Interpolator {
46public:
John Reck1bcacfd2017-11-03 10:12:19 -070047 explicit AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor * 2) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080048 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -070049
John Reckc8ac7752014-05-12 16:39:41 -070050private:
51 const float mFactor;
52 const float mDoubleFactor;
53};
54
55class ANDROID_API AnticipateInterpolator : public Interpolator {
56public:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070057 explicit AnticipateInterpolator(float tension) : mTension(tension) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080058 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -070059
John Reckc8ac7752014-05-12 16:39:41 -070060private:
61 const float mTension;
62};
63
64class ANDROID_API AnticipateOvershootInterpolator : public Interpolator {
65public:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070066 explicit AnticipateOvershootInterpolator(float tension) : mTension(tension) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080067 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -070068
John Reckc8ac7752014-05-12 16:39:41 -070069private:
70 const float mTension;
71};
72
73class ANDROID_API BounceInterpolator : public Interpolator {
74public:
Chris Craikd41c4d82015-01-05 15:51:13 -080075 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070076};
77
78class ANDROID_API CycleInterpolator : public Interpolator {
79public:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070080 explicit CycleInterpolator(float cycles) : mCycles(cycles) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080081 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -070082
John Reckc8ac7752014-05-12 16:39:41 -070083private:
84 const float mCycles;
85};
86
87class ANDROID_API DecelerateInterpolator : public Interpolator {
88public:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070089 explicit DecelerateInterpolator(float factor) : mFactor(factor) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080090 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -070091
John Reckc8ac7752014-05-12 16:39:41 -070092private:
93 const float mFactor;
94};
95
96class ANDROID_API LinearInterpolator : public Interpolator {
97public:
Chris Craikd41c4d82015-01-05 15:51:13 -080098 virtual float interpolate(float input) override { return input; }
John Reckc8ac7752014-05-12 16:39:41 -070099};
100
101class ANDROID_API OvershootInterpolator : public Interpolator {
102public:
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700103 explicit OvershootInterpolator(float tension) : mTension(tension) {}
Chris Craikd41c4d82015-01-05 15:51:13 -0800104 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -0700105
John Reckc8ac7752014-05-12 16:39:41 -0700106private:
107 const float mTension;
108};
109
Doris Liu9e9eeee2016-11-29 14:48:25 -0800110class ANDROID_API PathInterpolator : public Interpolator {
111public:
John Reck1bcacfd2017-11-03 10:12:19 -0700112 explicit PathInterpolator(std::vector<float>&& x, std::vector<float>&& y) : mX(x), mY(y) {}
Doris Liu9e9eeee2016-11-29 14:48:25 -0800113 virtual float interpolate(float input) override;
John Reck1bcacfd2017-11-03 10:12:19 -0700114
Doris Liu9e9eeee2016-11-29 14:48:25 -0800115private:
116 std::vector<float> mX;
117 std::vector<float> mY;
118};
119
John Reck315c3292014-05-09 19:21:04 -0700120class ANDROID_API LUTInterpolator : public Interpolator {
121public:
122 LUTInterpolator(float* values, size_t size);
123 ~LUTInterpolator();
124
Chris Craikd41c4d82015-01-05 15:51:13 -0800125 virtual float interpolate(float input) override;
John Reck315c3292014-05-09 19:21:04 -0700126
127private:
Chris Craik51d6a3d2014-12-22 17:16:56 -0800128 std::unique_ptr<float[]> mValues;
John Reck315c3292014-05-09 19:21:04 -0700129 size_t mSize;
130};
131
John Recke45b1fd2014-04-15 09:50:16 -0700132} /* namespace uirenderer */
133} /* namespace android */
134
135#endif /* INTERPOLATOR_H */