OSDN Git Service

Support AVD animation falling back on UI thread
authorDoris Liu <tianliu@google.com>
Thu, 16 Jun 2016 02:04:36 +0000 (19:04 -0700)
committerDoris Liu <tianliu@google.com>
Thu, 16 Jun 2016 22:09:44 +0000 (22:09 +0000)
AVD will fall back to UI thread animation if the host view is
rendering onto a SW layer.

BUG: 27617346
Change-Id: I5b644529048a0c30aada3abf2f4e95e40760936d

graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java

index 6bb93ae..0bdc76f 100644 (file)
@@ -239,6 +239,17 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
 
     @Override
     public void draw(Canvas canvas) {
+        if (!canvas.isHardwareAccelerated() && mAnimatorSet instanceof VectorDrawableAnimatorRT) {
+            // If we have SW canvas and the RT animation is waiting to start, We need to fallback
+            // to UI thread animation for AVD.
+            if (!mAnimatorSet.isRunning() &&
+                    ((VectorDrawableAnimatorRT) mAnimatorSet).mPendingAnimationActions.size() > 0) {
+                VectorDrawableAnimatorRT oldAnim = (VectorDrawableAnimatorRT) mAnimatorSet;
+                mAnimatorSet = new VectorDrawableAnimatorUI(this);
+                mAnimatorSet.init(mAnimatorSetFromXml);
+                oldAnim.transferPendingActions(mAnimatorSet);
+            }
+        }
         mAnimatorSet.onDraw(canvas);
         mAnimatedVectorState.mVectorDrawable.draw(canvas);
     }
@@ -1590,6 +1601,25 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
         private static void callOnFinished(VectorDrawableAnimatorRT set, int id) {
             set.onAnimationEnd(id);
         }
+
+        private void transferPendingActions(VectorDrawableAnimator animatorSet) {
+            for (int i = 0; i < mPendingAnimationActions.size(); i++) {
+                int pendingAction = mPendingAnimationActions.get(i);
+                if (pendingAction == START_ANIMATION) {
+                    animatorSet.start();
+                } else if (pendingAction == END_ANIMATION) {
+                    animatorSet.end();
+                } else if (pendingAction == REVERSE_ANIMATION) {
+                    animatorSet.reverse();
+                } else if (pendingAction == RESET_ANIMATION) {
+                    animatorSet.reset();
+                } else {
+                    throw new UnsupportedOperationException("Animation action " +
+                            pendingAction + "is not supported");
+                }
+            }
+            mPendingAnimationActions.clear();
+        }
     }
 
     private static native long nCreateAnimatorSet();