| OLD | NEW |
| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 scoped_refptr<LayerAnimationController> controller_impl( | 247 scoped_refptr<LayerAnimationController> controller_impl( |
| 248 LayerAnimationController::Create(0)); | 248 LayerAnimationController::Create(0)); |
| 249 controller_impl->AddValueObserver(&dummy_impl); | 249 controller_impl->AddValueObserver(&dummy_impl); |
| 250 FakeLayerAnimationValueObserver dummy; | 250 FakeLayerAnimationValueObserver dummy; |
| 251 scoped_refptr<LayerAnimationController> controller( | 251 scoped_refptr<LayerAnimationController> controller( |
| 252 LayerAnimationController::Create(0)); | 252 LayerAnimationController::Create(0)); |
| 253 controller->AddValueObserver(&dummy); | 253 controller->AddValueObserver(&dummy); |
| 254 | 254 |
| 255 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); | 255 EXPECT_FALSE(controller_impl->GetAnimation(Animation::OPACITY)); |
| 256 | 256 |
| 257 int animation_id = | 257 // Two steps, three ranges: [0-1) -> 0.2, [1-2) -> 0.3, [2-3] -> 0.4. |
| 258 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 258 const double duration = 3.0; |
| 259 const int animation_id = |
| 260 AddOpacityStepsToController(controller.get(), duration, 0.2f, 0.4f, 2); |
| 261 |
| 262 // Set start offset to be at the beginning of the second range. |
| 263 controller->GetAnimationById(animation_id) |
| 264 ->set_time_offset(TimeDelta::FromSecondsD(1.01)); |
| 259 | 265 |
| 260 controller->PushAnimationUpdatesTo(controller_impl.get()); | 266 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 261 controller_impl->ActivateAnimations(); | 267 controller_impl->ActivateAnimations(); |
| 262 | 268 |
| 263 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | 269 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); |
| 264 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, | 270 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY, |
| 265 controller_impl->GetAnimationById(animation_id)->run_state()); | 271 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 266 | 272 |
| 273 TimeTicks time = kInitialTickTime; |
| 274 |
| 267 // Start the animations on each controller. | 275 // Start the animations on each controller. |
| 268 AnimationEventsVector events; | 276 AnimationEventsVector events; |
| 269 controller_impl->Animate(kInitialTickTime); | 277 controller_impl->Animate(time); |
| 270 controller_impl->UpdateState(true, &events); | 278 controller_impl->UpdateState(true, &events); |
| 271 controller->Animate(kInitialTickTime); | 279 EXPECT_EQ(1u, events.size()); |
| 280 |
| 281 controller->Animate(time); |
| 272 controller->UpdateState(true, nullptr); | 282 controller->UpdateState(true, nullptr); |
| 283 controller->NotifyAnimationStarted(events[0]); |
| 284 |
| 273 EXPECT_EQ(Animation::RUNNING, | 285 EXPECT_EQ(Animation::RUNNING, |
| 274 controller_impl->GetAnimationById(animation_id)->run_state()); | 286 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 275 EXPECT_EQ(Animation::RUNNING, | 287 EXPECT_EQ(Animation::RUNNING, |
| 276 controller->GetAnimationById(animation_id)->run_state()); | 288 controller->GetAnimationById(animation_id)->run_state()); |
| 277 | 289 |
| 278 // Pause the main-thread animation. | 290 EXPECT_EQ(0.3f, dummy.opacity()); |
| 279 controller->PauseAnimation( | 291 EXPECT_EQ(0.3f, dummy_impl.opacity()); |
| 280 animation_id, | 292 |
| 281 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000)); | 293 EXPECT_EQ(kInitialTickTime, |
| 294 controller->GetAnimationById(animation_id)->start_time()); |
| 295 EXPECT_EQ(kInitialTickTime, |
| 296 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 297 |
| 298 // Pause the animation at the middle of the second range so the offset |
| 299 // delays animation until the middle of the third range. |
| 300 controller->PauseAnimation(animation_id, TimeDelta::FromSecondsD(1.5)); |
| 282 EXPECT_EQ(Animation::PAUSED, | 301 EXPECT_EQ(Animation::PAUSED, |
| 283 controller->GetAnimationById(animation_id)->run_state()); | 302 controller->GetAnimationById(animation_id)->run_state()); |
| 284 | 303 |
| 285 // The pause run state change should make it to the impl thread controller. | 304 // The pause run state change should make it to the impl thread controller. |
| 286 controller->PushAnimationUpdatesTo(controller_impl.get()); | 305 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 287 controller_impl->ActivateAnimations(); | 306 controller_impl->ActivateAnimations(); |
| 307 |
| 308 // Advance time so it stays within the first range. |
| 309 time += TimeDelta::FromMilliseconds(10); |
| 310 controller->Animate(time); |
| 311 controller_impl->Animate(time); |
| 312 |
| 288 EXPECT_EQ(Animation::PAUSED, | 313 EXPECT_EQ(Animation::PAUSED, |
| 289 controller_impl->GetAnimationById(animation_id)->run_state()); | 314 controller_impl->GetAnimationById(animation_id)->run_state()); |
| 315 |
| 316 // Opacity value doesn't depend on time if paused at specified time offset. |
| 317 EXPECT_EQ(0.4f, dummy.opacity()); |
| 318 EXPECT_EQ(0.4f, dummy_impl.opacity()); |
| 290 } | 319 } |
| 291 | 320 |
| 292 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { | 321 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { |
| 293 FakeLayerAnimationValueObserver dummy_impl; | 322 FakeLayerAnimationValueObserver dummy_impl; |
| 294 scoped_refptr<LayerAnimationController> controller_impl( | 323 scoped_refptr<LayerAnimationController> controller_impl( |
| 295 LayerAnimationController::Create(0)); | 324 LayerAnimationController::Create(0)); |
| 296 controller_impl->AddValueObserver(&dummy_impl); | 325 controller_impl->AddValueObserver(&dummy_impl); |
| 297 FakeLayerAnimationValueObserver dummy; | 326 FakeLayerAnimationValueObserver dummy; |
| 298 scoped_refptr<LayerAnimationController> controller( | 327 scoped_refptr<LayerAnimationController> controller( |
| 299 LayerAnimationController::Create(0)); | 328 LayerAnimationController::Create(0)); |
| (...skipping 2263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2563 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::OPACITY)); | 2592 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2564 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::FILTER)); | 2593 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::FILTER)); |
| 2565 | 2594 |
| 2566 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); | 2595 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); |
| 2567 controller->UpdateState(true, nullptr); | 2596 controller->UpdateState(true, nullptr); |
| 2568 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::OPACITY)); | 2597 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::OPACITY)); |
| 2569 } | 2598 } |
| 2570 | 2599 |
| 2571 } // namespace | 2600 } // namespace |
| 2572 } // namespace cc | 2601 } // namespace cc |
| OLD | NEW |