• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 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 
17 #ifndef INTERPOLATOR_H_
18 #define INTERPOLATOR_H_
19 
20 #include <jni.h>
21 #include <errno.h>
22 #include <time.h>
23 #include "JNIHelper.h"
24 #include "perfMonitor.h"
25 #include <list>
26 
27 namespace ndk_helper
28 {
29 
30 enum INTERPOLATOR_TYPE
31 {
32     INTERPOLATOR_TYPE_LINEAR,
33     INTERPOLATOR_TYPE_EASEINQUAD,
34     INTERPOLATOR_TYPE_EASEOUTQUAD,
35     INTERPOLATOR_TYPE_EASEINOUTQUAD,
36     INTERPOLATOR_TYPE_EASEINCUBIC,
37     INTERPOLATOR_TYPE_EASEOUTCUBIC,
38     INTERPOLATOR_TYPE_EASEINOUTCUBIC,
39     INTERPOLATOR_TYPE_EASEINQUART,
40     INTERPOLATOR_TYPE_EASEINEXPO,
41     INTERPOLATOR_TYPE_EASEOUTEXPO,
42 };
43 
44 struct InterpolatorParams
45 {
46     float dest_value_;
47     INTERPOLATOR_TYPE type_;
48     double duration_;
49 };
50 
51 /******************************************************************
52  * Interpolates values with several interpolation methods
53  */
54 class Interpolator
55 {
56 private:
57     double start_time_;
58     double dest_time_;
59     INTERPOLATOR_TYPE type_;
60 
61     float start_value_;
62     float dest_value_;
63     std::list<InterpolatorParams> list_params_;
64 
65     float GetFormula( const INTERPOLATOR_TYPE type,
66             const float t,
67             const float b,
68             const float d,
69             const float c );
70 public:
71     Interpolator();
72     ~Interpolator();
73 
74     Interpolator& Set( const float start,
75             const float dest,
76             const INTERPOLATOR_TYPE type,
77             double duration );
78 
79     Interpolator& Add( const float dest,
80             const INTERPOLATOR_TYPE type,
81             const double duration );
82 
83     bool Update( const double currentTime, float& p );
84 
85     void Clear();
86 };
87 
88 }   //namespace ndkHelper
89 #endif /* INTERPOLATOR_H_ */
90