From c82e879e563ad692cabf19f61a08559c6220171e Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Fri, 29 Jul 2016 16:45:24 -0700 Subject: [PATCH] Put VD animators on paused list when RT stops drawing When we stop scheduling for new frames on RenderThread, we should put the running animations on pause, rather than purge the list of the running animations, such that in the next full sync, the animations that were paused will continue to run. BUG: 30226711 Change-Id: I36ff6f5d26ffa7999f60ca0ff676a35157577dc2 --- core/jni/android_view_ThreadedRenderer.cpp | 16 +++++++++++++--- libs/hwui/AnimationContext.h | 2 +- libs/hwui/renderthread/CanvasContext.cpp | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 3669da8a9cd8a..7cd0d2a3e8884 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -242,6 +242,16 @@ public: mPausedVDAnimators.clear(); } + // Move all the animators to the paused list, and send a delayed message to notify the finished + // listener. + void pauseAnimators() { + mPausedVDAnimators.insert(mRunningVDAnimators.begin(), mRunningVDAnimators.end()); + for (auto& anim : mRunningVDAnimators) { + detachVectorDrawableAnimator(anim.get()); + } + mRunningVDAnimators.clear(); + } + void doAttachAnimatingNodes(AnimationContext* context) { for (size_t i = 0; i < mPendingAnimatingRenderNodes.size(); i++) { RenderNode* node = mPendingAnimatingRenderNodes[i].get(); @@ -415,8 +425,8 @@ public: postOnFinishedEvents(); } - virtual void detachAnimators() override { - mRootNode->detachAnimators(); + virtual void pauseAnimators() override { + mRootNode->pauseAnimators(); } virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) { @@ -426,7 +436,7 @@ public: virtual void destroy() { AnimationContext::destroy(); - detachAnimators(); + mRootNode->detachAnimators(); postOnFinishedEvents(); } diff --git a/libs/hwui/AnimationContext.h b/libs/hwui/AnimationContext.h index 801fd8719a142..11d305c3c8d0c 100644 --- a/libs/hwui/AnimationContext.h +++ b/libs/hwui/AnimationContext.h @@ -100,7 +100,7 @@ public: ANDROID_API virtual void destroy(); - ANDROID_API virtual void detachAnimators() {} + ANDROID_API virtual void pauseAnimators() {} private: friend class AnimationHandle; diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index d68f0e383152d..30920a75210c7 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -326,7 +326,7 @@ void CanvasContext::prepareTree(TreeInfo& info, int64_t* uiFrameInfo, void CanvasContext::stopDrawing() { mRenderThread.removeFrameCallback(this); - mAnimationContext->detachAnimators(); + mAnimationContext->pauseAnimators(); } void CanvasContext::notifyFramePending() {