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

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

Issue 2261113002: CC Animation: Introduce some dirty flags to optimize PushProperties on commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not change SetNeedsCommit invalidation, leave it as-is. 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());
668 animations->PushPropertiesTo(animations_impl.get()); 669 animations->PushPropertiesTo(animations_impl.get());
669 animations_impl->ActivateAnimations(); 670 animations_impl->ActivateAnimations();
670 671
671 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 672 animations_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
672 animations_impl->UpdateState(true, events.get()); 673 animations_impl->UpdateState(true, events.get());
673 674
674 // There should be a STARTED event for the animation. 675 // There should be a STARTED event for the animation.
675 EXPECT_EQ(1u, events->events_.size()); 676 EXPECT_EQ(1u, events->events_.size());
676 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type); 677 EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
677 animations->NotifyAnimationStarted(events->events_[0]); 678 animations->NotifyAnimationStarted(events->events_[0]);
678 679
679 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 680 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
680 animations->UpdateState(true, nullptr); 681 animations->UpdateState(true, nullptr);
681 682
682 EXPECT_FALSE(host_->animation_waiting_for_deletion()); 683 EXPECT_FALSE(host_->needs_push_properties());
683 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion()); 684 EXPECT_FALSE(host_impl_->needs_push_properties());
684 685
685 events = host_impl_->CreateEvents(); 686 events = host_impl_->CreateEvents();
686 animations_impl->Animate(kInitialTickTime + 687 animations_impl->Animate(kInitialTickTime +
687 TimeDelta::FromMilliseconds(2000)); 688 TimeDelta::FromMilliseconds(2000));
688 animations_impl->UpdateState(true, events.get()); 689 animations_impl->UpdateState(true, events.get());
689 690
690 EXPECT_TRUE(host_impl_->animation_waiting_for_deletion()); 691 EXPECT_TRUE(host_impl_->needs_push_properties());
691 692
692 // There should be a FINISHED event for the animation. 693 // There should be a FINISHED event for the animation.
693 EXPECT_EQ(1u, events->events_.size()); 694 EXPECT_EQ(1u, events->events_.size());
694 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type); 695 EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
695 696
696 // Neither animations should have deleted the animation yet. 697 // Neither animations should have deleted the animation yet.
697 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY)); 698 EXPECT_TRUE(animations->GetAnimation(TargetProperty::OPACITY));
698 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::OPACITY)); 699 EXPECT_TRUE(animations_impl->GetAnimation(TargetProperty::OPACITY));
699 700
700 animations->NotifyAnimationFinished(events->events_[0]); 701 animations->NotifyAnimationFinished(events->events_[0]);
701 702
702 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); 703 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
703 animations->UpdateState(true, nullptr); 704 animations->UpdateState(true, nullptr);
704 EXPECT_TRUE(host_->animation_waiting_for_deletion()); 705 EXPECT_TRUE(host_->needs_push_properties());
705 706
706 animations->PushPropertiesTo(animations_impl.get()); 707 animations->PushPropertiesTo(animations_impl.get());
707 708
708 // Both animationss should now have deleted the animation. The impl animations 709 // Both animationss should now have deleted the animation. The impl animations
709 // should have deleted the animation even though activation has not occurred, 710 // should have deleted the animation even though activation has not occurred,
710 // since the animation was already waiting for deletion when 711 // since the animation was already waiting for deletion when
711 // PushPropertiesTo was called. 712 // PushPropertiesTo was called.
712 EXPECT_FALSE(animations->has_any_animation()); 713 EXPECT_FALSE(animations->has_any_animation());
713 EXPECT_FALSE(animations_impl->has_any_animation()); 714 EXPECT_FALSE(animations_impl->has_any_animation());
714 } 715 }
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 animations->AddAnimation(std::move(to_add)); 1681 animations->AddAnimation(std::move(to_add));
1681 1682
1682 animations->Animate(kInitialTickTime); 1683 animations->Animate(kInitialTickTime);
1683 animations->UpdateState(true, events.get()); 1684 animations->UpdateState(true, events.get());
1684 EXPECT_TRUE(animations->HasActiveAnimation()); 1685 EXPECT_TRUE(animations->HasActiveAnimation());
1685 Animation* active_animation = 1686 Animation* active_animation =
1686 animations->GetAnimation(TargetProperty::OPACITY); 1687 animations->GetAnimation(TargetProperty::OPACITY);
1687 EXPECT_TRUE(active_animation); 1688 EXPECT_TRUE(active_animation);
1688 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 1689 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1689 1690
1691 EXPECT_TRUE(animations->needs_push_properties());
1690 animations->PushPropertiesTo(animations_impl.get()); 1692 animations->PushPropertiesTo(animations_impl.get());
1691 animations_impl->ActivateAnimations(); 1693 animations_impl->ActivateAnimations();
1692 1694
1693 active_animation = animations_impl->GetAnimation(TargetProperty::OPACITY); 1695 active_animation = animations_impl->GetAnimation(TargetProperty::OPACITY);
1694 EXPECT_TRUE(active_animation); 1696 EXPECT_TRUE(active_animation);
1695 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, 1697 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1696 active_animation->run_state()); 1698 active_animation->run_state());
1697 } 1699 }
1698 1700
1699 // Tests that skipping a call to UpdateState works as expected. 1701 // Tests that skipping a call to UpdateState works as expected.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 int animation_id = AddOpacityTransitionToElementAnimations( 1945 int animation_id = AddOpacityTransitionToElementAnimations(
1944 animations.get(), 1.0, 0.f, 1.f, false); 1946 animations.get(), 1.0, 0.f, 1.f, false);
1945 1947
1946 animations->PushPropertiesTo(animations_impl.get()); 1948 animations->PushPropertiesTo(animations_impl.get());
1947 animations_impl->ActivateAnimations(); 1949 animations_impl->ActivateAnimations();
1948 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); 1950 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id));
1949 1951
1950 animations->AbortAnimations(TargetProperty::OPACITY); 1952 animations->AbortAnimations(TargetProperty::OPACITY);
1951 EXPECT_EQ(Animation::ABORTED, 1953 EXPECT_EQ(Animation::ABORTED,
1952 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 1954 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
1953 EXPECT_FALSE(host_->animation_waiting_for_deletion()); 1955 EXPECT_FALSE(host_->needs_push_properties());
1954 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion()); 1956 EXPECT_FALSE(host_impl_->needs_push_properties());
1955 1957
1956 animations->Animate(kInitialTickTime); 1958 animations->Animate(kInitialTickTime);
1957 animations->UpdateState(true, nullptr); 1959 animations->UpdateState(true, nullptr);
1958 EXPECT_FALSE(host_->animation_waiting_for_deletion()); 1960 EXPECT_FALSE(host_->needs_push_properties());
1959 EXPECT_EQ(Animation::ABORTED, 1961 EXPECT_EQ(Animation::ABORTED,
1960 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 1962 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
1961 1963
1964 EXPECT_TRUE(animations->needs_push_properties());
1962 animations->PushPropertiesTo(animations_impl.get()); 1965 animations->PushPropertiesTo(animations_impl.get());
1963 EXPECT_FALSE(animations->GetAnimationById(animation_id)); 1966 EXPECT_FALSE(animations->GetAnimationById(animation_id));
1964 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); 1967 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id));
1965 } 1968 }
1966 1969
1967 // An animation aborted on the impl thread should get deleted on both threads. 1970 // An animation aborted on the impl thread should get deleted on both threads.
1968 TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) { 1971 TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) {
1969 CreateTestLayer(true, false); 1972 CreateTestLayer(true, false);
1970 AttachTimelinePlayerLayer(); 1973 AttachTimelinePlayerLayer();
1971 CreateImplTimelineAndPlayer(); 1974 CreateImplTimelineAndPlayer();
1972 1975
1973 scoped_refptr<ElementAnimations> animations = element_animations(); 1976 scoped_refptr<ElementAnimations> animations = element_animations();
1974 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); 1977 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl();
1975 1978
1976 TestAnimationDelegate delegate; 1979 TestAnimationDelegate delegate;
1977 player_->set_animation_delegate(&delegate); 1980 player_->set_animation_delegate(&delegate);
1978 1981
1979 int animation_id = AddOpacityTransitionToElementAnimations( 1982 int animation_id = AddOpacityTransitionToElementAnimations(
1980 animations.get(), 1.0, 0.f, 1.f, false); 1983 animations.get(), 1.0, 0.f, 1.f, false);
1981 1984
1982 animations->PushPropertiesTo(animations_impl.get()); 1985 animations->PushPropertiesTo(animations_impl.get());
1983 animations_impl->ActivateAnimations(); 1986 animations_impl->ActivateAnimations();
1984 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); 1987 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id));
1985 1988
1986 animations_impl->AbortAnimations(TargetProperty::OPACITY); 1989 animations_impl->AbortAnimations(TargetProperty::OPACITY);
1987 EXPECT_EQ( 1990 EXPECT_EQ(
1988 Animation::ABORTED, 1991 Animation::ABORTED,
1989 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); 1992 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state());
1990 EXPECT_FALSE(host_->animation_waiting_for_deletion()); 1993 EXPECT_FALSE(host_->needs_push_properties());
1991 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion()); 1994 EXPECT_FALSE(host_impl_->needs_push_properties());
1992 1995
1993 auto events = host_impl_->CreateEvents(); 1996 auto events = host_impl_->CreateEvents();
1994 animations_impl->Animate(kInitialTickTime); 1997 animations_impl->Animate(kInitialTickTime);
1995 animations_impl->UpdateState(true, events.get()); 1998 animations_impl->UpdateState(true, events.get());
1996 EXPECT_TRUE(host_impl_->animation_waiting_for_deletion()); 1999 EXPECT_TRUE(host_impl_->needs_push_properties());
1997 EXPECT_EQ(1u, events->events_.size()); 2000 EXPECT_EQ(1u, events->events_.size());
1998 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type); 2001 EXPECT_EQ(AnimationEvent::ABORTED, events->events_[0].type);
1999 EXPECT_EQ( 2002 EXPECT_EQ(
2000 Animation::WAITING_FOR_DELETION, 2003 Animation::WAITING_FOR_DELETION,
2001 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); 2004 animations_impl->GetAnimation(TargetProperty::OPACITY)->run_state());
2002 2005
2003 animations->NotifyAnimationAborted(events->events_[0]); 2006 animations->NotifyAnimationAborted(events->events_[0]);
2004 EXPECT_EQ(Animation::ABORTED, 2007 EXPECT_EQ(Animation::ABORTED,
2005 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 2008 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
2006 EXPECT_TRUE(delegate.aborted()); 2009 EXPECT_TRUE(delegate.aborted());
2007 2010
2008 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 2011 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2009 animations->UpdateState(true, nullptr); 2012 animations->UpdateState(true, nullptr);
2010 EXPECT_TRUE(host_->animation_waiting_for_deletion()); 2013 EXPECT_TRUE(host_->needs_push_properties());
2011 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 2014 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
2012 animations->GetAnimation(TargetProperty::OPACITY)->run_state()); 2015 animations->GetAnimation(TargetProperty::OPACITY)->run_state());
2013 2016
2014 animations->PushPropertiesTo(animations_impl.get()); 2017 animations->PushPropertiesTo(animations_impl.get());
2015 animations_impl->ActivateAnimations(); 2018 animations_impl->ActivateAnimations();
2016 EXPECT_FALSE(animations->GetAnimationById(animation_id)); 2019 EXPECT_FALSE(animations->GetAnimationById(animation_id));
2017 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); 2020 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id));
2018 } 2021 }
2019 2022
2020 // Test that an impl-only scroll offset animation that needs to be completed on 2023 // Test that an impl-only scroll offset animation that needs to be completed on
(...skipping 29 matching lines...) Expand all
2050 animations->PushPropertiesTo(animations_impl.get()); 2053 animations->PushPropertiesTo(animations_impl.get());
2051 animations_impl->ActivateAnimations(); 2054 animations_impl->ActivateAnimations();
2052 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id)); 2055 EXPECT_TRUE(animations_impl->GetAnimationById(animation_id));
2053 2056
2054 const bool needs_completion = true; 2057 const bool needs_completion = true;
2055 animations_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET, 2058 animations_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET,
2056 needs_completion); 2059 needs_completion);
2057 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION, 2060 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION,
2058 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) 2061 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
2059 ->run_state()); 2062 ->run_state());
2060 EXPECT_FALSE(host_->animation_waiting_for_deletion()); 2063 EXPECT_FALSE(host_->needs_push_properties());
2061 EXPECT_FALSE(host_impl_->animation_waiting_for_deletion()); 2064 EXPECT_FALSE(host_impl_->needs_push_properties());
2062 2065
2063 auto events = host_impl_->CreateEvents(); 2066 auto events = host_impl_->CreateEvents();
2064 animations_impl->Animate(kInitialTickTime); 2067 animations_impl->Animate(kInitialTickTime);
2065 animations_impl->UpdateState(true, events.get()); 2068 animations_impl->UpdateState(true, events.get());
2066 EXPECT_TRUE(delegate_impl.finished()); 2069 EXPECT_TRUE(delegate_impl.finished());
2067 EXPECT_TRUE(host_impl_->animation_waiting_for_deletion()); 2070 EXPECT_TRUE(host_impl_->needs_push_properties());
2068 EXPECT_EQ(1u, events->events_.size()); 2071 EXPECT_EQ(1u, events->events_.size());
2069 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type); 2072 EXPECT_EQ(AnimationEvent::TAKEOVER, events->events_[0].type);
2070 EXPECT_EQ(123, events->events_[0].animation_start_time); 2073 EXPECT_EQ(123, events->events_[0].animation_start_time);
2071 EXPECT_EQ( 2074 EXPECT_EQ(
2072 target_value, 2075 target_value,
2073 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); 2076 events->events_[0].curve->ToScrollOffsetAnimationCurve()->target_value());
2074 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 2077 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
2075 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) 2078 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
2076 ->run_state()); 2079 ->run_state());
2077 2080
2081 // MT receives the event to take over.
2078 animations->NotifyAnimationTakeover(events->events_[0]); 2082 animations->NotifyAnimationTakeover(events->events_[0]);
2079 EXPECT_TRUE(delegate.takeover()); 2083 EXPECT_TRUE(delegate.takeover());
2080 2084
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.
2081 animations->PushPropertiesTo(animations_impl.get()); 2091 animations->PushPropertiesTo(animations_impl.get());
2082 animations_impl->ActivateAnimations(); 2092 animations_impl->ActivateAnimations();
2083 EXPECT_FALSE(animations->GetAnimationById(animation_id)); 2093 EXPECT_FALSE(animations->GetAnimationById(animation_id));
2084 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id)); 2094 EXPECT_FALSE(animations_impl->GetAnimationById(animation_id));
2085 } 2095 }
2086 2096
2087 // Ensure that we only generate FINISHED events for animations in a group 2097 // Ensure that we only generate FINISHED events for animations in a group
2088 // once all animations in that group are finished. 2098 // once all animations in that group are finished.
2089 TEST_F(ElementAnimationsTest, FinishedEventsForGroup) { 2099 TEST_F(ElementAnimationsTest, FinishedEventsForGroup) {
2090 CreateTestLayer(true, false); 2100 CreateTestLayer(true, false);
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after
3735 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( 3745 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty(
3736 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3746 TargetProperty::OPACITY, ElementListType::ACTIVE));
3737 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3747 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3738 TargetProperty::OPACITY, ElementListType::PENDING)); 3748 TargetProperty::OPACITY, ElementListType::PENDING));
3739 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( 3749 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty(
3740 TargetProperty::OPACITY, ElementListType::ACTIVE)); 3750 TargetProperty::OPACITY, ElementListType::ACTIVE));
3741 } 3751 }
3742 3752
3743 } // namespace 3753 } // namespace
3744 } // namespace cc 3754 } // 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