| 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // a while, we do eventually force a draw. | 644 // a while, we do eventually force a draw. |
| 645 class LayerTreeHostTestCheckerboardDoesNotStarveDraws : public LayerTreeHostTest
{ | 645 class LayerTreeHostTestCheckerboardDoesNotStarveDraws : public LayerTreeHostTest
{ |
| 646 public: | 646 public: |
| 647 LayerTreeHostTestCheckerboardDoesNotStarveDraws() | 647 LayerTreeHostTestCheckerboardDoesNotStarveDraws() |
| 648 : m_startedAnimating(false) | 648 : m_startedAnimating(false) |
| 649 { | 649 { |
| 650 } | 650 } |
| 651 | 651 |
| 652 virtual void beginTest() OVERRIDE | 652 virtual void beginTest() OVERRIDE |
| 653 { | 653 { |
| 654 postAddAnimationToMainThread(); | 654 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); |
| 655 } | 655 } |
| 656 | 656 |
| 657 virtual void afterTest() OVERRIDE | 657 virtual void afterTest() OVERRIDE |
| 658 { | 658 { |
| 659 } | 659 } |
| 660 | 660 |
| 661 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE | 661 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE |
| 662 { | 662 { |
| 663 m_startedAnimating = true; | 663 m_startedAnimating = true; |
| 664 } | 664 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 687 // Ensures that animations continue to be ticked when we are backgrounded. | 687 // Ensures that animations continue to be ticked when we are backgrounded. |
| 688 class LayerTreeHostTestTickAnimationWhileBackgrounded : public LayerTreeHostTest
{ | 688 class LayerTreeHostTestTickAnimationWhileBackgrounded : public LayerTreeHostTest
{ |
| 689 public: | 689 public: |
| 690 LayerTreeHostTestTickAnimationWhileBackgrounded() | 690 LayerTreeHostTestTickAnimationWhileBackgrounded() |
| 691 : m_numAnimates(0) | 691 : m_numAnimates(0) |
| 692 { | 692 { |
| 693 } | 693 } |
| 694 | 694 |
| 695 virtual void beginTest() OVERRIDE | 695 virtual void beginTest() OVERRIDE |
| 696 { | 696 { |
| 697 postAddAnimationToMainThread(); | 697 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); |
| 698 } | 698 } |
| 699 | 699 |
| 700 // Use willAnimateLayers to set visible false before the animation runs and | 700 // Use willAnimateLayers to set visible false before the animation runs and |
| 701 // 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 |
| 702 // mode. | 702 // mode. |
| 703 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::T
imeTicks monotonicTime) OVERRIDE | 703 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::T
imeTicks monotonicTime) OVERRIDE |
| 704 { | 704 { |
| 705 if (m_numAnimates < 2) { | 705 if (m_numAnimates < 2) { |
| 706 if (!m_numAnimates) { | 706 if (!m_numAnimates) { |
| 707 // 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. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 725 | 725 |
| 726 // Ensures that animations continue to be ticked when we are backgrounded. | 726 // Ensures that animations continue to be ticked when we are backgrounded. |
| 727 class LayerTreeHostTestAddAnimationWithTimingFunction : public LayerTreeHostTest
{ | 727 class LayerTreeHostTestAddAnimationWithTimingFunction : public LayerTreeHostTest
{ |
| 728 public: | 728 public: |
| 729 LayerTreeHostTestAddAnimationWithTimingFunction() | 729 LayerTreeHostTestAddAnimationWithTimingFunction() |
| 730 { | 730 { |
| 731 } | 731 } |
| 732 | 732 |
| 733 virtual void beginTest() OVERRIDE | 733 virtual void beginTest() OVERRIDE |
| 734 { | 734 { |
| 735 postAddAnimationToMainThread(); | 735 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); |
| 736 } | 736 } |
| 737 | 737 |
| 738 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE | 738 virtual void animateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::TimeT
icks monotonicTime) OVERRIDE |
| 739 { | 739 { |
| 740 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); |
| 741 if (!animation) | 741 if (!animation) |
| 742 return; | 742 return; |
| 743 const FloatAnimationCurve* curve = animation->curve()->toFloatAnimationC
urve(); | 743 const FloatAnimationCurve* curve = animation->curve()->toFloatAnimationC
urve(); |
| 744 float startOpacity = curve->getValue(0); | 744 float startOpacity = curve->getValue(0); |
| 745 float endOpacity = curve->getValue(curve->duration()); | 745 float endOpacity = curve->getValue(curve->duration()); |
| 746 float linearlyInterpolatedOpacity = 0.25 * endOpacity + 0.75 * startOpac
ity; | 746 float linearlyInterpolatedOpacity = 0.25 * endOpacity + 0.75 * startOpac
ity; |
| 747 double time = curve->duration() * 0.25; | 747 double time = curve->duration() * 0.25; |
| 748 // 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, |
| 749 // then the linearly interpolated opacity would be different because of
the | 749 // then the linearly interpolated opacity would be different because of
the |
| 750 // default ease timing function. | 750 // default ease timing function. |
| 751 EXPECT_FLOAT_EQ(linearlyInterpolatedOpacity, curve->getValue(time)); | 751 EXPECT_FLOAT_EQ(linearlyInterpolatedOpacity, curve->getValue(time)); |
| 752 endTest(); | 752 endTest(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 virtual void afterTest() OVERRIDE | 755 virtual void afterTest() OVERRIDE |
| 756 { | 756 { |
| 757 } | 757 } |
| 758 | 758 |
| 759 private: | 759 private: |
| 760 }; | 760 }; |
| 761 | 761 |
| 762 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAddAnimationWithTimingFunction) | 762 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAddAnimationWithTimingFunction) |
| 763 | 763 |
| 764 // Ensures that when opacity is being animated, this value does not cause the su
btree to be skipped. | |
| 765 class LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity : public LayerTreeHost
Test { | |
| 766 public: | |
| 767 LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity() | |
| 768 { | |
| 769 } | |
| 770 | |
| 771 virtual void beginTest() OVERRIDE | |
| 772 { | |
| 773 m_layerTreeHost->rootLayer()->setDrawOpacity(1); | |
| 774 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10)); | |
| 775 m_layerTreeHost->rootLayer()->setOpacity(0); | |
| 776 postAddAnimationToMainThread(); | |
| 777 } | |
| 778 | |
| 779 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE | |
| 780 { | |
| 781 // If the subtree was skipped when preparing to draw, the layer's draw o
pacity | |
| 782 // will not have been updated. It should be set to 0 due to the animatio
n. | |
| 783 // Without the animation, the layer will be skipped since it has zero op
acity. | |
| 784 EXPECT_EQ(0, m_layerTreeHost->rootLayer()->drawOpacity()); | |
| 785 endTest(); | |
| 786 } | |
| 787 | |
| 788 virtual void afterTest() OVERRIDE | |
| 789 { | |
| 790 } | |
| 791 }; | |
| 792 | |
| 793 TEST_F(LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity, runMultiThread) | |
| 794 { | |
| 795 runTest(true); | |
| 796 } | |
| 797 | |
| 798 // Ensures that main thread animations have their start times synchronized with
impl thread animations. | 764 // Ensures that main thread animations have their start times synchronized with
impl thread animations. |
| 799 class LayerTreeHostTestSynchronizeAnimationStartTimes : public LayerTreeHostTest
{ | 765 class LayerTreeHostTestSynchronizeAnimationStartTimes : public LayerTreeHostTest
{ |
| 800 public: | 766 public: |
| 801 LayerTreeHostTestSynchronizeAnimationStartTimes() | 767 LayerTreeHostTestSynchronizeAnimationStartTimes() |
| 802 : m_layerTreeHostImpl(0) | 768 : m_layerTreeHostImpl(0) |
| 803 { | 769 { |
| 804 } | 770 } |
| 805 | 771 |
| 806 virtual void beginTest() OVERRIDE | 772 virtual void beginTest() OVERRIDE |
| 807 { | 773 { |
| 808 postAddAnimationToMainThread(); | 774 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); |
| 809 } | 775 } |
| 810 | 776 |
| 811 // This is guaranteed to be called before CCLayerTreeHostImpl::animateLayers
. | 777 // This is guaranteed to be called before CCLayerTreeHostImpl::animateLayers
. |
| 812 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::T
imeTicks monotonicTime) OVERRIDE | 778 virtual void willAnimateLayers(LayerTreeHostImpl* layerTreeHostImpl, base::T
imeTicks monotonicTime) OVERRIDE |
| 813 { | 779 { |
| 814 m_layerTreeHostImpl = layerTreeHostImpl; | 780 m_layerTreeHostImpl = layerTreeHostImpl; |
| 815 } | 781 } |
| 816 | 782 |
| 817 virtual void notifyAnimationStarted(double time) OVERRIDE | 783 virtual void notifyAnimationStarted(double time) OVERRIDE |
| 818 { | 784 { |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 private: | 1199 private: |
| 1234 TestOpacityChangeLayerDelegate m_testOpacityChangeDelegate; | 1200 TestOpacityChangeLayerDelegate m_testOpacityChangeDelegate; |
| 1235 scoped_refptr<ContentLayerWithUpdateTracking> m_updateCheckLayer; | 1201 scoped_refptr<ContentLayerWithUpdateTracking> m_updateCheckLayer; |
| 1236 }; | 1202 }; |
| 1237 | 1203 |
| 1238 TEST_F(LayerTreeHostTestOpacityChange, runMultiThread) | 1204 TEST_F(LayerTreeHostTestOpacityChange, runMultiThread) |
| 1239 { | 1205 { |
| 1240 runTest(true); | 1206 runTest(true); |
| 1241 } | 1207 } |
| 1242 | 1208 |
| 1209 // Ensures that when opacity is being animated, this value does not cause the su
btree to be skipped. |
| 1210 class LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity : public LayerTreeHost
Test { |
| 1211 public: |
| 1212 LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity() |
| 1213 : m_testOpacityChangeDelegate(this) |
| 1214 , m_updateCheckLayer(ContentLayerWithUpdateTracking::create(&m_testOpaci
tyChangeDelegate)) |
| 1215 { |
| 1216 } |
| 1217 |
| 1218 virtual void beginTest() OVERRIDE |
| 1219 { |
| 1220 m_layerTreeHost->setViewportSize(IntSize(10, 10), IntSize(10, 10)); |
| 1221 m_layerTreeHost->rootLayer()->addChild(m_updateCheckLayer); |
| 1222 m_updateCheckLayer->setOpacity(0); |
| 1223 m_updateCheckLayer->setDrawOpacity(0); |
| 1224 postAddAnimationToMainThread(m_updateCheckLayer.get()); |
| 1225 } |
| 1226 |
| 1227 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE |
| 1228 { |
| 1229 endTest(); |
| 1230 } |
| 1231 |
| 1232 virtual void afterTest() OVERRIDE |
| 1233 { |
| 1234 // update() should have been called once, proving that the layer was not
skipped. |
| 1235 EXPECT_EQ(1, m_updateCheckLayer->paintContentsCount()); |
| 1236 |
| 1237 // clear m_updateCheckLayer so LayerTreeHost dies. |
| 1238 m_updateCheckLayer = NULL; |
| 1239 } |
| 1240 |
| 1241 private: |
| 1242 TestOpacityChangeLayerDelegate m_testOpacityChangeDelegate; |
| 1243 scoped_refptr<ContentLayerWithUpdateTracking> m_updateCheckLayer; |
| 1244 }; |
| 1245 |
| 1246 TEST_F(LayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity, runMultiThread) |
| 1247 { |
| 1248 runTest(true); |
| 1249 } |
| 1250 |
| 1243 class MockContentLayerClient : public ContentLayerClient { | 1251 class MockContentLayerClient : public ContentLayerClient { |
| 1244 public: | 1252 public: |
| 1245 bool drawsContent() const { return true; } | 1253 bool drawsContent() const { return true; } |
| 1246 MOCK_CONST_METHOD0(preserves3D, bool()); | 1254 MOCK_CONST_METHOD0(preserves3D, bool()); |
| 1247 void paintContents(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { } | 1255 void paintContents(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { } |
| 1248 void notifySyncRequired() { } | 1256 void notifySyncRequired() { } |
| 1249 }; | 1257 }; |
| 1250 | 1258 |
| 1251 class NoScaleContentLayer : public ContentLayer { | 1259 class NoScaleContentLayer : public ContentLayer { |
| 1252 public: | 1260 public: |
| (...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3227 int m_numCommitsDeferred; | 3235 int m_numCommitsDeferred; |
| 3228 int m_numCompleteCommits; | 3236 int m_numCompleteCommits; |
| 3229 }; | 3237 }; |
| 3230 | 3238 |
| 3231 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) | 3239 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) |
| 3232 { | 3240 { |
| 3233 runTest(true); | 3241 runTest(true); |
| 3234 } | 3242 } |
| 3235 | 3243 |
| 3236 } // namespace | 3244 } // namespace |
| OLD | NEW |