blob: 66ce1197f060371a9bc09cc69115d97567e5de96 [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>
23
John Recke45b1fd2014-04-15 09:50:16 -070024namespace android {
25namespace uirenderer {
26
27class Interpolator {
28public:
29 virtual ~Interpolator() {}
30
31 virtual float interpolate(float input) = 0;
32
33 static Interpolator* createDefaultInterpolator();
34
35protected:
36 Interpolator() {}
37};
38
John Reck315c3292014-05-09 19:21:04 -070039class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator {
John Recke45b1fd2014-04-15 09:50:16 -070040public:
Chris Craikd41c4d82015-01-05 15:51:13 -080041 virtual float interpolate(float input) override;
John Recke45b1fd2014-04-15 09:50:16 -070042};
43
John Reckc8ac7752014-05-12 16:39:41 -070044class ANDROID_API AccelerateInterpolator : public Interpolator {
45public:
46 AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor*2) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080047 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070048private:
49 const float mFactor;
50 const float mDoubleFactor;
51};
52
53class ANDROID_API AnticipateInterpolator : public Interpolator {
54public:
55 AnticipateInterpolator(float tension) : mTension(tension) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080056 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070057private:
58 const float mTension;
59};
60
61class ANDROID_API AnticipateOvershootInterpolator : public Interpolator {
62public:
63 AnticipateOvershootInterpolator(float tension) : mTension(tension) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080064 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070065private:
66 const float mTension;
67};
68
69class ANDROID_API BounceInterpolator : public Interpolator {
70public:
Chris Craikd41c4d82015-01-05 15:51:13 -080071 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070072};
73
74class ANDROID_API CycleInterpolator : public Interpolator {
75public:
76 CycleInterpolator(float cycles) : mCycles(cycles) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080077 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070078private:
79 const float mCycles;
80};
81
82class ANDROID_API DecelerateInterpolator : public Interpolator {
83public:
84 DecelerateInterpolator(float factor) : mFactor(factor) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080085 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070086private:
87 const float mFactor;
88};
89
90class ANDROID_API LinearInterpolator : public Interpolator {
91public:
Chris Craikd41c4d82015-01-05 15:51:13 -080092 virtual float interpolate(float input) override { return input; }
John Reckc8ac7752014-05-12 16:39:41 -070093};
94
95class ANDROID_API OvershootInterpolator : public Interpolator {
96public:
97 OvershootInterpolator(float tension) : mTension(tension) {}
Chris Craikd41c4d82015-01-05 15:51:13 -080098 virtual float interpolate(float input) override;
John Reckc8ac7752014-05-12 16:39:41 -070099private:
100 const float mTension;
101};
102
John Reck315c3292014-05-09 19:21:04 -0700103class ANDROID_API LUTInterpolator : public Interpolator {
104public:
105 LUTInterpolator(float* values, size_t size);
106 ~LUTInterpolator();
107
Chris Craikd41c4d82015-01-05 15:51:13 -0800108 virtual float interpolate(float input) override;
John Reck315c3292014-05-09 19:21:04 -0700109
110private:
Chris Craik51d6a3d2014-12-22 17:16:56 -0800111 std::unique_ptr<float[]> mValues;
John Reck315c3292014-05-09 19:21:04 -0700112 size_t mSize;
113};
114
John Recke45b1fd2014-04-15 09:50:16 -0700115} /* namespace uirenderer */
116} /* namespace android */
117
118#endif /* INTERPOLATOR_H */