Animator refactoring & fixes

 Tweaks animators to have less unnecessary refcounting

 Pull animator management out into seperate class

 More control to tweak animator lifecycle, such as doing
 Java-side handling of start delay by attaching but not
 starting the animator

Change-Id: I4ff8207580ca11fb38f45ef0007b406e0097281c
diff --git a/libs/hwui/Animator.h b/libs/hwui/Animator.h
index 6cb72c4c..a981b5a 100644
--- a/libs/hwui/Animator.h
+++ b/libs/hwui/Animator.h
@@ -50,12 +50,11 @@
     ANDROID_API void setListener(AnimationListener* listener) {
         mListener = listener;
     }
+    ANDROID_API void start() { mStagingPlayState = RUNNING; }
+    ANDROID_API void cancel() { mStagingPlayState = FINISHED; }
 
-    ANDROID_API virtual void onAttached(RenderNode* target) {}
-
-    // Guaranteed to happen before the staging push
-    void setupStartValueIfNecessary(RenderNode* target, TreeInfo& info);
-
+    virtual void onAttached(RenderNode* target) {}
+    virtual void pushStaging(RenderNode* target, TreeInfo& info);
     bool animate(RenderNode* target, TreeInfo& info);
 
     bool isFinished() { return mPlayState == FINISHED; }
@@ -73,8 +72,7 @@
     void callOnFinishedListener(TreeInfo& info);
 
     enum PlayState {
-        NEEDS_START,
-        PENDING,
+        NOT_STARTED,
         RUNNING,
         FINISHED,
     };
@@ -84,13 +82,19 @@
     float mFromValue;
 
     Interpolator* mInterpolator;
+    PlayState mStagingPlayState;
     PlayState mPlayState;
+    bool mHasStartValue;
     nsecs_t mStartTime;
-    nsecs_t mDelayUntil;
     nsecs_t mDuration;
     nsecs_t mStartDelay;
 
     sp<AnimationListener> mListener;
+
+private:
+    void doSetStartValue(float value);
+    inline void checkMutable();
+    void transitionToRunning(TreeInfo& info);
 };
 
 class RenderPropertyAnimator : public BaseRenderNodeAnimator {
@@ -112,7 +116,7 @@
 
     ANDROID_API RenderPropertyAnimator(RenderProperty property, float finalValue);
 
-    ANDROID_API virtual void onAttached(RenderNode* target);
+    virtual void onAttached(RenderNode* target);
 
     ANDROID_API virtual uint32_t dirtyMask();