John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 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 ANIMATOR_H |
| 17 | #define ANIMATOR_H |
| 18 | |
| 19 | #include <cutils/compiler.h> |
| 20 | |
| 21 | #include "Interpolator.h" |
| 22 | #include "TreeInfo.h" |
| 23 | #include "utils/VirtualLightRefBase.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | class RenderProperties; |
| 29 | class RenderPropertyAnimatorImpl; |
| 30 | |
| 31 | class RenderPropertyAnimator : public VirtualLightRefBase { |
| 32 | public: |
| 33 | // Since the UI thread doesn't necessarily know what the current values |
| 34 | // actually are and thus can't do the calculations, this is used to inform |
| 35 | // the animator how to lazy-resolve the input value |
| 36 | enum DeltaValueType { |
| 37 | // The delta value represents an absolute value endpoint |
| 38 | // mDeltaValue needs to be recalculated to be mDelta = (mDelta - fromValue) |
| 39 | // in onAnimationStarted() |
| 40 | ABSOLUTE = 0, |
| 41 | // The final value represents an offset from the current value |
| 42 | // No recalculation is needed |
| 43 | DELTA, |
| 44 | }; |
| 45 | |
| 46 | enum RenderProperty { |
| 47 | TRANSLATION_X = 0, |
| 48 | TRANSLATION_Y, |
| 49 | TRANSLATION_Z, |
| 50 | SCALE_X, |
| 51 | SCALE_Y, |
| 52 | ROTATION, |
| 53 | ROTATION_X, |
| 54 | ROTATION_Y, |
| 55 | X, |
| 56 | Y, |
| 57 | Z, |
| 58 | ALPHA, |
| 59 | }; |
| 60 | |
| 61 | ANDROID_API void setInterpolator(Interpolator* interpolator); |
| 62 | ANDROID_API void setDuration(nsecs_t durationInMs); |
| 63 | ANDROID_API bool isFinished(); |
| 64 | |
| 65 | bool animate(RenderProperties* target, TreeInfo& info); |
| 66 | |
| 67 | protected: |
| 68 | ANDROID_API RenderPropertyAnimator(RenderProperty property, DeltaValueType deltaType, |
| 69 | float deltaValue); |
| 70 | ANDROID_API virtual ~RenderPropertyAnimator(); |
| 71 | |
| 72 | private: |
| 73 | RenderPropertyAnimatorImpl* mImpl; |
| 74 | }; |
| 75 | |
| 76 | } /* namespace uirenderer */ |
| 77 | } /* namespace android */ |
| 78 | |
| 79 | #endif /* ANIMATOR_H */ |