summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 16:12:07 +0000
committerajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 16:12:07 +0000
commita829909e49e6fbb93e4d1e3a7579bb98c11f58a1 (patch)
treee79247ee2fc9008f0611616f33e01f65d4e23216 /cc
parent5e589bc5e9d7ad23044dfbe8aaa61086c47acbea (diff)
downloadchromium_src-a829909e49e6fbb93e4d1e3a7579bb98c11f58a1.zip
chromium_src-a829909e49e6fbb93e4d1e3a7579bb98c11f58a1.tar.gz
chromium_src-a829909e49e6fbb93e4d1e3a7579bb98c11f58a1.tar.bz2
cc: Make LayerAnimationController only call StartAnimations when needed
This makes LayerAnimationController track when it has animations that might need to be started, allowing StartAnimations to only be called when needed rather than during every call to Animate and every call to UpdateState. BUG=369690 Review URL: https://codereview.chromium.org/271473004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268800 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/animation/layer_animation_controller.cc14
-rw-r--r--cc/animation/layer_animation_controller.h8
-rw-r--r--cc/animation/layer_animation_controller_unittest.cc25
3 files changed, 44 insertions, 3 deletions
diff --git a/cc/animation/layer_animation_controller.cc b/cc/animation/layer_animation_controller.cc
index 239a29a..58b26d7 100644
--- a/cc/animation/layer_animation_controller.cc
+++ b/cc/animation/layer_animation_controller.cc
@@ -26,7 +26,9 @@ LayerAnimationController::LayerAnimationController(int id)
is_active_(false),
last_tick_time_(0),
value_provider_(NULL),
- layer_animation_delegate_(NULL) {}
+ layer_animation_delegate_(NULL),
+ needs_to_start_animations_(false) {
+}
LayerAnimationController::~LayerAnimationController() {
if (registrar_)
@@ -126,7 +128,8 @@ void LayerAnimationController::Animate(double monotonic_time) {
if (!HasValueObserver())
return;
- StartAnimations(monotonic_time);
+ if (needs_to_start_animations_)
+ StartAnimations(monotonic_time);
TickAnimations(monotonic_time);
last_tick_time_ = monotonic_time;
}
@@ -210,7 +213,7 @@ void LayerAnimationController::UpdateState(bool start_ready_animations,
MarkFinishedAnimations(last_tick_time_);
MarkAnimationsForDeletion(last_tick_time_, events);
- if (start_ready_animations) {
+ if (needs_to_start_animations_ && start_ready_animations) {
StartAnimations(last_tick_time_);
PromoteStartedAnimations(last_tick_time_, events);
}
@@ -242,6 +245,7 @@ void LayerAnimationController::ActivateAnimations() {
void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) {
animations_.push_back(animation.Pass());
+ needs_to_start_animations_ = true;
UpdateActivation(NormalActivation);
}
@@ -599,6 +603,8 @@ void LayerAnimationController::PushPropertiesToImplThread(
}
void LayerAnimationController::StartAnimations(double monotonic_time) {
+ DCHECK(needs_to_start_animations_);
+ needs_to_start_animations_ = false;
// First collect running properties affecting each type of observer.
TargetProperties blocked_properties_for_active_observers;
TargetProperties blocked_properties_for_pending_observers;
@@ -663,6 +669,8 @@ void LayerAnimationController::StartAnimations(double monotonic_time) {
animations_[j]->SetRunState(Animation::Starting, monotonic_time);
}
}
+ } else {
+ needs_to_start_animations_ = true;
}
}
}
diff --git a/cc/animation/layer_animation_controller.h b/cc/animation/layer_animation_controller.h
index c98a879..bf54a14 100644
--- a/cc/animation/layer_animation_controller.h
+++ b/cc/animation/layer_animation_controller.h
@@ -132,6 +132,10 @@ class CC_EXPORT LayerAnimationController
// animations. Returns false if the maximum scale cannot be computed.
bool MaximumScale(float* max_scale) const;
+ bool needs_to_start_animations_for_testing() {
+ return needs_to_start_animations_;
+ }
+
protected:
friend class base::RefCounted<LayerAnimationController>;
@@ -198,6 +202,10 @@ class CC_EXPORT LayerAnimationController
AnimationDelegate* layer_animation_delegate_;
+ // Only try to start animations when new animations are added or when the
+ // previous attempt at starting animations failed to start all animations.
+ bool needs_to_start_animations_;
+
DISALLOW_COPY_AND_ASSIGN(LayerAnimationController);
};
diff --git a/cc/animation/layer_animation_controller_unittest.cc b/cc/animation/layer_animation_controller_unittest.cc
index a6a5363..e172f72 100644
--- a/cc/animation/layer_animation_controller_unittest.cc
+++ b/cc/animation/layer_animation_controller_unittest.cc
@@ -43,10 +43,15 @@ TEST(LayerAnimationControllerTest, SyncNewAnimation) {
EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
+ EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
+ EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
+
AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
+ EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
int group_id = controller->GetAnimation(Animation::Opacity)->group();
controller->PushAnimationUpdatesTo(controller_impl.get());
+ EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing());
controller_impl->ActivateAnimations();
EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
@@ -421,8 +426,11 @@ TEST(LayerAnimationControllerTest, TrivialTransition) {
1,
Animation::Opacity));
+ EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
controller->AddAnimation(to_add.Pass());
+ EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
controller->Animate(kInitialTickTime);
+ EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
controller->UpdateState(true, events.get());
EXPECT_TRUE(controller->HasActiveAnimation());
EXPECT_EQ(0.f, dummy.opacity());
@@ -962,6 +970,8 @@ TEST(LayerAnimationControllerTest, TrivialQueuing) {
LayerAnimationController::Create(0));
controller->AddValueObserver(&dummy);
+ EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
+
controller->AddAnimation(CreateAnimation(
scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1,
@@ -972,12 +982,22 @@ TEST(LayerAnimationControllerTest, TrivialQueuing) {
2,
Animation::Opacity));
+ EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
+
controller->Animate(kInitialTickTime);
+
+ // The second animation still needs to be started.
+ EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
+
controller->UpdateState(true, events.get());
EXPECT_TRUE(controller->HasActiveAnimation());
EXPECT_EQ(0.f, dummy.opacity());
controller->Animate(kInitialTickTime + 1.0);
+
+ EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
controller->UpdateState(true, events.get());
+ EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
+
EXPECT_TRUE(controller->HasActiveAnimation());
EXPECT_EQ(1.f, dummy.opacity());
controller->Animate(kInitialTickTime + 2.0);
@@ -1942,10 +1962,14 @@ TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) {
LayerAnimationController::Create(0));
controller->AddValueObserver(&dummy);
+ EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false);
int group_id = controller->GetAnimation(Animation::Opacity)->group();
+ EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
+ EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
controller->PushAnimationUpdatesTo(controller_impl.get());
+ EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing());
EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
EXPECT_EQ(
@@ -1957,6 +1981,7 @@ TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) {
->affects_active_observers());
controller_impl->Animate(kInitialTickTime);
+ EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
controller_impl->UpdateState(true, events.get());
// Since the animation hasn't been activated, it should still be Starting