| 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "cc/animation/animation_curve.h" | 7 #include "cc/animation/animation_curve.h" |
| 8 #include "cc/animation/layer_animation_controller.h" | 8 #include "cc/animation/layer_animation_controller.h" |
| 9 #include "cc/animation/scroll_offset_animation_curve.h" | 9 #include "cc/animation/scroll_offset_animation_curve.h" |
| 10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
| 11 #include "cc/base/time_util.h" | 11 #include "cc/base/time_util.h" |
| 12 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
| 13 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
| 14 #include "cc/test/animation_test_common.h" | 14 #include "cc/test/animation_test_common.h" |
| 15 #include "cc/test/fake_content_layer.h" | |
| 16 #include "cc/test/fake_content_layer_client.h" | 15 #include "cc/test/fake_content_layer_client.h" |
| 16 #include "cc/test/fake_picture_layer.h" |
| 17 #include "cc/test/layer_tree_test.h" | 17 #include "cc/test/layer_tree_test.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class LayerTreeHostAnimationTest : public LayerTreeTest { | 23 class LayerTreeHostAnimationTest : public LayerTreeTest { |
| 24 public: | 24 public: |
| 25 void SetupTree() override { | 25 void SetupTree() override { |
| 26 LayerTreeTest::SetupTree(); | 26 LayerTreeTest::SetupTree(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted); | 224 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted); |
| 225 | 225 |
| 226 // Ensure that an animation's timing function is respected. | 226 // Ensure that an animation's timing function is respected. |
| 227 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 227 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
| 228 : public LayerTreeHostAnimationTest { | 228 : public LayerTreeHostAnimationTest { |
| 229 public: | 229 public: |
| 230 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} | 230 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} |
| 231 | 231 |
| 232 void SetupTree() override { | 232 void SetupTree() override { |
| 233 LayerTreeHostAnimationTest::SetupTree(); | 233 LayerTreeHostAnimationTest::SetupTree(); |
| 234 content_ = FakeContentLayer::Create(layer_settings(), &client_); | 234 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 235 content_->SetBounds(gfx::Size(4, 4)); | 235 picture_->SetBounds(gfx::Size(4, 4)); |
| 236 layer_tree_host()->root_layer()->AddChild(content_); | 236 layer_tree_host()->root_layer()->AddChild(picture_); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void BeginTest() override { PostAddAnimationToMainThread(content_.get()); } | 239 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } |
| 240 | 240 |
| 241 void AnimateLayers(LayerTreeHostImpl* host_impl, | 241 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 242 base::TimeTicks monotonic_time) override { | 242 base::TimeTicks monotonic_time) override { |
| 243 LayerAnimationController* controller_impl = | 243 LayerAnimationController* controller_impl = |
| 244 host_impl->active_tree()->root_layer()->children()[0]-> | 244 host_impl->active_tree()->root_layer()->children()[0]-> |
| 245 layer_animation_controller(); | 245 layer_animation_controller(); |
| 246 Animation* animation = controller_impl->GetAnimation(Animation::OPACITY); | 246 Animation* animation = controller_impl->GetAnimation(Animation::OPACITY); |
| 247 if (!animation) | 247 if (!animation) |
| 248 return; | 248 return; |
| 249 | 249 |
| 250 const FloatAnimationCurve* curve = | 250 const FloatAnimationCurve* curve = |
| 251 animation->curve()->ToFloatAnimationCurve(); | 251 animation->curve()->ToFloatAnimationCurve(); |
| 252 float start_opacity = curve->GetValue(base::TimeDelta()); | 252 float start_opacity = curve->GetValue(base::TimeDelta()); |
| 253 float end_opacity = curve->GetValue(curve->Duration()); | 253 float end_opacity = curve->GetValue(curve->Duration()); |
| 254 float linearly_interpolated_opacity = | 254 float linearly_interpolated_opacity = |
| 255 0.25f * end_opacity + 0.75f * start_opacity; | 255 0.25f * end_opacity + 0.75f * start_opacity; |
| 256 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); | 256 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); |
| 257 // If the linear timing function associated with this animation was not | 257 // If the linear timing function associated with this animation was not |
| 258 // picked up, then the linearly interpolated opacity would be different | 258 // picked up, then the linearly interpolated opacity would be different |
| 259 // because of the default ease timing function. | 259 // because of the default ease timing function. |
| 260 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); | 260 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); |
| 261 | 261 |
| 262 EndTest(); | 262 EndTest(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void AfterTest() override {} | 265 void AfterTest() override {} |
| 266 | 266 |
| 267 FakeContentLayerClient client_; | 267 FakeContentLayerClient client_; |
| 268 scoped_refptr<FakeContentLayer> content_; | 268 scoped_refptr<FakePictureLayer> picture_; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 SINGLE_AND_MULTI_THREAD_TEST_F( | 271 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 272 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); | 272 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); |
| 273 | 273 |
| 274 // Ensures that main thread animations have their start times synchronized with | 274 // Ensures that main thread animations have their start times synchronized with |
| 275 // impl thread animations. | 275 // impl thread animations. |
| 276 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes | 276 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
| 277 : public LayerTreeHostAnimationTest { | 277 : public LayerTreeHostAnimationTest { |
| 278 public: | 278 public: |
| 279 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() {} | 279 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() {} |
| 280 | 280 |
| 281 void SetupTree() override { | 281 void SetupTree() override { |
| 282 LayerTreeHostAnimationTest::SetupTree(); | 282 LayerTreeHostAnimationTest::SetupTree(); |
| 283 content_ = FakeContentLayer::Create(layer_settings(), &client_); | 283 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 284 content_->SetBounds(gfx::Size(4, 4)); | 284 picture_->SetBounds(gfx::Size(4, 4)); |
| 285 content_->set_layer_animation_delegate(this); | 285 picture_->set_layer_animation_delegate(this); |
| 286 layer_tree_host()->root_layer()->AddChild(content_); | 286 layer_tree_host()->root_layer()->AddChild(picture_); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void BeginTest() override { PostAddAnimationToMainThread(content_.get()); } | 289 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } |
| 290 | 290 |
| 291 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 291 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 292 Animation::TargetProperty target_property, | 292 Animation::TargetProperty target_property, |
| 293 int group) override { | 293 int group) override { |
| 294 LayerAnimationController* controller = | 294 LayerAnimationController* controller = |
| 295 layer_tree_host()->root_layer()->children()[0]-> | 295 layer_tree_host()->root_layer()->children()[0]-> |
| 296 layer_animation_controller(); | 296 layer_animation_controller(); |
| 297 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 297 Animation* animation = controller->GetAnimation(Animation::OPACITY); |
| 298 main_start_time_ = animation->start_time(); | 298 main_start_time_ = animation->start_time(); |
| 299 controller->RemoveAnimation(animation->id()); | 299 controller->RemoveAnimation(animation->id()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 314 | 314 |
| 315 void AfterTest() override { | 315 void AfterTest() override { |
| 316 EXPECT_EQ(impl_start_time_, main_start_time_); | 316 EXPECT_EQ(impl_start_time_, main_start_time_); |
| 317 EXPECT_LT(base::TimeTicks(), impl_start_time_); | 317 EXPECT_LT(base::TimeTicks(), impl_start_time_); |
| 318 } | 318 } |
| 319 | 319 |
| 320 private: | 320 private: |
| 321 base::TimeTicks main_start_time_; | 321 base::TimeTicks main_start_time_; |
| 322 base::TimeTicks impl_start_time_; | 322 base::TimeTicks impl_start_time_; |
| 323 FakeContentLayerClient client_; | 323 FakeContentLayerClient client_; |
| 324 scoped_refptr<FakeContentLayer> content_; | 324 scoped_refptr<FakePictureLayer> picture_; |
| 325 }; | 325 }; |
| 326 | 326 |
| 327 SINGLE_AND_MULTI_THREAD_TEST_F( | 327 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 328 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); | 328 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); |
| 329 | 329 |
| 330 // Ensures that notify animation finished is called. | 330 // Ensures that notify animation finished is called. |
| 331 class LayerTreeHostAnimationTestAnimationFinishedEvents | 331 class LayerTreeHostAnimationTestAnimationFinishedEvents |
| 332 : public LayerTreeHostAnimationTest { | 332 : public LayerTreeHostAnimationTest { |
| 333 public: | 333 public: |
| 334 LayerTreeHostAnimationTestAnimationFinishedEvents() {} | 334 LayerTreeHostAnimationTestAnimationFinishedEvents() {} |
| (...skipping 19 matching lines...) Expand all Loading... |
| 354 SINGLE_AND_MULTI_THREAD_TEST_F( | 354 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 355 LayerTreeHostAnimationTestAnimationFinishedEvents); | 355 LayerTreeHostAnimationTestAnimationFinishedEvents); |
| 356 | 356 |
| 357 // Ensures that when opacity is being animated, this value does not cause the | 357 // Ensures that when opacity is being animated, this value does not cause the |
| 358 // subtree to be skipped. | 358 // subtree to be skipped. |
| 359 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity | 359 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity |
| 360 : public LayerTreeHostAnimationTest { | 360 : public LayerTreeHostAnimationTest { |
| 361 public: | 361 public: |
| 362 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() | 362 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() |
| 363 : update_check_layer_( | 363 : update_check_layer_( |
| 364 FakeContentLayer::Create(layer_settings(), &client_)) {} | 364 FakePictureLayer::Create(layer_settings(), &client_)) {} |
| 365 | 365 |
| 366 void SetupTree() override { | 366 void SetupTree() override { |
| 367 update_check_layer_->SetOpacity(0.f); | 367 update_check_layer_->SetOpacity(0.f); |
| 368 layer_tree_host()->SetRootLayer(update_check_layer_); | 368 layer_tree_host()->SetRootLayer(update_check_layer_); |
| 369 LayerTreeHostAnimationTest::SetupTree(); | 369 LayerTreeHostAnimationTest::SetupTree(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void BeginTest() override { | 372 void BeginTest() override { |
| 373 PostAddAnimationToMainThread(update_check_layer_.get()); | 373 PostAddAnimationToMainThread(update_check_layer_.get()); |
| 374 } | 374 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 386 // Update() should have been called once, proving that the layer was not | 386 // Update() should have been called once, proving that the layer was not |
| 387 // skipped. | 387 // skipped. |
| 388 EXPECT_EQ(1u, update_check_layer_->update_count()); | 388 EXPECT_EQ(1u, update_check_layer_->update_count()); |
| 389 | 389 |
| 390 // clear update_check_layer_ so LayerTreeHost dies. | 390 // clear update_check_layer_ so LayerTreeHost dies. |
| 391 update_check_layer_ = NULL; | 391 update_check_layer_ = NULL; |
| 392 } | 392 } |
| 393 | 393 |
| 394 private: | 394 private: |
| 395 FakeContentLayerClient client_; | 395 FakeContentLayerClient client_; |
| 396 scoped_refptr<FakeContentLayer> update_check_layer_; | 396 scoped_refptr<FakePictureLayer> update_check_layer_; |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 SINGLE_AND_MULTI_THREAD_TEST_F( | 399 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 400 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); | 400 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); |
| 401 | 401 |
| 402 // Layers added to tree with existing active animations should have the | 402 // Layers added to tree with existing active animations should have the |
| 403 // animation correctly recognized. | 403 // animation correctly recognized. |
| 404 class LayerTreeHostAnimationTestLayerAddedWithAnimation | 404 class LayerTreeHostAnimationTestLayerAddedWithAnimation |
| 405 : public LayerTreeHostAnimationTest { | 405 : public LayerTreeHostAnimationTest { |
| 406 public: | 406 public: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 void AfterTest() override { | 468 void AfterTest() override { |
| 469 EXPECT_EQ(2, num_begin_frames_); | 469 EXPECT_EQ(2, num_begin_frames_); |
| 470 EXPECT_EQ(1, num_commit_calls_); | 470 EXPECT_EQ(1, num_commit_calls_); |
| 471 EXPECT_EQ(1, num_draw_calls_); | 471 EXPECT_EQ(1, num_draw_calls_); |
| 472 } | 472 } |
| 473 | 473 |
| 474 private: | 474 private: |
| 475 int num_begin_frames_; | 475 int num_begin_frames_; |
| 476 int num_commit_calls_; | 476 int num_commit_calls_; |
| 477 int num_draw_calls_; | 477 int num_draw_calls_; |
| 478 FakeContentLayerClient client_; | |
| 479 scoped_refptr<FakeContentLayer> content_; | |
| 480 }; | 478 }; |
| 481 | 479 |
| 482 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit); | 480 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit); |
| 483 | 481 |
| 484 class LayerTreeHostAnimationTestForceRedraw | 482 class LayerTreeHostAnimationTestForceRedraw |
| 485 : public LayerTreeHostAnimationTest { | 483 : public LayerTreeHostAnimationTest { |
| 486 public: | 484 public: |
| 487 LayerTreeHostAnimationTestForceRedraw() | 485 LayerTreeHostAnimationTestForceRedraw() |
| 488 : num_animate_(0), num_draw_layers_(0) {} | 486 : num_animate_(0), num_draw_layers_(0) {} |
| 489 | 487 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 549 |
| 552 // Make sure the main thread can still execute animations when CanDraw() is not | 550 // Make sure the main thread can still execute animations when CanDraw() is not |
| 553 // true. | 551 // true. |
| 554 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw | 552 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw |
| 555 : public LayerTreeHostAnimationTest { | 553 : public LayerTreeHostAnimationTest { |
| 556 public: | 554 public: |
| 557 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} | 555 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} |
| 558 | 556 |
| 559 void SetupTree() override { | 557 void SetupTree() override { |
| 560 LayerTreeHostAnimationTest::SetupTree(); | 558 LayerTreeHostAnimationTest::SetupTree(); |
| 561 content_ = FakeContentLayer::Create(layer_settings(), &client_); | 559 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 562 content_->SetBounds(gfx::Size(4, 4)); | 560 picture_->SetBounds(gfx::Size(4, 4)); |
| 563 content_->set_layer_animation_delegate(this); | 561 picture_->set_layer_animation_delegate(this); |
| 564 layer_tree_host()->root_layer()->AddChild(content_); | 562 layer_tree_host()->root_layer()->AddChild(picture_); |
| 565 } | 563 } |
| 566 | 564 |
| 567 void BeginTest() override { | 565 void BeginTest() override { |
| 568 layer_tree_host()->SetViewportSize(gfx::Size()); | 566 layer_tree_host()->SetViewportSize(gfx::Size()); |
| 569 PostAddAnimationToMainThread(content_.get()); | 567 PostAddAnimationToMainThread(picture_.get()); |
| 570 } | 568 } |
| 571 | 569 |
| 572 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 570 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 573 Animation::TargetProperty target_property, | 571 Animation::TargetProperty target_property, |
| 574 int group) override { | 572 int group) override { |
| 575 started_times_++; | 573 started_times_++; |
| 576 } | 574 } |
| 577 | 575 |
| 578 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 576 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
| 579 Animation::TargetProperty target_property, | 577 Animation::TargetProperty target_property, |
| 580 int group) override { | 578 int group) override { |
| 581 EndTest(); | 579 EndTest(); |
| 582 } | 580 } |
| 583 | 581 |
| 584 void AfterTest() override { EXPECT_EQ(1, started_times_); } | 582 void AfterTest() override { EXPECT_EQ(1, started_times_); } |
| 585 | 583 |
| 586 private: | 584 private: |
| 587 int started_times_; | 585 int started_times_; |
| 588 FakeContentLayerClient client_; | 586 FakeContentLayerClient client_; |
| 589 scoped_refptr<FakeContentLayer> content_; | 587 scoped_refptr<FakePictureLayer> picture_; |
| 590 }; | 588 }; |
| 591 | 589 |
| 592 SINGLE_AND_MULTI_THREAD_TEST_F( | 590 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 593 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw); | 591 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw); |
| 594 | 592 |
| 595 // Animations should not be started when frames are being skipped due to | 593 // Animations should not be started when frames are being skipped due to |
| 596 // checkerboard. | 594 // checkerboard. |
| 597 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations | 595 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
| 598 : public LayerTreeHostAnimationTest { | 596 : public LayerTreeHostAnimationTest { |
| 599 void SetupTree() override { | 597 void SetupTree() override { |
| 600 LayerTreeHostAnimationTest::SetupTree(); | 598 LayerTreeHostAnimationTest::SetupTree(); |
| 601 content_ = FakeContentLayer::Create(layer_settings(), &client_); | 599 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 602 content_->SetBounds(gfx::Size(4, 4)); | 600 picture_->SetBounds(gfx::Size(4, 4)); |
| 603 content_->set_layer_animation_delegate(this); | 601 picture_->set_layer_animation_delegate(this); |
| 604 layer_tree_host()->root_layer()->AddChild(content_); | 602 layer_tree_host()->root_layer()->AddChild(picture_); |
| 605 } | 603 } |
| 606 | 604 |
| 607 void InitializeSettings(LayerTreeSettings* settings) override { | 605 void InitializeSettings(LayerTreeSettings* settings) override { |
| 608 // Make sure that drawing many times doesn't cause a checkerboarded | 606 // Make sure that drawing many times doesn't cause a checkerboarded |
| 609 // animation to start so we avoid flake in this test. | 607 // animation to start so we avoid flake in this test. |
| 610 settings->timeout_and_draw_when_animation_checkerboards = false; | 608 settings->timeout_and_draw_when_animation_checkerboards = false; |
| 611 } | 609 } |
| 612 | 610 |
| 613 void BeginTest() override { | 611 void BeginTest() override { |
| 614 prevented_draw_ = 0; | 612 prevented_draw_ = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 629 ++prevented_draw_; | 627 ++prevented_draw_; |
| 630 if (prevented_draw_ > 2) | 628 if (prevented_draw_ > 2) |
| 631 EndTest(); | 629 EndTest(); |
| 632 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 630 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 633 } | 631 } |
| 634 | 632 |
| 635 void DidCommitAndDrawFrame() override { | 633 void DidCommitAndDrawFrame() override { |
| 636 switch (layer_tree_host()->source_frame_number()) { | 634 switch (layer_tree_host()->source_frame_number()) { |
| 637 case 1: | 635 case 1: |
| 638 // The animation is longer than 1 BeginFrame interval. | 636 // The animation is longer than 1 BeginFrame interval. |
| 639 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); | 637 AddOpacityTransitionToLayer(picture_.get(), 0.1, 0.2f, 0.8f, false); |
| 640 added_animations_++; | 638 added_animations_++; |
| 641 break; | 639 break; |
| 642 case 2: | 640 case 2: |
| 643 // This second animation will not be drawn so it should not start. | 641 // This second animation will not be drawn so it should not start. |
| 644 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); | 642 AddAnimatedTransformToLayer(picture_.get(), 0.1, 5, 5); |
| 645 added_animations_++; | 643 added_animations_++; |
| 646 break; | 644 break; |
| 647 } | 645 } |
| 648 } | 646 } |
| 649 | 647 |
| 650 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 648 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 651 Animation::TargetProperty target_property, | 649 Animation::TargetProperty target_property, |
| 652 int group) override { | 650 int group) override { |
| 653 if (TestEnded()) | 651 if (TestEnded()) |
| 654 return; | 652 return; |
| 655 started_times_++; | 653 started_times_++; |
| 656 } | 654 } |
| 657 | 655 |
| 658 void AfterTest() override { | 656 void AfterTest() override { |
| 659 // Make sure we tried to draw the second animation but failed. | 657 // Make sure we tried to draw the second animation but failed. |
| 660 EXPECT_LT(0, prevented_draw_); | 658 EXPECT_LT(0, prevented_draw_); |
| 661 // The first animation should be started, but the second should not because | 659 // The first animation should be started, but the second should not because |
| 662 // of checkerboard. | 660 // of checkerboard. |
| 663 EXPECT_EQ(1, started_times_); | 661 EXPECT_EQ(1, started_times_); |
| 664 } | 662 } |
| 665 | 663 |
| 666 int prevented_draw_; | 664 int prevented_draw_; |
| 667 int added_animations_; | 665 int added_animations_; |
| 668 int started_times_; | 666 int started_times_; |
| 669 FakeContentLayerClient client_; | 667 FakeContentLayerClient client_; |
| 670 scoped_refptr<FakeContentLayer> content_; | 668 scoped_refptr<FakePictureLayer> picture_; |
| 671 }; | 669 }; |
| 672 | 670 |
| 673 MULTI_THREAD_TEST_F( | 671 MULTI_THREAD_TEST_F( |
| 674 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 672 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
| 675 | 673 |
| 676 // Verifies that scroll offset animations are only accepted when impl-scrolling | 674 // Verifies that scroll offset animations are only accepted when impl-scrolling |
| 677 // is supported, and that when scroll offset animations are accepted, | 675 // is supported, and that when scroll offset animations are accepted, |
| 678 // scroll offset updates are sent back to the main thread. | 676 // scroll offset updates are sent back to the main thread. |
| 679 class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated | 677 class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
| 680 : public LayerTreeHostAnimationTest { | 678 : public LayerTreeHostAnimationTest { |
| 681 public: | 679 public: |
| 682 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated() {} | 680 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated() {} |
| 683 | 681 |
| 684 void SetupTree() override { | 682 void SetupTree() override { |
| 685 LayerTreeHostAnimationTest::SetupTree(); | 683 LayerTreeHostAnimationTest::SetupTree(); |
| 686 | 684 |
| 687 scroll_layer_ = FakeContentLayer::Create(layer_settings(), &client_); | 685 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 688 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 686 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 689 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); | 687 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); |
| 690 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 688 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 691 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 689 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 692 } | 690 } |
| 693 | 691 |
| 694 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 692 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 695 | 693 |
| 696 void DidCommit() override { | 694 void DidCommit() override { |
| 697 switch (layer_tree_host()->source_frame_number()) { | 695 switch (layer_tree_host()->source_frame_number()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 715 if (scroll_layer_->scroll_offset().x() > 10 && | 713 if (scroll_layer_->scroll_offset().x() > 10 && |
| 716 scroll_layer_->scroll_offset().y() > 20) | 714 scroll_layer_->scroll_offset().y() > 20) |
| 717 EndTest(); | 715 EndTest(); |
| 718 } | 716 } |
| 719 } | 717 } |
| 720 | 718 |
| 721 void AfterTest() override {} | 719 void AfterTest() override {} |
| 722 | 720 |
| 723 private: | 721 private: |
| 724 FakeContentLayerClient client_; | 722 FakeContentLayerClient client_; |
| 725 scoped_refptr<FakeContentLayer> scroll_layer_; | 723 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 726 }; | 724 }; |
| 727 | 725 |
| 728 SINGLE_AND_MULTI_THREAD_TEST_F( | 726 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 729 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); | 727 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); |
| 730 | 728 |
| 731 // Verifies that when the main thread removes a scroll animation and sets a new | 729 // Verifies that when the main thread removes a scroll animation and sets a new |
| 732 // scroll position, the active tree takes on exactly this new scroll position | 730 // scroll position, the active tree takes on exactly this new scroll position |
| 733 // after activation, and the main thread doesn't receive a spurious scroll | 731 // after activation, and the main thread doesn't receive a spurious scroll |
| 734 // delta. | 732 // delta. |
| 735 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval | 733 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| 736 : public LayerTreeHostAnimationTest { | 734 : public LayerTreeHostAnimationTest { |
| 737 public: | 735 public: |
| 738 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() | 736 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() |
| 739 : final_postion_(50.0, 100.0) {} | 737 : final_postion_(50.0, 100.0) {} |
| 740 | 738 |
| 741 void SetupTree() override { | 739 void SetupTree() override { |
| 742 LayerTreeHostAnimationTest::SetupTree(); | 740 LayerTreeHostAnimationTest::SetupTree(); |
| 743 | 741 |
| 744 scroll_layer_ = FakeContentLayer::Create(layer_settings(), &client_); | 742 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 745 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 743 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 746 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); | 744 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| 747 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); | 745 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); |
| 748 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 746 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 749 | 747 |
| 750 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 748 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 751 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), | 749 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), |
| 752 EaseInOutTimingFunction::Create())); | 750 EaseInOutTimingFunction::Create())); |
| 753 scoped_ptr<Animation> animation( | 751 scoped_ptr<Animation> animation( |
| 754 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); | 752 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 827 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 830 EndTest(); | 828 EndTest(); |
| 831 } | 829 } |
| 832 | 830 |
| 833 void AfterTest() override { | 831 void AfterTest() override { |
| 834 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 832 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 835 } | 833 } |
| 836 | 834 |
| 837 private: | 835 private: |
| 838 FakeContentLayerClient client_; | 836 FakeContentLayerClient client_; |
| 839 scoped_refptr<FakeContentLayer> scroll_layer_; | 837 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 840 const gfx::ScrollOffset final_postion_; | 838 const gfx::ScrollOffset final_postion_; |
| 841 }; | 839 }; |
| 842 | 840 |
| 843 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval); | 841 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval); |
| 844 | 842 |
| 845 // When animations are simultaneously added to an existing layer and to a new | 843 // When animations are simultaneously added to an existing layer and to a new |
| 846 // layer, they should start at the same time, even when there's already a | 844 // layer, they should start at the same time, even when there's already a |
| 847 // running animation on the existing layer. | 845 // running animation on the existing layer. |
| 848 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers | 846 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers |
| 849 : public LayerTreeHostAnimationTest { | 847 : public LayerTreeHostAnimationTest { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 | 928 |
| 931 // When a layer with an animation is removed from the tree and later re-added, | 929 // When a layer with an animation is removed from the tree and later re-added, |
| 932 // the animation should resume. | 930 // the animation should resume. |
| 933 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded | 931 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded |
| 934 : public LayerTreeHostAnimationTest { | 932 : public LayerTreeHostAnimationTest { |
| 935 public: | 933 public: |
| 936 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded() {} | 934 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded() {} |
| 937 | 935 |
| 938 void SetupTree() override { | 936 void SetupTree() override { |
| 939 LayerTreeHostAnimationTest::SetupTree(); | 937 LayerTreeHostAnimationTest::SetupTree(); |
| 940 content_ = Layer::Create(layer_settings()); | 938 layer_ = Layer::Create(layer_settings()); |
| 941 content_->SetBounds(gfx::Size(4, 4)); | 939 layer_->SetBounds(gfx::Size(4, 4)); |
| 942 layer_tree_host()->root_layer()->AddChild(content_); | 940 layer_tree_host()->root_layer()->AddChild(layer_); |
| 943 AddOpacityTransitionToLayer(content_.get(), 10000.0, 0.1f, 0.9f, true); | 941 AddOpacityTransitionToLayer(layer_.get(), 10000.0, 0.1f, 0.9f, true); |
| 944 } | 942 } |
| 945 | 943 |
| 946 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 944 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 947 | 945 |
| 948 void DidCommit() override { | 946 void DidCommit() override { |
| 949 switch (layer_tree_host()->source_frame_number()) { | 947 switch (layer_tree_host()->source_frame_number()) { |
| 950 case 1: | 948 case 1: |
| 951 content_->RemoveFromParent(); | 949 layer_->RemoveFromParent(); |
| 952 break; | 950 break; |
| 953 case 2: | 951 case 2: |
| 954 layer_tree_host()->root_layer()->AddChild(content_); | 952 layer_tree_host()->root_layer()->AddChild(layer_); |
| 955 break; | 953 break; |
| 956 } | 954 } |
| 957 } | 955 } |
| 958 | 956 |
| 959 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 957 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 960 switch (host_impl->active_tree()->source_frame_number()) { | 958 switch (host_impl->active_tree()->source_frame_number()) { |
| 961 case 0: | 959 case 0: |
| 962 EXPECT_TRUE(host_impl->animation_registrar()->needs_animate_layers()); | 960 EXPECT_TRUE(host_impl->animation_registrar()->needs_animate_layers()); |
| 963 break; | 961 break; |
| 964 case 1: | 962 case 1: |
| 965 EXPECT_FALSE(host_impl->animation_registrar()->needs_animate_layers()); | 963 EXPECT_FALSE(host_impl->animation_registrar()->needs_animate_layers()); |
| 966 break; | 964 break; |
| 967 case 2: | 965 case 2: |
| 968 EXPECT_TRUE(host_impl->animation_registrar()->needs_animate_layers()); | 966 EXPECT_TRUE(host_impl->animation_registrar()->needs_animate_layers()); |
| 969 EndTest(); | 967 EndTest(); |
| 970 break; | 968 break; |
| 971 } | 969 } |
| 972 } | 970 } |
| 973 | 971 |
| 974 void AfterTest() override {} | 972 void AfterTest() override {} |
| 975 | 973 |
| 976 private: | 974 private: |
| 977 scoped_refptr<Layer> content_; | 975 scoped_refptr<Layer> layer_; |
| 978 }; | 976 }; |
| 979 | 977 |
| 980 SINGLE_AND_MULTI_THREAD_TEST_F( | 978 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 981 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded); | 979 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded); |
| 982 | 980 |
| 983 class LayerTreeHostAnimationTestAddAnimationAfterAnimating | 981 class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
| 984 : public LayerTreeHostAnimationTest { | 982 : public LayerTreeHostAnimationTest { |
| 985 public: | 983 public: |
| 986 LayerTreeHostAnimationTestAddAnimationAfterAnimating() | 984 LayerTreeHostAnimationTestAddAnimationAfterAnimating() |
| 987 : num_swap_buffers_(0) {} | 985 : num_swap_buffers_(0) {} |
| 988 | 986 |
| 989 void SetupTree() override { | 987 void SetupTree() override { |
| 990 LayerTreeHostAnimationTest::SetupTree(); | 988 LayerTreeHostAnimationTest::SetupTree(); |
| 991 content_ = Layer::Create(layer_settings()); | 989 layer_ = Layer::Create(layer_settings()); |
| 992 content_->SetBounds(gfx::Size(4, 4)); | 990 layer_->SetBounds(gfx::Size(4, 4)); |
| 993 layer_tree_host()->root_layer()->AddChild(content_); | 991 layer_tree_host()->root_layer()->AddChild(layer_); |
| 994 } | 992 } |
| 995 | 993 |
| 996 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 994 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 997 | 995 |
| 998 void DidCommit() override { | 996 void DidCommit() override { |
| 999 switch (layer_tree_host()->source_frame_number()) { | 997 switch (layer_tree_host()->source_frame_number()) { |
| 1000 case 1: | 998 case 1: |
| 1001 // First frame: add an animation to the root layer. | 999 // First frame: add an animation to the root layer. |
| 1002 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 0.1, 5, 5); | 1000 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 0.1, 5, 5); |
| 1003 break; | 1001 break; |
| 1004 case 2: | 1002 case 2: |
| 1005 // Second frame: add an animation to the content layer. The root layer | 1003 // Second frame: add an animation to the content layer. The root layer |
| 1006 // animation has caused us to animate already during this frame. | 1004 // animation has caused us to animate already during this frame. |
| 1007 AddOpacityTransitionToLayer(content_.get(), 0.1, 5, 5, false); | 1005 AddOpacityTransitionToLayer(layer_.get(), 0.1, 5, 5, false); |
| 1008 break; | 1006 break; |
| 1009 } | 1007 } |
| 1010 } | 1008 } |
| 1011 | 1009 |
| 1012 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 1010 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 1013 // After both animations have started, verify that they have valid | 1011 // After both animations have started, verify that they have valid |
| 1014 // start times. | 1012 // start times. |
| 1015 num_swap_buffers_++; | 1013 num_swap_buffers_++; |
| 1016 AnimationRegistrar::AnimationControllerMap controllers_copy = | 1014 AnimationRegistrar::AnimationControllerMap controllers_copy = |
| 1017 host_impl->animation_registrar() | 1015 host_impl->animation_registrar() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1028 Animation* anim = it.second->GetAnimation(Animation::OPACITY); | 1026 Animation* anim = it.second->GetAnimation(Animation::OPACITY); |
| 1029 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1027 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1030 } | 1028 } |
| 1031 } | 1029 } |
| 1032 } | 1030 } |
| 1033 } | 1031 } |
| 1034 | 1032 |
| 1035 void AfterTest() override {} | 1033 void AfterTest() override {} |
| 1036 | 1034 |
| 1037 private: | 1035 private: |
| 1038 scoped_refptr<Layer> content_; | 1036 scoped_refptr<Layer> layer_; |
| 1039 int num_swap_buffers_; | 1037 int num_swap_buffers_; |
| 1040 }; | 1038 }; |
| 1041 | 1039 |
| 1042 SINGLE_AND_MULTI_THREAD_TEST_F( | 1040 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1043 LayerTreeHostAnimationTestAddAnimationAfterAnimating); | 1041 LayerTreeHostAnimationTestAddAnimationAfterAnimating); |
| 1044 | 1042 |
| 1045 } // namespace | 1043 } // namespace |
| 1046 } // namespace cc | 1044 } // namespace cc |
| OLD | NEW |