Home | History | Annotate | Download | only in hwui
      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 
     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 
     39 class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator {
     40 public:
     41     virtual float interpolate(float input) override;
     42 };
     43 
     44 class ANDROID_API AccelerateInterpolator : public Interpolator {
     45 public:
     46     AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor*2) {}
     47     virtual float interpolate(float input) override;
     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) {}
     56     virtual float interpolate(float input) override;
     57 private:
     58     const float mTension;
     59 };
     60 
     61 class ANDROID_API AnticipateOvershootInterpolator : public Interpolator {
     62 public:
     63     AnticipateOvershootInterpolator(float tension) : mTension(tension) {}
     64     virtual float interpolate(float input) override;
     65 private:
     66     const float mTension;
     67 };
     68 
     69 class ANDROID_API BounceInterpolator : public Interpolator {
     70 public:
     71     virtual float interpolate(float input) override;
     72 };
     73 
     74 class ANDROID_API CycleInterpolator : public Interpolator {
     75 public:
     76     CycleInterpolator(float cycles) : mCycles(cycles) {}
     77     virtual float interpolate(float input) override;
     78 private:
     79     const float mCycles;
     80 };
     81 
     82 class ANDROID_API DecelerateInterpolator : public Interpolator {
     83 public:
     84     DecelerateInterpolator(float factor) : mFactor(factor) {}
     85     virtual float interpolate(float input) override;
     86 private:
     87     const float mFactor;
     88 };
     89 
     90 class ANDROID_API LinearInterpolator : public Interpolator {
     91 public:
     92     virtual float interpolate(float input) override { return input; }
     93 };
     94 
     95 class ANDROID_API OvershootInterpolator : public Interpolator {
     96 public:
     97     OvershootInterpolator(float tension) : mTension(tension) {}
     98     virtual float interpolate(float input) override;
     99 private:
    100     const float mTension;
    101 };
    102 
    103 class ANDROID_API LUTInterpolator : public Interpolator {
    104 public:
    105     LUTInterpolator(float* values, size_t size);
    106     ~LUTInterpolator();
    107 
    108     virtual float interpolate(float input) override;
    109 
    110 private:
    111     std::unique_ptr<float[]> mValues;
    112     size_t mSize;
    113 };
    114 
    115 } /* namespace uirenderer */
    116 } /* namespace android */
    117 
    118 #endif /* INTERPOLATOR_H */
    119