diff options
author | Doris Liu <tianliu@google.com> | 2016-02-02 14:14:04 -0800 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2016-02-11 01:08:47 +0000 |
commit | 18bdf443e371e9f293439b4ff92cc79abaa422e5 (patch) | |
tree | 8e73638e5dbfe34df3a7184e04437c1c7283ed81 /libs/hwui/Animator.h | |
parent | 7f036f8bce5c2f70b2cbc5e252220909bba69b5d (diff) |
VectorDrawable native rendering - Step 5 of MANY
Implemented reset() (public API for AVD)
and reverse() (internal API that needs to be supported)
Change-Id: Ife1650049f271cad1347943151a5800c40c20aa2
Diffstat (limited to 'libs/hwui/Animator.h')
-rw-r--r-- | libs/hwui/Animator.h | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/libs/hwui/Animator.h b/libs/hwui/Animator.h index 2c9c9c3fe0f9..fcbc11b0306c 100644 --- a/libs/hwui/Animator.h +++ b/libs/hwui/Animator.h @@ -24,6 +24,8 @@ #include "utils/Macros.h" +#include <vector> + namespace android { namespace uirenderer { @@ -59,14 +61,14 @@ public: mMayRunAsync = mayRunAsync; } bool mayRunAsync() { return mMayRunAsync; } - ANDROID_API void start() { - if (mStagingPlayState == PlayState::NotStarted) { - mStagingPlayState = PlayState::Running; - } else { - mStagingPlayState = PlayState::Restarted; - } - onStagingPlayStateChanged(); } - ANDROID_API void end() { mStagingPlayState = PlayState::Finished; onStagingPlayStateChanged(); } + ANDROID_API void start(); + ANDROID_API void reset(); + ANDROID_API void reverse(); + // Terminates the animation at its current progress. + ANDROID_API void cancel(); + + // Terminates the animation and skip to the end of the animation. + ANDROID_API void end(); void attach(RenderNode* target); virtual void onAttached() {} @@ -74,36 +76,41 @@ public: void pushStaging(AnimationContext& context); bool animate(AnimationContext& context); - bool isRunning() { return mPlayState == PlayState::Running; } + bool isRunning() { return mPlayState == PlayState::Running + || mPlayState == PlayState::Reversing; } bool isFinished() { return mPlayState == PlayState::Finished; } float finalValue() { return mFinalValue; } ANDROID_API virtual uint32_t dirtyMask() = 0; void forceEndNow(AnimationContext& context); + RenderNode* target() { return mTarget; } protected: // PlayState is used by mStagingPlayState and mPlayState to track the state initiated from UI // thread and Render Thread animation state, respectively. // From the UI thread, mStagingPlayState transition looks like - // NotStarted -> Running -> Finished - // ^ | - // | | - // Restarted <------ + // NotStarted -> Running/Reversing -> Finished + // ^ | + // | | + // ---------------------- // Note: For mStagingState, the Finished state (optional) is only set when the animation is // terminated by user. // // On Render Thread, mPlayState transition: - // NotStart -> Running -> Finished - // ^ | - // | | - // ------------- + // NotStart -> Running/Reversing-> Finished + // ^ | + // | | + // ------------------ + // Note that if the animation is in Running/Reversing state, calling start or reverse again + // would do nothing if the animation has the same play direction as the request; otherwise, + // the animation would start from where it is and change direction (i.e. Reversing <-> Running) enum class PlayState { NotStarted, Running, + Reversing, Finished, - Restarted, }; BaseRenderNodeAnimator(float finalValue); @@ -111,7 +118,6 @@ protected: virtual float getValue(RenderNode* target) const = 0; virtual void setValue(RenderNode* target, float value) = 0; - RenderNode* target() { return mTarget; } void callOnFinishedListener(AnimationContext& context); @@ -132,13 +138,28 @@ protected: nsecs_t mDuration; nsecs_t mStartDelay; bool mMayRunAsync; + // Play Time tracks the progress of animation, it should always be [0, mDuration], 0 being + // the beginning of the animation, will reach mDuration at the end of an animation. + nsecs_t mPlayTime; sp<AnimationListener> mListener; private: + enum class Request { + Start, + Reverse, + Reset, + Cancel, + End + }; inline void checkMutable(); virtual void transitionToRunning(AnimationContext& context); void doSetStartValue(float value); + bool updatePlayTime(nsecs_t playTime); + void resolveStagingRequest(Request request); + + std::vector<Request> mStagingRequests; + }; class RenderPropertyAnimator : public BaseRenderNodeAnimator { |