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

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

Issue 60083018: Don't PushProperties every commit for animating layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include "cc/animation/animation.h" 7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_registrar.h" 10 #include "cc/animation/animation_registrar.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 controller_impl->UpdateState(true, events.get()); 286 controller_impl->UpdateState(true, events.get());
287 287
288 // There should be a Started event for the animation. 288 // There should be a Started event for the animation.
289 EXPECT_EQ(1u, events->size()); 289 EXPECT_EQ(1u, events->size());
290 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); 290 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
291 controller->NotifyAnimationStarted((*events)[0], 0.0); 291 controller->NotifyAnimationStarted((*events)[0], 0.0);
292 292
293 controller->Animate(1.0); 293 controller->Animate(1.0);
294 controller->UpdateState(true, NULL); 294 controller->UpdateState(true, NULL);
295 295
296 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
297 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
298
296 events.reset(new AnimationEventsVector); 299 events.reset(new AnimationEventsVector);
297 controller_impl->Animate(2.0); 300 controller_impl->Animate(2.0);
298 controller_impl->UpdateState(true, events.get()); 301 controller_impl->UpdateState(true, events.get());
299 302
303 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
304
300 // There should be a Finished event for the animation. 305 // There should be a Finished event for the animation.
301 EXPECT_EQ(1u, events->size()); 306 EXPECT_EQ(1u, events->size());
302 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); 307 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
303 308
304 // Neither controller should have deleted the animation yet. 309 // Neither controller should have deleted the animation yet.
305 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity)); 310 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
306 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity)); 311 EXPECT_TRUE(controller_impl->GetAnimation(Animation::Opacity));
307 312
308 controller->NotifyAnimationFinished((*events)[0], 0.0); 313 controller->NotifyAnimationFinished((*events)[0], 0.0);
309 314
310 controller->Animate(3.0); 315 controller->Animate(3.0);
311 controller->UpdateState(true, NULL); 316 controller->UpdateState(true, NULL);
317 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
312 318
313 controller->PushAnimationUpdatesTo(controller_impl.get()); 319 controller->PushAnimationUpdatesTo(controller_impl.get());
314 320
315 // Both controllers should now have deleted the animation. 321 // Both controllers should now have deleted the animation.
316 EXPECT_FALSE(controller->has_any_animation()); 322 EXPECT_FALSE(controller->has_any_animation());
317 EXPECT_FALSE(controller_impl->has_any_animation()); 323 EXPECT_FALSE(controller_impl->has_any_animation());
318 } 324 }
319 325
320 // Tests that transitioning opacity from 0 to 1 works as expected. 326 // Tests that transitioning opacity from 0 to 1 works as expected.
321 327
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 controller->Animate(1.0); 1139 controller->Animate(1.0);
1134 controller->UpdateState(true, events.get()); 1140 controller->UpdateState(true, events.get());
1135 EXPECT_TRUE(controller->HasActiveAnimation()); 1141 EXPECT_TRUE(controller->HasActiveAnimation());
1136 EXPECT_EQ(1.f, dummy.opacity()); 1142 EXPECT_EQ(1.f, dummy.opacity());
1137 controller->Animate(2.0); 1143 controller->Animate(2.0);
1138 controller->UpdateState(true, events.get()); 1144 controller->UpdateState(true, events.get());
1139 EXPECT_TRUE(!controller->HasActiveAnimation()); 1145 EXPECT_TRUE(!controller->HasActiveAnimation());
1140 EXPECT_EQ(0.75f, dummy.opacity()); 1146 EXPECT_EQ(0.75f, dummy.opacity());
1141 } 1147 }
1142 1148
1143 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) { 1149 TEST(LayerAnimationControllerTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
1144 FakeLayerAnimationValueObserver dummy_impl; 1150 FakeLayerAnimationValueObserver dummy_impl;
1145 scoped_refptr<LayerAnimationController> controller_impl( 1151 scoped_refptr<LayerAnimationController> controller_impl(
1146 LayerAnimationController::Create(0)); 1152 LayerAnimationController::Create(0));
1147 controller_impl->AddValueObserver(&dummy_impl); 1153 controller_impl->AddValueObserver(&dummy_impl);
1148 scoped_ptr<AnimationEventsVector> events( 1154 scoped_ptr<AnimationEventsVector> events(
1149 make_scoped_ptr(new AnimationEventsVector)); 1155 make_scoped_ptr(new AnimationEventsVector));
1150 FakeLayerAnimationValueObserver dummy; 1156 FakeLayerAnimationValueObserver dummy;
1151 scoped_refptr<LayerAnimationController> controller( 1157 scoped_refptr<LayerAnimationController> controller(
1152 LayerAnimationController::Create(0)); 1158 LayerAnimationController::Create(0));
1153 controller->AddValueObserver(&dummy); 1159 controller->AddValueObserver(&dummy);
1154 1160
1155 scoped_ptr<Animation> to_add(CreateAnimation( 1161 scoped_ptr<Animation> to_add(CreateAnimation(
1156 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), 1162 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1157 0, 1163 0,
1158 Animation::Opacity)); 1164 Animation::Opacity));
1159 to_add->set_needs_synchronized_start_time(true); 1165 to_add->set_needs_synchronized_start_time(true);
1160 controller->AddAnimation(to_add.Pass()); 1166 controller->AddAnimation(to_add.Pass());
1161 1167
1162 controller->Animate(0.0); 1168 controller->Animate(0.0);
1163 controller->UpdateState(true, events.get()); 1169 controller->UpdateState(true, events.get());
1164 EXPECT_TRUE(controller->HasActiveAnimation()); 1170 EXPECT_TRUE(controller->HasActiveAnimation());
1165 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity); 1171 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity);
1166 EXPECT_TRUE(active_animation); 1172 EXPECT_TRUE(active_animation);
1167 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 1173 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1168 1174
1169 controller->set_force_sync();
1170
1171 controller->PushAnimationUpdatesTo(controller_impl.get()); 1175 controller->PushAnimationUpdatesTo(controller_impl.get());
1172 1176
1173 active_animation = controller_impl->GetAnimation(0, Animation::Opacity); 1177 active_animation = controller_impl->GetAnimation(0, Animation::Opacity);
1174 EXPECT_TRUE(active_animation); 1178 EXPECT_TRUE(active_animation);
1175 EXPECT_EQ(Animation::WaitingForTargetAvailability, 1179 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1176 active_animation->run_state()); 1180 active_animation->run_state());
1177 } 1181 }
1178 1182
1179 // Tests that skipping a call to UpdateState works as expected. 1183 // Tests that skipping a call to UpdateState works as expected.
1180 TEST(LayerAnimationControllerTest, SkipUpdateState) { 1184 TEST(LayerAnimationControllerTest, SkipUpdateState) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 1434
1431 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); 1435 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1432 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 1436 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1433 1437
1434 controller->PushAnimationUpdatesTo(controller_impl.get()); 1438 controller->PushAnimationUpdatesTo(controller_impl.get());
1435 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1439 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1436 1440
1437 controller->AbortAnimations(Animation::Opacity); 1441 controller->AbortAnimations(Animation::Opacity);
1438 EXPECT_EQ(Animation::Aborted, 1442 EXPECT_EQ(Animation::Aborted,
1439 controller->GetAnimation(Animation::Opacity)->run_state()); 1443 controller->GetAnimation(Animation::Opacity)->run_state());
1444 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1445 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1440 1446
1441 controller->Animate(1.0); 1447 controller->Animate(1.0);
1442 controller->UpdateState(true, NULL); 1448 controller->UpdateState(true, NULL);
1449 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1443 EXPECT_EQ(Animation::WaitingForDeletion, 1450 EXPECT_EQ(Animation::WaitingForDeletion,
1444 controller->GetAnimation(Animation::Opacity)->run_state()); 1451 controller->GetAnimation(Animation::Opacity)->run_state());
1445 1452
1446 controller->PushAnimationUpdatesTo(controller_impl.get()); 1453 controller->PushAnimationUpdatesTo(controller_impl.get());
1447 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); 1454 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1448 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1455 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1449 } 1456 }
1450 1457
1451 // An animation aborted on the impl thread should get deleted on both threads. 1458 // An animation aborted on the impl thread should get deleted on both threads.
1452 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { 1459 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) {
1453 FakeLayerAnimationValueObserver dummy_impl; 1460 FakeLayerAnimationValueObserver dummy_impl;
1454 scoped_refptr<LayerAnimationController> controller_impl( 1461 scoped_refptr<LayerAnimationController> controller_impl(
1455 LayerAnimationController::Create(0)); 1462 LayerAnimationController::Create(0));
1456 controller_impl->AddValueObserver(&dummy_impl); 1463 controller_impl->AddValueObserver(&dummy_impl);
1457 FakeLayerAnimationValueObserver dummy; 1464 FakeLayerAnimationValueObserver dummy;
1458 scoped_refptr<LayerAnimationController> controller( 1465 scoped_refptr<LayerAnimationController> controller(
1459 LayerAnimationController::Create(0)); 1466 LayerAnimationController::Create(0));
1460 controller->AddValueObserver(&dummy); 1467 controller->AddValueObserver(&dummy);
1461 1468
1462 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); 1469 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1463 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 1470 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1464 1471
1465 controller->PushAnimationUpdatesTo(controller_impl.get()); 1472 controller->PushAnimationUpdatesTo(controller_impl.get());
1466 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1473 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1467 1474
1468 controller_impl->AbortAnimations(Animation::Opacity); 1475 controller_impl->AbortAnimations(Animation::Opacity);
1469 EXPECT_EQ(Animation::Aborted, 1476 EXPECT_EQ(Animation::Aborted,
1470 controller_impl->GetAnimation(Animation::Opacity)->run_state()); 1477 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1478 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1479 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1471 1480
1472 AnimationEventsVector events; 1481 AnimationEventsVector events;
1473 controller_impl->Animate(1.0); 1482 controller_impl->Animate(1.0);
1474 controller_impl->UpdateState(true, &events); 1483 controller_impl->UpdateState(true, &events);
1484 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
1475 EXPECT_EQ(1u, events.size()); 1485 EXPECT_EQ(1u, events.size());
1476 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); 1486 EXPECT_EQ(AnimationEvent::Aborted, events[0].type);
1477 EXPECT_EQ(Animation::WaitingForDeletion, 1487 EXPECT_EQ(Animation::WaitingForDeletion,
1478 controller_impl->GetAnimation(Animation::Opacity)->run_state()); 1488 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1479 1489
1480 controller->NotifyAnimationAborted(events[0]); 1490 controller->NotifyAnimationAborted(events[0]);
1481 EXPECT_EQ(Animation::Aborted, 1491 EXPECT_EQ(Animation::Aborted,
1482 controller->GetAnimation(Animation::Opacity)->run_state()); 1492 controller->GetAnimation(Animation::Opacity)->run_state());
1483 1493
1484 controller->Animate(1.5); 1494 controller->Animate(1.5);
1485 controller->UpdateState(true, NULL); 1495 controller->UpdateState(true, NULL);
1496 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1486 EXPECT_EQ(Animation::WaitingForDeletion, 1497 EXPECT_EQ(Animation::WaitingForDeletion,
1487 controller->GetAnimation(Animation::Opacity)->run_state()); 1498 controller->GetAnimation(Animation::Opacity)->run_state());
1488 1499
1489 controller->PushAnimationUpdatesTo(controller_impl.get()); 1500 controller->PushAnimationUpdatesTo(controller_impl.get());
1490 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); 1501 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1491 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1502 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1492 } 1503 }
1493 1504
1494 // Ensure that we only generate Finished events for animations in a group 1505 // Ensure that we only generate Finished events for animations in a group
1495 // once all animations in that group are finished. 1506 // once all animations in that group are finished.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 // animation, and an Aborted event for the opacity animation. 1591 // animation, and an Aborted event for the opacity animation.
1581 EXPECT_EQ(2u, events->size()); 1592 EXPECT_EQ(2u, events->size());
1582 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); 1593 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1583 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); 1594 EXPECT_EQ(Animation::Transform, (*events)[0].target_property);
1584 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); 1595 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type);
1585 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); 1596 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property);
1586 } 1597 }
1587 1598
1588 } // namespace 1599 } // namespace
1589 } // namespace cc 1600 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/animation/layer_animation_value_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698