summaryrefslogtreecommitdiffstats
path: root/cc/animation
diff options
context:
space:
mode:
authorajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 08:10:00 +0000
committerajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 08:10:00 +0000
commit40880faa21a0a9ac7365437748c98358290319b6 (patch)
treebff3ed39938cf895b86af61a0a48816274ac75c3 /cc/animation
parentc817ad70e0927459d06045e4be82cc0719c39529 (diff)
downloadchromium_src-40880faa21a0a9ac7365437748c98358290319b6.zip
chromium_src-40880faa21a0a9ac7365437748c98358290319b6.tar.gz
chromium_src-40880faa21a0a9ac7365437748c98358290319b6.tar.bz2
De-activate LayerAnimationControllers when all animations are WaitingForDeletion
Animations that are in the WaitingForDeletion state cannot make any further progress, so we do not need to tick LayerAnimationControllers that only have such animations. BUG=319557 Review URL: https://codereview.chromium.org/73343002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235657 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/animation')
-rw-r--r--cc/animation/layer_animation_controller.cc14
-rw-r--r--cc/animation/layer_animation_controller_unittest.cc82
2 files changed, 93 insertions, 3 deletions
diff --git a/cc/animation/layer_animation_controller.cc b/cc/animation/layer_animation_controller.cc
index 556c9c2..3bac4a9 100644
--- a/cc/animation/layer_animation_controller.cc
+++ b/cc/animation/layer_animation_controller.cc
@@ -756,11 +756,19 @@ void LayerAnimationController::TickAnimations(double monotonic_time) {
void LayerAnimationController::UpdateActivation(UpdateActivationType type) {
bool force = type == ForceActivation;
if (registrar_) {
- if (!active_animations_.empty() && (!is_active_ || force))
+ bool was_active = is_active_;
+ is_active_ = false;
+ for (size_t i = 0; i < active_animations_.size(); ++i) {
+ if (active_animations_[i]->run_state() != Animation::WaitingForDeletion) {
+ is_active_ = true;
+ break;
+ }
+ }
+
+ if (is_active_ && (!was_active || force))
registrar_->DidActivateAnimationController(this);
- else if (active_animations_.empty() && (is_active_ || force))
+ else if (!is_active_ && (was_active || force))
registrar_->DidDeactivateAnimationController(this);
- is_active_ = !active_animations_.empty();
}
}
diff --git a/cc/animation/layer_animation_controller_unittest.cc b/cc/animation/layer_animation_controller_unittest.cc
index 23257ad..a1dd9a2 100644
--- a/cc/animation/layer_animation_controller_unittest.cc
+++ b/cc/animation/layer_animation_controller_unittest.cc
@@ -7,6 +7,7 @@
#include "cc/animation/animation.h"
#include "cc/animation/animation_curve.h"
#include "cc/animation/animation_delegate.h"
+#include "cc/animation/animation_registrar.h"
#include "cc/animation/keyframed_animation_curve.h"
#include "cc/animation/transform_operations.h"
#include "cc/test/animation_test_common.h"
@@ -92,6 +93,87 @@ TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
Animation::Opacity)->start_time());
}
+// Tests that controllers activate and deactivate as expected.
+TEST(LayerAnimationControllerTest, Activation) {
+ scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
+ scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create();
+
+ FakeLayerAnimationValueObserver dummy_impl;
+ scoped_refptr<LayerAnimationController> controller_impl(
+ LayerAnimationController::Create(0));
+ controller_impl->AddValueObserver(&dummy_impl);
+ FakeLayerAnimationValueObserver dummy;
+ scoped_refptr<LayerAnimationController> controller(
+ LayerAnimationController::Create(0));
+ controller->AddValueObserver(&dummy);
+ scoped_ptr<AnimationEventsVector> events(
+ make_scoped_ptr(new AnimationEventsVector));
+
+ controller->SetAnimationRegistrar(registrar.get());
+ controller_impl->SetAnimationRegistrar(registrar_impl.get());
+ EXPECT_EQ(1u, registrar->all_animation_controllers().size());
+ EXPECT_EQ(1u, registrar_impl->all_animation_controllers().size());
+
+ // Initially, both controllers should be inactive.
+ EXPECT_EQ(0u, registrar->active_animation_controllers().size());
+ EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
+
+ AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
+ // The main thread controller should now be active.
+ EXPECT_EQ(1u, registrar->active_animation_controllers().size());
+
+ controller->PushAnimationUpdatesTo(controller_impl.get());
+ // Both controllers should now be active.
+ EXPECT_EQ(1u, registrar->active_animation_controllers().size());
+ EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size());
+
+ controller_impl->Animate(1.0);
+ controller_impl->UpdateState(true, events.get());
+ EXPECT_EQ(1u, events->size());
+ controller->NotifyAnimationStarted((*events)[0], 0.0);
+
+ EXPECT_EQ(1u, registrar->active_animation_controllers().size());
+ EXPECT_EQ(1u, registrar_impl->active_animation_controllers().size());
+
+ controller->Animate(1.5);
+ controller->UpdateState(true, NULL);
+ EXPECT_EQ(1u, registrar->active_animation_controllers().size());
+
+ controller->Animate(2.0);
+ controller->UpdateState(true, NULL);
+ EXPECT_EQ(Animation::Finished,
+ controller->GetAnimation(Animation::Opacity)->run_state());
+ EXPECT_EQ(1u, registrar->active_animation_controllers().size());
+
+ events.reset(new AnimationEventsVector);
+ controller_impl->Animate(2.5);
+ controller_impl->UpdateState(true, events.get());
+
+ EXPECT_EQ(Animation::WaitingForDeletion,
+ controller_impl->GetAnimation(Animation::Opacity)->run_state());
+ // The impl thread controller should have de-activated.
+ EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
+
+ EXPECT_EQ(1u, events->size());
+ controller->NotifyAnimationFinished((*events)[0], 0.0);
+ controller->Animate(2.5);
+ controller->UpdateState(true, NULL);
+
+ EXPECT_EQ(Animation::WaitingForDeletion,
+ controller->GetAnimation(Animation::Opacity)->run_state());
+ // The main thread controller should have de-activated.
+ EXPECT_EQ(0u, registrar->active_animation_controllers().size());
+
+ controller->PushAnimationUpdatesTo(controller_impl.get());
+ EXPECT_FALSE(controller->has_any_animation());
+ EXPECT_FALSE(controller_impl->has_any_animation());
+ EXPECT_EQ(0u, registrar->active_animation_controllers().size());
+ EXPECT_EQ(0u, registrar_impl->active_animation_controllers().size());
+
+ controller->SetAnimationRegistrar(NULL);
+ controller_impl->SetAnimationRegistrar(NULL);
+}
+
TEST(LayerAnimationControllerTest, SyncPause) {
FakeLayerAnimationValueObserver dummy_impl;
scoped_refptr<LayerAnimationController> controller_impl(