Revert "Revert "Check RenderNode's owning view before attaching animators""
This reverts commit eb40178af3b7c8d925eaf6c1aa0bef739c8ea47e.
Change-Id: I6838ecb35b50847746ee66ac204f14eb5f579b91
diff --git a/libs/hwui/AnimatorManager.cpp b/libs/hwui/AnimatorManager.cpp
index 2b49b47..2198fcc 100644
--- a/libs/hwui/AnimatorManager.cpp
+++ b/libs/hwui/AnimatorManager.cpp
@@ -42,7 +42,23 @@
}
void AnimatorManager::addAnimator(const sp<BaseRenderNodeAnimator>& animator) {
+ RenderNode* stagingTarget = animator->stagingTarget();
+ if (stagingTarget == &mParent) {
+ return;
+ }
mNewAnimators.emplace_back(animator.get());
+ // If the animator is already attached to other RenderNode, remove it from that RenderNode's
+ // new animator list. This ensures one animator only ends up in one newAnimatorList during one
+ // frame, even when it's added multiple times to multiple targets.
+ if (stagingTarget) {
+ stagingTarget->removeAnimator(animator);
+ }
+ animator->attach(&mParent);
+}
+
+void AnimatorManager::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) {
+ mNewAnimators.erase(std::remove(mNewAnimators.begin(), mNewAnimators.end(), animator),
+ mNewAnimators.end());
}
void AnimatorManager::setAnimationHandle(AnimationHandle* handle) {
@@ -58,21 +74,12 @@
LOG_ALWAYS_FATAL_IF(!mAnimationHandle,
"Trying to start new animators on %p (%s) without an animation handle!",
&mParent, mParent.getName());
- // Only add animators that are not already in the on-going animator list.
- for (auto& animator : mNewAnimators) {
- RenderNode* targetRenderNode = animator->target();
- if (targetRenderNode == &mParent) {
- // Animator already in the animator list: skip adding again
- continue;
- }
- if (targetRenderNode){
- // If the animator is already in another RenderNode's animator list, remove animator from
- // that list and add animator to current RenderNode's list.
- targetRenderNode->animators().removeActiveAnimator(animator);
+ // Only add new animators that are not already in the mAnimators list
+ for (auto& anim : mNewAnimators) {
+ if (anim->target() != &mParent) {
+ mAnimators.push_back(std::move(anim));
}
- animator->attach(&mParent);
- mAnimators.push_back(std::move(animator));
}
mNewAnimators.clear();
}
@@ -81,6 +88,11 @@
}
}
+void AnimatorManager::onAnimatorTargetChanged(BaseRenderNodeAnimator* animator) {
+ LOG_ALWAYS_FATAL_IF(animator->target() == &mParent, "Target has not been changed");
+ mAnimators.erase(std::remove(mAnimators.begin(), mAnimators.end(), animator), mAnimators.end());
+}
+
class AnimateFunctor {
public:
AnimateFunctor(TreeInfo& info, AnimationContext& context)
@@ -154,10 +166,6 @@
mNewAnimators.clear();
}
-void AnimatorManager::removeActiveAnimator(const sp<BaseRenderNodeAnimator>& animator) {
- std::remove(mAnimators.begin(), mAnimators.end(), animator);
-}
-
class EndActiveAnimatorsFunctor {
public:
EndActiveAnimatorsFunctor(AnimationContext& context) : mContext(context) {}