Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: cc/animation/element_animations_unittest.cc

Issue 2291463003: Revert "CC Animation: Introduce some dirty flags to optimize PushProperties on commit" (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/element_animations.cc ('k') | cc/animation/scroll_offset_animations.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/animation/element_animations.h" 5 #include "cc/animation/element_animations.h"
6 6
7 #include "cc/animation/animation_delegate.h" 7 #include "cc/animation/animation_delegate.h"
8 #include "cc/animation/animation_host.h" 8 #include "cc/animation/animation_host.h"
9 #include "cc/animation/animation_id_provider.h" 9 #include "cc/animation/animation_id_provider.h"
10 #include "cc/animation/animation_player.h" 10 #include "cc/animation/animation_player.h"
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 658
659 scoped_refptr<ElementAnimations> animations = element_animations(); 659 scoped_refptr<ElementAnimations> animations = element_animations();
660 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); 660 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
661 661
662 auto events = host_impl_->CreateEvents(); 662 auto events = host_impl_->CreateEvents();
663 663
664 AddOpacityTransitionToElementAnimations(animations.get(), 1.0, 0.0f, 1.0f, 664 AddOpacityTransitionToElementAnimations(animations.get(), 1.0, 0.0f, 1.0f,
665 false); 665 false);
666 animations->Animate(kInitialTickTime); 666 animations->Animate(kInitialTickTime);
667 animations->UpdateState(true, nullptr); 667 animations->UpdateState(true, nullptr);
668 EXPECT_TRUE(animations->needs_push_properties());
669 animations->PushPropertiesTo(animations_impl.get()); 668 animations->PushPropertiesTo(animations_impl.get());
670 animations_impl->ActivateAnimations(); 669 animations_impl->ActivateAnimations();
671 670
672 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 671 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
673 animations_impl->UpdateState(true, events.get()); 672 animations_impl->UpdateState(true, events.get());
674 673
675 // There should be a STARTED event for the animation. 674 // There should be a STARTED event for the animation.
676 EXPECT_EQ(1u, events->events_.size()); 675 EXPECT_EQ(1u, events->events_.size());
677 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 676 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
678 animations->NotifyAnimationStarted(events->events_[0]); 677 animations->NotifyAnimationStarted(events->events_[0]);
679 678
680 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 679 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
681 animations->UpdateState(true, nullptr); 680 animations->UpdateState(true, nullptr);
682 681
683 EXPECT_FALSE(host_->needs_push_properties()); 682 EXPECT_FALSE(host_->animation_waiting_for_deletion());
684 EXPECT_FALSE(host_impl_->needs_push_properties()); 683 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion());
685 684
686 events = host_impl_->CreateEvents(); 685 events = host_impl_->CreateEvents();
687 animations_impl->Animate(kInitialTickTime + 686 animations_impl->Animate(kInitialTickTime +
688 TimeDelta::FromMilliseconds(2000)); 687 TimeDelta::FromMilliseconds(2000));
689 animations_impl->UpdateState(true, events.get()); 688 animations_impl->UpdateState(true, events.get());
690 689
691 EXPECT_TRUE(host_impl_->needs_push_properties()); 690 EXPECT_TRUE(host_impl_->animation_waiting_for_deletion());
692 691
693 // There should be a FINISHED event for the animation. 692 // There should be a FINISHED event for the animation.
694 EXPECT_EQ(1u, events->events_.size()); 693 EXPECT_EQ(1u, events->events_.size());
695 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 694 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
696 695
697 // Neither animations should have deleted the animation yet. 696 // Neither animations should have deleted the animation yet.
698 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); 697 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY));
699 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::OPACITY)); 698 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::OPACITY));
700 699
701 animations->NotifyAnimationFinished(events->events_[0]); 700 animations->NotifyAnimationFinished(events->events_[0]);
702 701
703 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); 702 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
704 animations->UpdateState(true, nullptr); 703 animations->UpdateState(true, nullptr);
705 EXPECT_TRUE(host_->needs_push_properties()); 704 EXPECT_TRUE(host_->animation_waiting_for_deletion());
706 705
707 animations->PushPropertiesTo(animations_impl.get()); 706 animations->PushPropertiesTo(animations_impl.get());
708 707
709 // Both animationss should now have deleted the animation. The impl animations 708 // Both animationss should now have deleted the animation. The impl animations
710 // should have deleted the animation even though activation has not occurred, 709 // should have deleted the animation even though activation has not occurred,
711 // since the animation was already waiting for deletion when 710 // since the animation was already waiting for deletion when
712 // PushPropertiesTo was called. 711 // PushPropertiesTo was called.
713 EXPECT_FALSE(animations->has_any_animation()); 712 EXPECT_FALSE(animations->has_any_animation());
714 EXPECT_FALSE(animations_impl->has_any_animation()); 713 EXPECT_FALSE(animations_impl->has_any_animation());
715 } 714 }
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 animations->AddAnimation(std::move(to_add)); 1680 animations->AddAnimation(std::move(to_add));
1682 1681
1683 animations->Animate(kInitialTickTime); 1682 animations->Animate(kInitialTickTime);
1684 animations->UpdateState(true, events.get()); 1683 animations->UpdateState(true, events.get());
1685 EXPECT_TRUE(animations->HasActiveAnimation()); 1684 EXPECT_TRUE(animations->HasActiveAnimation());
1686 Animation* active_animation = 1685 Animation* active_animation =
1687 animations->GetAnimation(TargetProperty::OPACITY); 1686 animations->GetAnimation(TargetProperty::OPACITY);
1688 EXPECT_TRUE(active_animation); 1687 EXPECT_TRUE(active_animation);
1689 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 1688 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1690 1689
1691 EXPECT_TRUE(animations->needs_push_properties());
1692 animations->PushPropertiesTo(animations_impl.get()); 1690 animations->PushPropertiesTo(animations_impl.get());
1693 animations_impl->ActivateAnimations(); 1691 animations_impl->ActivateAnimations();
1694 1692
1695 active_animation = animations_impl->GetAnimation(TargetProperty::OPACITY); 1693 active_animation = animations_impl->GetAnimation(TargetProperty::OPACITY);
1696 EXPECT_TRUE(active_animation); 1694 EXPECT_TRUE(active_animation);
1697 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1695 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1698 active_animation->run_state()); 1696 active_animation->run_state());
1699 } 1697 }
1700 1698
1701 // Tests that skipping a call to UpdateState works as expected. 1699 // Tests that skipping a call to UpdateState works as expected.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 int animation_id = AddOpacityTransitionToElementAnimations( 1943 int animation_id = AddOpacityTransitionToElementAnimations(
1946 animations.get(), 1.0, 0.f, 1.f, false); 1944 animations.get(), 1.0, 0.f, 1.f, false);
1947 1945
1948 animations->PushPropertiesTo(animations_impl.get()); 1946 animations->PushPropertiesTo(animations_impl.get());
1949 animations_impl->ActivateAnimations(); 1947 animations_impl->ActivateAnimations();
1950 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); 1948 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id));
1951 1949
1952 animations->AbortAnimations(TargetProperty::OPACITY); 1950 animations->AbortAnimations(TargetProperty::OPACITY);
1953 EXPECT_EQ(Animation::ABORTED, 1951 EXPECT_EQ(Animation::ABORTED,
1954 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 1952 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
1955 EXPECT_FALSE(host_->needs_push_properties()); 1953 EXPECT_FALSE(host_->animation_waiting_for_deletion());
1956 EXPECT_FALSE(host_impl_->needs_push_properties()); 1954 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion());
1957 1955
1958 animations->Animate(kInitialTickTime); 1956 animations->Animate(kInitialTickTime);
1959 animations->UpdateState(true, nullptr); 1957 animations->UpdateState(true, nullptr);
1960 EXPECT_FALSE(host_->needs_push_properties()); 1958 EXPECT_FALSE(host_->animation_waiting_for_deletion());
1961 EXPECT_EQ(Animation::ABORTED, 1959 EXPECT_EQ(Animation::ABORTED,
1962 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 1960 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
1963 1961
1964 EXPECT_TRUE(animations->needs_push_properties());
1965 animations->PushPropertiesTo(animations_impl.get()); 1962 animations->PushPropertiesTo(animations_impl.get());
1966 EXPECT_FALSE(animations->GetAnimationById(animation_id)); 1963 EXPECT_FALSE(animations->GetAnimationById(animation_id));
1967 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); 1964 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id));
1968 } 1965 }
1969 1966
1970 // An animation aborted on the impl thread should get deleted on both threads. 1967 // An animation aborted on the impl thread should get deleted on both threads.
1971 TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) { 1968 TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) {
1972 CreateTestLayer(true, false); 1969 CreateTestLayer(true, false);
1973 AttachTimelinePlayerLayer(); 1970 AttachTimelinePlayerLayer();
1974 CreateImplTimelineAndPlayer(); 1971 CreateImplTimelineAndPlayer();
1975 1972
1976 scoped_refptr<ElementAnimations> animations = element_animations(); 1973 scoped_refptr<ElementAnimations> animations = element_animations();
1977 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); 1974 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
1978 1975
1979 TestAnimationDelegate delegate; 1976 TestAnimationDelegate delegate;
1980 player_->set_animation_delegate(&delegate); 1977 player_->set_animation_delegate(&delegate);
1981 1978
1982 int animation_id = AddOpacityTransitionToElementAnimations( 1979 int animation_id = AddOpacityTransitionToElementAnimations(
1983 animations.get(), 1.0, 0.f, 1.f, false); 1980 animations.get(), 1.0, 0.f, 1.f, false);
1984 1981
1985 animations->PushPropertiesTo(animations_impl.get()); 1982 animations->PushPropertiesTo(animations_impl.get());
1986 animations_impl->ActivateAnimations(); 1983 animations_impl->ActivateAnimations();
1987 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); 1984 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id));
1988 1985
1989 animations_impl->AbortAnimations(TargetProperty::OPACITY); 1986 animations_impl->AbortAnimations(TargetProperty::OPACITY);
1990 EXPECT_EQ( 1987 EXPECT_EQ(
1991 Animation::ABORTED, 1988 Animation::ABORTED,
1992 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); 1989 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state());
1993 EXPECT_FALSE(host_->needs_push_properties()); 1990 EXPECT_FALSE(host_->animation_waiting_for_deletion());
1994 EXPECT_FALSE(host_impl_->needs_push_properties()); 1991 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion());
1995 1992
1996 auto events = host_impl_->CreateEvents(); 1993 auto events = host_impl_->CreateEvents();
1997 animations_impl->Animate(kInitialTickTime); 1994 animations_impl->Animate(kInitialTickTime);
1998 animations_impl->UpdateState(true, events.get()); 1995 animations_impl->UpdateState(true, events.get());
1999 EXPECT_TRUE(host_impl_->needs_push_properties()); 1996 EXPECT_TRUE(host_impl_->animation_waiting_for_deletion());
2000 EXPECT_EQ(1u, events->events_.size()); 1997 EXPECT_EQ(1u, events->events_.size());
2001 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type); 1998 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type);
2002 EXPECT_EQ( 1999 EXPECT_EQ(
2003 Animation::WAITING_FOR_DELETION, 2000 Animation::WAITING_FOR_DELETION,
2004 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); 2001 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state());
2005 2002
2006 animations->NotifyAnimationAborted(events->events_[0]); 2003 animations->NotifyAnimationAborted(events->events_[0]);
2007 EXPECT_EQ(Animation::ABORTED, 2004 EXPECT_EQ(Animation::ABORTED,
2008 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 2005 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
2009 EXPECT_TRUE(delegate.aborted()); 2006 EXPECT_TRUE(delegate.aborted());
2010 2007
2011 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 2008 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2012 animations->UpdateState(true, nullptr); 2009 animations->UpdateState(true, nullptr);
2013 EXPECT_TRUE(host_->needs_push_properties()); 2010 EXPECT_TRUE(host_->animation_waiting_for_deletion());
2014 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 2011 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
2015 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 2012 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
2016 2013
2017 animations->PushPropertiesTo(animations_impl.get()); 2014 animations->PushPropertiesTo(animations_impl.get());
2018 animations_impl->ActivateAnimations(); 2015 animations_impl->ActivateAnimations();
2019 EXPECT_FALSE(animations->GetAnimationById(animation_id)); 2016 EXPECT_FALSE(animations->GetAnimationById(animation_id));
2020 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); 2017 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id));
2021 } 2018 }
2022 2019
2023 // Test that an impl-only scroll offset animation that needs to be completed on 2020 // Test that an impl-only scroll offset animation that needs to be completed on
(...skipping 29 matching lines...) Expand all
2053 animations->PushPropertiesTo(animations_impl.get()); 2050 animations->PushPropertiesTo(animations_impl.get());
2054 animations_impl->ActivateAnimations(); 2051 animations_impl->ActivateAnimations();
2055 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); 2052 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id));
2056 2053
2057 const bool needs_completion = true; 2054 const bool needs_completion = true;
2058 animations_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET, 2055 animations_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET,
2059 needs_completion); 2056 needs_completion);
2060 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION, 2057 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION,
2061 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) 2058 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
2062 ->run_state()); 2059 ->run_state());
2063 EXPECT_FALSE(host_->needs_push_properties()); 2060 EXPECT_FALSE(host_->animation_waiting_for_deletion());
2064 EXPECT_FALSE(host_impl_->needs_push_properties()); 2061 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion());
2065 2062
2066 auto events = host_impl_->CreateEvents(); 2063 auto events = host_impl_->CreateEvents();
2067 animations_impl->Animate(kInitialTickTime); 2064 animations_impl->Animate(kInitialTickTime);
2068 animations_impl->UpdateState(true, events.get()); 2065 animations_impl->UpdateState(true, events.get());
2069 EXPECT_TRUE(delegate_impl.finished()); 2066 EXPECT_TRUE(delegate_impl.finished());
2070 EXPECT_TRUE(host_impl_->needs_push_properties()); 2067 EXPECT_TRUE(host_impl_->animation_waiting_for_deletion());
2071 EXPECT_EQ(1u, events->events_.size()); 2068 EXPECT_EQ(1u, events->events_.size());
2072 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type); 2069 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type);
2073 EXPECT_EQ(123, events->events_[0].animation_start_time); 2070 EXPECT_EQ(123, events->events_[0].animation_start_time);
2074 EXPECT_EQ( 2071 EXPECT_EQ(
2075 target_value, 2072 target_value,
2076 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); 2073 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value());
2077 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 2074 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
2078 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) 2075 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
2079 ->run_state()); 2076 ->run_state());
2080 2077
2081 // MT receives the event to take over.
2082 animations->NotifyAnimationTakeover(events->events_[0]); 2078 animations->NotifyAnimationTakeover(events->events_[0]);
2083 EXPECT_TRUE(delegate.takeover()); 2079 EXPECT_TRUE(delegate.takeover());
2084 2080
2085 // AnimationPlayer::NotifyAnimationTakeover requests SetNeedsPushProperties
2086 // to purge CT animations marked for deletion.
2087 EXPECT_TRUE(animations->needs_push_properties());
2088
2089 // ElementAnimations::PurgeAnimationsMarkedForDeletion call happens only in
2090 // ElementAnimations::PushPropertiesTo.
2091 animations->PushPropertiesTo(animations_impl.get()); 2081 animations->PushPropertiesTo(animations_impl.get());
2092 animations_impl->ActivateAnimations(); 2082 animations_impl->ActivateAnimations();
2093 EXPECT_FALSE(animations->GetAnimationById(animation_id)); 2083 EXPECT_FALSE(animations->GetAnimationById(animation_id));
2094 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); 2084 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id));
2095 } 2085 }
2096 2086
2097 // Ensure that we only generate FINISHED events for animations in a group 2087 // Ensure that we only generate FINISHED events for animations in a group
2098 // once all animations in that group are finished. 2088 // once all animations in that group are finished.
2099 TEST_F(ElementAnimationsTest, FinishedEventsForGroup) { 2089 TEST_F(ElementAnimationsTest, FinishedEventsForGroup) {
2100 CreateTestLayer(true, false); 2090 CreateTestLayer(true, false);
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after
3745 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( 3735 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty(
3746 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3736 TargetProperty::OPACITY, ElementListType::ACTIVE));
3747 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3737 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3748 TargetProperty::OPACITY, ElementListType::PENDING)); 3738 TargetProperty::OPACITY, ElementListType::PENDING));
3749 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3739 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3750 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3740 TargetProperty::OPACITY, ElementListType::ACTIVE));
3751 } 3741 }
3752 3742
3753 } // namespace 3743 } // namespace
3754 } // namespace cc 3744 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/element_animations.cc ('k') | cc/animation/scroll_offset_animations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698