OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/layer_tree_host.h" | 7 #include "cc/layer_tree_host.h" |
8 | 8 |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "cc/content_layer.h" | 10 #include "cc/content_layer.h" |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 LayerTreeHostTestSetNeedsAnimateShouldNotSetCommitRequested() | 497 LayerTreeHostTestSetNeedsAnimateShouldNotSetCommitRequested() |
498 : m_numCommits(0) | 498 : m_numCommits(0) |
499 { | 499 { |
500 } | 500 } |
501 | 501 |
502 virtual void beginTest() OVERRIDE | 502 virtual void beginTest() OVERRIDE |
503 { | 503 { |
504 postSetNeedsCommitToMainThread(); | 504 postSetNeedsCommitToMainThread(); |
505 } | 505 } |
506 | 506 |
507 virtual void animate(double monotonicTime) OVERRIDE | 507 virtual void animate(base::TimeTicks monotonicTime) OVERRIDE |
508 { | 508 { |
509 // We skip the first commit becasue its the commit that populates the | 509 // We skip the first commit becasue its the commit that populates the |
510 // impl thread with a tree. | 510 // impl thread with a tree. |
511 if (!m_numCommits) | 511 if (!m_numCommits) |
512 return; | 512 return; |
513 | 513 |
514 m_layerTreeHost->setNeedsAnimate(); | 514 m_layerTreeHost->setNeedsAnimate(); |
515 // Right now, commitRequested is going to be true, because during | 515 // Right now, commitRequested is going to be true, because during |
516 // beginFrame, we force commitRequested to true to prevent requests from | 516 // beginFrame, we force commitRequested to true to prevent requests from |
517 // hitting the impl thread. But, when the next didCommit happens, we sho
uld | 517 // hitting the impl thread. But, when the next didCommit happens, we sho
uld |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 LayerTreeHostTestSetNeedsAnimateInsideAnimationCallback() | 557 LayerTreeHostTestSetNeedsAnimateInsideAnimationCallback() |
558 : m_numAnimates(0) | 558 : m_numAnimates(0) |
559 { | 559 { |
560 } | 560 } |
561 | 561 |
562 virtual void beginTest() OVERRIDE | 562 virtual void beginTest() OVERRIDE |
563 { | 563 { |
564 postSetNeedsAnimateToMainThread(); | 564 postSetNeedsAnimateToMainThread(); |
565 } | 565 } |
566 | 566 |
567 virtual void animate(double) OVERRIDE | 567 virtual void animate(base::TimeTicks) OVERRIDE |
568 { | 568 { |
569 if (!m_numAnimates) { | 569 if (!m_numAnimates) { |
570 m_layerTreeHost->setNeedsAnimate(); | 570 m_layerTreeHost->setNeedsAnimate(); |
571 m_numAnimates++; | 571 m_numAnimates++; |
572 return; | 572 return; |
573 } | 573 } |
574 endTest(); | 574 endTest(); |
575 } | 575 } |
576 | 576 |
577 virtual void afterTest() OVERRIDE | 577 virtual void afterTest() OVERRIDE |
(...skipping 10 matching lines...) Expand all Loading... |
588 } | 588 } |
589 | 589 |
590 // Add a layer animation and confirm that LayerTreeHostImpl::animateLayers does
get | 590 // Add a layer animation and confirm that LayerTreeHostImpl::animateLayers does
get |
591 // called and continues to get called. | 591 // called and continues to get called. |
592 class LayerTreeHostTestAddAnimation : public LayerTreeHostTest { | 592 class LayerTreeHostTestAddAnimation : public LayerTreeHostTest { |
593 public: | 593 public: |
594 LayerTreeHostTestAddAnimation() | 594 LayerTreeHostTestAddAnimation() |
595 : m_numAnimates(0) | 595 : m_numAnimates(0) |
596 , m_receivedAnimationStartedNotification(false) | 596 , m_receivedAnimationStartedNotification(false) |
597 , m_startTime(0) | 597 , m_startTime(0) |
598 , m_firstMonotonicTime(0) | |
599 { | 598 { |
600 } | 599 } |
601 | 600 |
602 virtual void beginTest() OVERRIDE | 601 virtual void beginTest() OVERRIDE |
603 { | 602 { |
604 postAddInstantAnimationToMainThread(); | 603 postAddInstantAnimationToMainThread(); |
605 } | 604 } |
606 | 605 |
607 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, double mono
tonicTime) OVERRIDE | 606 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE |
608 { | 607 { |
609 if (!m_numAnimates) { | 608 if (!m_numAnimates) { |
610 // The animation had zero duration so layerTreeHostImpl should no | 609 // The animation had zero duration so layerTreeHostImpl should no |
611 // longer need to animate its layers. | 610 // longer need to animate its layers. |
612 EXPECT_FALSE(layerTreeHostImpl->needsAnimateLayers()); | 611 EXPECT_FALSE(layerTreeHostImpl->needsAnimateLayers()); |
613 m_numAnimates++; | 612 m_numAnimates++; |
614 m_firstMonotonicTime = monotonicTime; | 613 m_firstMonotonicTime = monotonicTime; |
615 return; | 614 return; |
616 } | 615 } |
617 EXPECT_LT(0, m_startTime); | 616 EXPECT_LT(0, m_startTime); |
618 EXPECT_LT(0, m_firstMonotonicTime); | |
619 EXPECT_NE(m_startTime, m_firstMonotonicTime); | |
620 EXPECT_TRUE(m_receivedAnimationStartedNotification); | 617 EXPECT_TRUE(m_receivedAnimationStartedNotification); |
621 endTest(); | 618 endTest(); |
622 } | 619 } |
623 | 620 |
624 virtual void notifyAnimationStarted(double wallClockTime) OVERRIDE | 621 virtual void notifyAnimationStarted(double wallClockTime) OVERRIDE |
625 { | 622 { |
626 m_receivedAnimationStartedNotification = true; | 623 m_receivedAnimationStartedNotification = true; |
627 m_startTime = wallClockTime; | 624 m_startTime = wallClockTime; |
628 } | 625 } |
629 | 626 |
630 virtual void afterTest() OVERRIDE | 627 virtual void afterTest() OVERRIDE |
631 { | 628 { |
632 } | 629 } |
633 | 630 |
634 private: | 631 private: |
635 int m_numAnimates; | 632 int m_numAnimates; |
636 bool m_receivedAnimationStartedNotification; | 633 bool m_receivedAnimationStartedNotification; |
637 double m_startTime; | 634 double m_startTime; |
638 double m_firstMonotonicTime; | 635 base::TimeTicks m_firstMonotonicTime; |
639 }; | 636 }; |
640 | 637 |
641 TEST_F(LayerTreeHostTestAddAnimation, runMultiThread) | 638 TEST_F(LayerTreeHostTestAddAnimation, runMultiThread) |
642 { | 639 { |
643 runTest(true); | 640 runTest(true); |
644 } | 641 } |
645 | 642 |
646 // Add a layer animation to a layer, but continually fail to draw. Confirm that
after | 643 // Add a layer animation to a layer, but continually fail to draw. Confirm that
after |
647 // a while, we do eventually force a draw. | 644 // a while, we do eventually force a draw. |
648 class LayerTreeHostTestCheckerboardDoesNotStarveDraws : public LayerTreeHostTest
{ | 645 class LayerTreeHostTestCheckerboardDoesNotStarveDraws : public LayerTreeHostTest
{ |
649 public: | 646 public: |
650 LayerTreeHostTestCheckerboardDoesNotStarveDraws() | 647 LayerTreeHostTestCheckerboardDoesNotStarveDraws() |
651 : m_startedAnimating(false) | 648 : m_startedAnimating(false) |
652 { | 649 { |
653 } | 650 } |
654 | 651 |
655 virtual void beginTest() OVERRIDE | 652 virtual void beginTest() OVERRIDE |
656 { | 653 { |
657 postAddAnimationToMainThread(); | 654 postAddAnimationToMainThread(); |
658 } | 655 } |
659 | 656 |
660 virtual void afterTest() OVERRIDE | 657 virtual void afterTest() OVERRIDE |
661 { | 658 { |
662 } | 659 } |
663 | 660 |
664 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, double mono
tonicTime) OVERRIDE | 661 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE |
665 { | 662 { |
666 m_startedAnimating = true; | 663 m_startedAnimating = true; |
667 } | 664 } |
668 | 665 |
669 virtual void drawLayersOnThread(LayerTreeHostImpl*) OVERRIDE | 666 virtual void drawLayersOnThread(LayerTreeHostImpl*) OVERRIDE |
670 { | 667 { |
671 if (m_startedAnimating) | 668 if (m_startedAnimating) |
672 endTest(); | 669 endTest(); |
673 } | 670 } |
674 | 671 |
(...skipping 21 matching lines...) Expand all Loading... |
696 } | 693 } |
697 | 694 |
698 virtual void beginTest() OVERRIDE | 695 virtual void beginTest() OVERRIDE |
699 { | 696 { |
700 postAddAnimationToMainThread(); | 697 postAddAnimationToMainThread(); |
701 } | 698 } |
702 | 699 |
703 // Use willAnimateLayers to set visible false before the animation runs and | 700 // Use willAnimateLayers to set visible false before the animation runs and |
704 // causes a commit, so we block the second visible animate in single-thread | 701 // causes a commit, so we block the second visible animate in single-thread |
705 // mode. | 702 // mode. |
706 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, double
monotonicTime) OVERRIDE | 703 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::T
imeTicks monotonicTime) OVERRIDE |
707 { | 704 { |
708 if (m_numAnimates < 2) { | 705 if (m_numAnimates < 2) { |
709 if (!m_numAnimates) { | 706 if (!m_numAnimates) { |
710 // We have a long animation running. It should continue to tick
even if we are not visible. | 707 // We have a long animation running. It should continue to tick
even if we are not visible. |
711 postSetVisibleToMainThread(false); | 708 postSetVisibleToMainThread(false); |
712 } | 709 } |
713 m_numAnimates++; | 710 m_numAnimates++; |
714 return; | 711 return; |
715 } | 712 } |
716 endTest(); | 713 endTest(); |
(...skipping 14 matching lines...) Expand all Loading... |
731 public: | 728 public: |
732 LayerTreeHostTestAddAnimationWithTimingFunction() | 729 LayerTreeHostTestAddAnimationWithTimingFunction() |
733 { | 730 { |
734 } | 731 } |
735 | 732 |
736 virtual void beginTest() OVERRIDE | 733 virtual void beginTest() OVERRIDE |
737 { | 734 { |
738 postAddAnimationToMainThread(); | 735 postAddAnimationToMainThread(); |
739 } | 736 } |
740 | 737 |
741 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, double mono
tonicTime) OVERRIDE | 738 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE |
742 { | 739 { |
743 const ActiveAnimation* animation = m_layerTreeHost->rootLayer()->layerAn
imationController()->getActiveAnimation(0, ActiveAnimation::Opacity); | 740 const ActiveAnimation* animation = m_layerTreeHost->rootLayer()->layerAn
imationController()->getActiveAnimation(0, ActiveAnimation::Opacity); |
744 if (!animation) | 741 if (!animation) |
745 return; | 742 return; |
746 const FloatAnimationCurve* curve = animation->curve()->toFloatAnimationC
urve(); | 743 const FloatAnimationCurve* curve = animation->curve()->toFloatAnimationC
urve(); |
747 float startOpacity = curve->getValue(0); | 744 float startOpacity = curve->getValue(0); |
748 float endOpacity = curve->getValue(curve->duration()); | 745 float endOpacity = curve->getValue(curve->duration()); |
749 float linearlyInterpolatedOpacity = 0.25 * endOpacity + 0.75 * startOpac
ity; | 746 float linearlyInterpolatedOpacity = 0.25 * endOpacity + 0.75 * startOpac
ity; |
750 double time = curve->duration() * 0.25; | 747 double time = curve->duration() * 0.25; |
751 // If the linear timing function associated with this animation was not
picked up, | 748 // If the linear timing function associated with this animation was not
picked up, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 LayerTreeHostTestSynchronizeAnimationStartTimes() | 801 LayerTreeHostTestSynchronizeAnimationStartTimes() |
805 : m_layerTreeHostImpl(0) | 802 : m_layerTreeHostImpl(0) |
806 { | 803 { |
807 } | 804 } |
808 | 805 |
809 virtual void beginTest() OVERRIDE | 806 virtual void beginTest() OVERRIDE |
810 { | 807 { |
811 postAddAnimationToMainThread(); | 808 postAddAnimationToMainThread(); |
812 } | 809 } |
813 | 810 |
814 // This is guaranteed to be called before LayerTreeHostImpl::animateLayers. | 811 // This is guaranteed to be called before CCLayerTreeHostImpl::animateLayers
. |
815 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, double
monotonicTime) OVERRIDE | 812 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::T
imeTicks monotonicTime) OVERRIDE |
816 { | 813 { |
817 m_layerTreeHostImpl = layerTreeHostImpl; | 814 m_layerTreeHostImpl = layerTreeHostImpl; |
818 } | 815 } |
819 | 816 |
820 virtual void notifyAnimationStarted(double time) OVERRIDE | 817 virtual void notifyAnimationStarted(double time) OVERRIDE |
821 { | 818 { |
822 EXPECT_TRUE(m_layerTreeHostImpl); | 819 EXPECT_TRUE(m_layerTreeHostImpl); |
823 | 820 |
824 LayerAnimationController* controllerImpl = m_layerTreeHostImpl->rootLaye
r()->layerAnimationController(); | 821 LayerAnimationController* controllerImpl = m_layerTreeHostImpl->rootLaye
r()->layerAnimationController(); |
825 LayerAnimationController* controller = m_layerTreeHost->rootLayer()->lay
erAnimationController(); | 822 LayerAnimationController* controller = m_layerTreeHost->rootLayer()->lay
erAnimationController(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 virtual void beginTest() OVERRIDE | 1062 virtual void beginTest() OVERRIDE |
1066 { | 1063 { |
1067 m_layerTreeHost->rootLayer()->setScrollable(true); | 1064 m_layerTreeHost->rootLayer()->setScrollable(true); |
1068 m_layerTreeHost->rootLayer()->setScrollPosition(IntPoint()); | 1065 m_layerTreeHost->rootLayer()->setScrollPosition(IntPoint()); |
1069 postSetNeedsCommitToMainThread(); | 1066 postSetNeedsCommitToMainThread(); |
1070 postSetNeedsRedrawToMainThread(); | 1067 postSetNeedsRedrawToMainThread(); |
1071 } | 1068 } |
1072 | 1069 |
1073 void requestStartPageScaleAnimation() | 1070 void requestStartPageScaleAnimation() |
1074 { | 1071 { |
1075 layerTreeHost()->startPageScaleAnimation(IntSize(), false, 1.25, 0); | 1072 layerTreeHost()->startPageScaleAnimation(IntSize(), false, 1.25, base::T
imeDelta()); |
1076 } | 1073 } |
1077 | 1074 |
1078 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1075 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
1079 { | 1076 { |
1080 impl->rootLayer()->setScrollable(true); | 1077 impl->rootLayer()->setScrollable(true); |
1081 impl->rootLayer()->setScrollPosition(IntPoint()); | 1078 impl->rootLayer()->setScrollPosition(IntPoint()); |
1082 impl->setPageScaleFactorAndLimits(impl->pageScaleFactor(), 0.5, 2); | 1079 impl->setPageScaleFactorAndLimits(impl->pageScaleFactor(), 0.5, 2); |
1083 | 1080 |
1084 // We request animation only once. | 1081 // We request animation only once. |
1085 if (!m_animationRequested) { | 1082 if (!m_animationRequested) { |
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3137 } | 3134 } |
3138 | 3135 |
3139 virtual void beginTest() OVERRIDE | 3136 virtual void beginTest() OVERRIDE |
3140 { | 3137 { |
3141 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10)); | 3138 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10)); |
3142 m_layerTreeHost->rootLayer()->setBounds(IntSize(10, 10)); | 3139 m_layerTreeHost->rootLayer()->setBounds(IntSize(10, 10)); |
3143 | 3140 |
3144 postSetNeedsCommitToMainThread(); | 3141 postSetNeedsCommitToMainThread(); |
3145 } | 3142 } |
3146 | 3143 |
3147 virtual void animate(double) OVERRIDE | 3144 virtual void animate(base::TimeTicks) OVERRIDE |
3148 { | 3145 { |
3149 m_layerTreeHost->setNeedsAnimate(); | 3146 m_layerTreeHost->setNeedsAnimate(); |
3150 } | 3147 } |
3151 | 3148 |
3152 virtual void layout() OVERRIDE | 3149 virtual void layout() OVERRIDE |
3153 { | 3150 { |
3154 m_layerTreeHost->rootLayer()->setNeedsDisplay(); | 3151 m_layerTreeHost->rootLayer()->setNeedsDisplay(); |
3155 } | 3152 } |
3156 | 3153 |
3157 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | 3154 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 int m_numCommitsDeferred; | 3227 int m_numCommitsDeferred; |
3231 int m_numCompleteCommits; | 3228 int m_numCompleteCommits; |
3232 }; | 3229 }; |
3233 | 3230 |
3234 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) | 3231 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) |
3235 { | 3232 { |
3236 runTest(true); | 3233 runTest(true); |
3237 } | 3234 } |
3238 | 3235 |
3239 } // namespace | 3236 } // namespace |
OLD | NEW |