| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/animation/animation.h" | 10 #include "cc/animation/animation.h" |
| 11 #include "cc/animation/animation_curve.h" | 11 #include "cc/animation/animation_curve.h" |
| 12 #include "cc/animation/animation_delegate.h" | 12 #include "cc/animation/animation_delegate.h" |
| 13 #include "cc/animation/animation_events.h" | 13 #include "cc/animation/animation_events.h" |
| 14 #include "cc/animation/animation_registrar.h" | 14 #include "cc/animation/animation_host.h" |
| 15 #include "cc/animation/keyframed_animation_curve.h" | 15 #include "cc/animation/keyframed_animation_curve.h" |
| 16 #include "cc/animation/scroll_offset_animation_curve.h" | 16 #include "cc/animation/scroll_offset_animation_curve.h" |
| 17 #include "cc/animation/transform_operations.h" | 17 #include "cc/animation/transform_operations.h" |
| 18 #include "cc/test/animation_test_common.h" | 18 #include "cc/test/animation_test_common.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/gfx/geometry/box_f.h" | 21 #include "ui/gfx/geometry/box_f.h" |
| 22 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 23 | 23 |
| 24 namespace cc { | 24 namespace cc { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 210 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 211 controller->UpdateState(true, nullptr); | 211 controller->UpdateState(true, nullptr); |
| 212 EXPECT_EQ(start_time, | 212 EXPECT_EQ(start_time, |
| 213 controller->GetAnimationById(animation_id)->start_time()); | 213 controller->GetAnimationById(animation_id)->start_time()); |
| 214 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), | 214 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(), |
| 215 controller_impl->GetAnimationById(animation_id)->start_time()); | 215 controller_impl->GetAnimationById(animation_id)->start_time()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Tests that controllers activate and deactivate as expected. | 218 // Tests that controllers activate and deactivate as expected. |
| 219 TEST(LayerAnimationControllerTest, Activation) { | 219 TEST(LayerAnimationControllerTest, Activation) { |
| 220 std::unique_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); | 220 std::unique_ptr<AnimationHost> host = |
| 221 std::unique_ptr<AnimationRegistrar> registrar_impl = | 221 AnimationHost::Create(ThreadInstance::MAIN); |
| 222 AnimationRegistrar::Create(); | 222 std::unique_ptr<AnimationHost> host_impl = |
| 223 AnimationHost::Create(ThreadInstance::IMPL); |
| 223 | 224 |
| 224 FakeLayerAnimationValueObserver dummy_impl; | 225 FakeLayerAnimationValueObserver dummy_impl; |
| 225 scoped_refptr<LayerAnimationController> controller_impl( | 226 scoped_refptr<LayerAnimationController> controller_impl( |
| 226 LayerAnimationController::Create(0)); | 227 LayerAnimationController::Create(0)); |
| 227 controller_impl->AddValueObserver(&dummy_impl); | 228 controller_impl->AddValueObserver(&dummy_impl); |
| 228 FakeLayerAnimationValueObserver dummy; | 229 FakeLayerAnimationValueObserver dummy; |
| 229 scoped_refptr<LayerAnimationController> controller( | 230 scoped_refptr<LayerAnimationController> controller( |
| 230 LayerAnimationController::Create(0)); | 231 LayerAnimationController::Create(0)); |
| 231 controller->AddValueObserver(&dummy); | 232 controller->AddValueObserver(&dummy); |
| 232 std::unique_ptr<AnimationEvents> events = registrar->CreateEvents(); | 233 std::unique_ptr<AnimationEvents> events = host->CreateEvents(); |
| 233 | 234 |
| 234 controller->SetAnimationRegistrar(registrar.get()); | 235 host->SetAnimationRegistrarFor(controller); |
| 235 controller_impl->SetAnimationRegistrar(registrar_impl.get()); | 236 host_impl->SetAnimationRegistrarFor(controller_impl); |
| 236 EXPECT_EQ(1u, registrar->all_animation_controllers_for_testing().size()); | 237 EXPECT_EQ(1u, host->all_animation_controllers_for_testing().size()); |
| 237 EXPECT_EQ(1u, registrar_impl->all_animation_controllers_for_testing().size()); | 238 EXPECT_EQ(1u, host_impl->all_animation_controllers_for_testing().size()); |
| 238 | 239 |
| 239 // Initially, both controllers should be inactive. | 240 // Initially, both controllers should be inactive. |
| 240 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); | 241 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); |
| 241 EXPECT_EQ(0u, | 242 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); |
| 242 registrar_impl->active_animation_controllers_for_testing().size()); | |
| 243 | 243 |
| 244 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); | 244 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); |
| 245 // The main thread controller should now be active. | 245 // The main thread controller should now be active. |
| 246 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 246 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); |
| 247 | 247 |
| 248 controller->PushAnimationUpdatesTo(controller_impl.get()); | 248 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 249 controller_impl->ActivateAnimations(); | 249 controller_impl->ActivateAnimations(); |
| 250 // Both controllers should now be active. | 250 // Both controllers should now be active. |
| 251 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 251 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); |
| 252 EXPECT_EQ(1u, | 252 EXPECT_EQ(1u, host_impl->active_animation_controllers_for_testing().size()); |
| 253 registrar_impl->active_animation_controllers_for_testing().size()); | |
| 254 | 253 |
| 255 controller_impl->Animate(kInitialTickTime); | 254 controller_impl->Animate(kInitialTickTime); |
| 256 controller_impl->UpdateState(true, events.get()); | 255 controller_impl->UpdateState(true, events.get()); |
| 257 EXPECT_EQ(1u, events->events_.size()); | 256 EXPECT_EQ(1u, events->events_.size()); |
| 258 controller->NotifyAnimationStarted(events->events_[0]); | 257 controller->NotifyAnimationStarted(events->events_[0]); |
| 259 | 258 |
| 260 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 259 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); |
| 261 EXPECT_EQ(1u, | 260 EXPECT_EQ(1u, host_impl->active_animation_controllers_for_testing().size()); |
| 262 registrar_impl->active_animation_controllers_for_testing().size()); | |
| 263 | 261 |
| 264 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); | 262 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); |
| 265 controller->UpdateState(true, nullptr); | 263 controller->UpdateState(true, nullptr); |
| 266 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 264 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); |
| 267 | 265 |
| 268 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 266 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 269 controller->UpdateState(true, nullptr); | 267 controller->UpdateState(true, nullptr); |
| 270 EXPECT_EQ(Animation::FINISHED, | 268 EXPECT_EQ(Animation::FINISHED, |
| 271 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 269 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 272 EXPECT_EQ(1u, registrar->active_animation_controllers_for_testing().size()); | 270 EXPECT_EQ(1u, host->active_animation_controllers_for_testing().size()); |
| 273 | 271 |
| 274 events.reset(new AnimationEvents); | 272 events.reset(new AnimationEvents); |
| 275 controller_impl->Animate(kInitialTickTime + | 273 controller_impl->Animate(kInitialTickTime + |
| 276 TimeDelta::FromMilliseconds(1500)); | 274 TimeDelta::FromMilliseconds(1500)); |
| 277 controller_impl->UpdateState(true, events.get()); | 275 controller_impl->UpdateState(true, events.get()); |
| 278 | 276 |
| 279 EXPECT_EQ( | 277 EXPECT_EQ( |
| 280 Animation::WAITING_FOR_DELETION, | 278 Animation::WAITING_FOR_DELETION, |
| 281 controller_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); | 279 controller_impl->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 282 // The impl thread controller should have de-activated. | 280 // The impl thread controller should have de-activated. |
| 283 EXPECT_EQ(0u, | 281 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); |
| 284 registrar_impl->active_animation_controllers_for_testing().size()); | |
| 285 | 282 |
| 286 EXPECT_EQ(1u, events->events_.size()); | 283 EXPECT_EQ(1u, events->events_.size()); |
| 287 controller->NotifyAnimationFinished(events->events_[0]); | 284 controller->NotifyAnimationFinished(events->events_[0]); |
| 288 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); | 285 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1500)); |
| 289 controller->UpdateState(true, nullptr); | 286 controller->UpdateState(true, nullptr); |
| 290 | 287 |
| 291 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 288 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 292 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 289 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 293 // The main thread controller should have de-activated. | 290 // The main thread controller should have de-activated. |
| 294 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); | 291 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); |
| 295 | 292 |
| 296 controller->PushAnimationUpdatesTo(controller_impl.get()); | 293 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 297 controller_impl->ActivateAnimations(); | 294 controller_impl->ActivateAnimations(); |
| 298 EXPECT_FALSE(controller->has_any_animation()); | 295 EXPECT_FALSE(controller->has_any_animation()); |
| 299 EXPECT_FALSE(controller_impl->has_any_animation()); | 296 EXPECT_FALSE(controller_impl->has_any_animation()); |
| 300 EXPECT_EQ(0u, registrar->active_animation_controllers_for_testing().size()); | 297 EXPECT_EQ(0u, host->active_animation_controllers_for_testing().size()); |
| 301 EXPECT_EQ(0u, | 298 EXPECT_EQ(0u, host_impl->active_animation_controllers_for_testing().size()); |
| 302 registrar_impl->active_animation_controllers_for_testing().size()); | |
| 303 | 299 |
| 304 controller->SetAnimationRegistrar(nullptr); | 300 host->ResetAnimationRegistrarFor(controller); |
| 305 controller_impl->SetAnimationRegistrar(nullptr); | 301 host_impl->ResetAnimationRegistrarFor(controller_impl); |
| 306 } | 302 } |
| 307 | 303 |
| 308 TEST(LayerAnimationControllerTest, SyncPause) { | 304 TEST(LayerAnimationControllerTest, SyncPause) { |
| 309 FakeLayerAnimationValueObserver dummy_impl; | 305 FakeLayerAnimationValueObserver dummy_impl; |
| 310 scoped_refptr<LayerAnimationController> controller_impl( | 306 scoped_refptr<LayerAnimationController> controller_impl( |
| 311 LayerAnimationController::Create(0)); | 307 LayerAnimationController::Create(0)); |
| 312 controller_impl->AddValueObserver(&dummy_impl); | 308 controller_impl->AddValueObserver(&dummy_impl); |
| 313 FakeLayerAnimationValueObserver dummy; | 309 FakeLayerAnimationValueObserver dummy; |
| 314 scoped_refptr<LayerAnimationController> controller( | 310 scoped_refptr<LayerAnimationController> controller( |
| 315 LayerAnimationController::Create(0)); | 311 LayerAnimationController::Create(0)); |
| (...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3125 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3121 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3126 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3122 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3127 TargetProperty::OPACITY, | 3123 TargetProperty::OPACITY, |
| 3128 LayerAnimationController::ObserverType::PENDING)); | 3124 LayerAnimationController::ObserverType::PENDING)); |
| 3129 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3125 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3130 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3126 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3131 } | 3127 } |
| 3132 | 3128 |
| 3133 } // namespace | 3129 } // namespace |
| 3134 } // namespace cc | 3130 } // namespace cc |
| OLD | NEW |