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
19#include <stddef.h>
20#include <memory>
21
22#include <cutils/compiler.h>
23#include <vector>
24
25namespace 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
40class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator {
41public:
42    virtual float interpolate(float input) override;
43};
44
45class ANDROID_API AccelerateInterpolator : public Interpolator {
46public:
47    explicit AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor * 2) {}
48    virtual float interpolate(float input) override;
49
50private:
51    const float mFactor;
52    const float mDoubleFactor;
53};
54
55class ANDROID_API AnticipateInterpolator : public Interpolator {
56public:
57    explicit AnticipateInterpolator(float tension) : mTension(tension) {}
58    virtual float interpolate(float input) override;
59
60private:
61    const float mTension;
62};
63
64class ANDROID_API AnticipateOvershootInterpolator : public Interpolator {
65public:
66    explicit AnticipateOvershootInterpolator(float tension) : mTension(tension) {}
67    virtual float interpolate(float input) override;
68
69private:
70    const float mTension;
71};
72
73class ANDROID_API BounceInterpolator : public Interpolator {
74public:
75    virtual float interpolate(float input) override;
76};
77
78class ANDROID_API CycleInterpolator : public Interpolator {
79public:
80    explicit CycleInterpolator(float cycles) : mCycles(cycles) {}
81    virtual float interpolate(float input) override;
82
83private:
84    const float mCycles;
85};
86
87class ANDROID_API DecelerateInterpolator : public Interpolator {
88public:
89    explicit DecelerateInterpolator(float factor) : mFactor(factor) {}
90    virtual float interpolate(float input) override;
91
92private:
93    const float mFactor;
94};
95
96class ANDROID_API LinearInterpolator : public Interpolator {
97public:
98    virtual float interpolate(float input) override { return input; }
99};
100
101class ANDROID_API OvershootInterpolator : public Interpolator {
102public:
103    explicit OvershootInterpolator(float tension) : mTension(tension) {}
104    virtual float interpolate(float input) override;
105
106private:
107    const float mTension;
108};
109
110class ANDROID_API PathInterpolator : public Interpolator {
111public:
112    explicit PathInterpolator(std::vector<float>&& x, std::vector<float>&& y) : mX(x), mY(y) {}
113    virtual float interpolate(float input) override;
114
115private:
116    std::vector<float> mX;
117    std::vector<float> mY;
118};
119
120class ANDROID_API LUTInterpolator : public Interpolator {
121public:
122    LUTInterpolator(float* values, size_t size);
123    ~LUTInterpolator();
124
125    virtual float interpolate(float input) override;
126
127private:
128    std::unique_ptr<float[]> mValues;
129    size_t mSize;
130};
131
132} /* namespace uirenderer */
133} /* namespace android */
134
135#endif /* INTERPOLATOR_H */
136