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