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 "cc/layer.h" | 5 #include "cc/layer.h" |
6 | 6 |
7 #include "cc/keyframed_animation_curve.h" | 7 #include "cc/keyframed_animation_curve.h" |
8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
9 #include "cc/layer_painter.h" | 9 #include "cc/layer_painter.h" |
10 #include "cc/layer_tree_host.h" | 10 #include "cc/layer_tree_host.h" |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 class FakeLayerImplTreeHost : public LayerTreeHost { | 642 class FakeLayerImplTreeHost : public LayerTreeHost { |
643 public: | 643 public: |
644 static scoped_ptr<FakeLayerImplTreeHost> create() | 644 static scoped_ptr<FakeLayerImplTreeHost> create() |
645 { | 645 { |
646 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(LayerTr
eeSettings())); | 646 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(LayerTr
eeSettings())); |
647 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. | 647 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. |
648 host->initialize(scoped_ptr<Thread>(NULL)); | 648 host->initialize(scoped_ptr<Thread>(NULL)); |
649 return host.Pass(); | 649 return host.Pass(); |
650 } | 650 } |
651 | 651 |
| 652 static scoped_ptr<FakeLayerImplTreeHost> create(LayerTreeSettings settings) |
| 653 { |
| 654 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(setting
s)); |
| 655 host->initialize(scoped_ptr<Thread>(NULL)); |
| 656 return host.Pass(); |
| 657 } |
| 658 |
652 private: | 659 private: |
653 FakeLayerImplTreeHost(const LayerTreeSettings& settings) | 660 FakeLayerImplTreeHost(const LayerTreeSettings& settings) |
654 : LayerTreeHost(&m_client, settings) | 661 : LayerTreeHost(&m_client, settings) |
655 { | 662 { |
656 } | 663 } |
657 | 664 |
658 FakeLayerImplTreeHostClient m_client; | 665 FakeLayerImplTreeHostClient m_client; |
659 }; | 666 }; |
660 | 667 |
661 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) | 668 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 static bool addTestAnimation(Layer* layer) | 844 static bool addTestAnimation(Layer* layer) |
838 { | 845 { |
839 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); | 846 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:create()); |
840 curve->addKeyframe(FloatKeyframe::create(0, 0.3f, scoped_ptr<TimingFunction>
())); | 847 curve->addKeyframe(FloatKeyframe::create(0, 0.3f, scoped_ptr<TimingFunction>
())); |
841 curve->addKeyframe(FloatKeyframe::create(1, 0.7f, scoped_ptr<TimingFunction>
())); | 848 curve->addKeyframe(FloatKeyframe::create(1, 0.7f, scoped_ptr<TimingFunction>
())); |
842 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv
e>(), 0, 0, Animation::Opacity)); | 849 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv
e>(), 0, 0, Animation::Opacity)); |
843 | 850 |
844 return layer->addAnimation(animation.Pass()); | 851 return layer->addAnimation(animation.Pass()); |
845 } | 852 } |
846 | 853 |
847 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost) | 854 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutAnimationRegistrar) |
848 { | 855 { |
849 // Currently, WebCore assumes that animations will be started immediately /
very soon | |
850 // if a composited layer's addAnimation() returns true. However, without a l
ayerTreeHost, | |
851 // layers cannot actually animate yet. So, to prevent violating this WebCore
assumption, | |
852 // the animation should not be accepted if the layer doesn't already have a
layerTreeHost. | |
853 | |
854 scoped_refptr<Layer> layer = Layer::create(); | 856 scoped_refptr<Layer> layer = Layer::create(); |
855 | 857 |
856 // Case 1: without a layerTreeHost, the animation should not be accepted. | 858 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the |
857 #if defined(OS_ANDROID) | 859 // animation should not be accepted. |
858 // All animations are enabled on Android to avoid performance regressions. | 860 EXPECT_FALSE(addTestAnimation(layer.get())); |
859 // Other platforms will be enabled with http://crbug.com/129683 | 861 |
| 862 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); |
| 863 layer->layerAnimationController()->setAnimationRegistrar(registrar.get()); |
| 864 |
| 865 // Case 2: with an AnimationRegistrar, the animation should be accepted. |
860 EXPECT_TRUE(addTestAnimation(layer.get())); | 866 EXPECT_TRUE(addTestAnimation(layer.get())); |
861 #else | |
862 EXPECT_FALSE(addTestAnimation(layer.get())); | |
863 #endif | |
864 | 867 |
865 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat
e()); | 868 LayerTreeSettings settings; |
| 869 settings.acceleratedAnimationEnabled = false; |
| 870 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat
e(settings)); |
866 layerTreeHost->setRootLayer(layer.get()); | 871 layerTreeHost->setRootLayer(layer.get()); |
867 layer->setLayerTreeHost(layerTreeHost.get()); | 872 layer->setLayerTreeHost(layerTreeHost.get()); |
868 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); | 873 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); |
869 | 874 |
870 // Case 2: with a layerTreeHost, the animation should be accepted. | 875 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the |
871 EXPECT_TRUE(addTestAnimation(layer.get())); | 876 // animation should be rejected. |
| 877 EXPECT_FALSE(addTestAnimation(layer.get())); |
872 } | 878 } |
873 | 879 |
874 } // namespace | 880 } // namespace |
875 } // namespace cc | 881 } // namespace cc |
OLD | NEW |