Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: cc/layer_unittest.cc

Issue 11344004: Remove WebKit::Platform dependencies from cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix webkit_compositor_bindings_unittests Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/prioritized_texture_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 7 #include "cc/layer.h"
8 8
9 #include "cc/keyframed_animation_curve.h" 9 #include "cc/keyframed_animation_curve.h"
10 #include "cc/layer_impl.h" 10 #include "cc/layer_impl.h"
11 #include "cc/layer_painter.h" 11 #include "cc/layer_painter.h"
12 #include "cc/layer_tree_host.h" 12 #include "cc/layer_tree_host.h"
13 #include "cc/settings.h" 13 #include "cc/settings.h"
14 #include "cc/single_thread_proxy.h" 14 #include "cc/single_thread_proxy.h"
15 #include "cc/test/fake_layer_tree_host_client.h" 15 #include "cc/test/fake_layer_tree_host_client.h"
16 #include "cc/test/geometry_test_utils.h" 16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/test/test_common.h" 17 #include "cc/test/test_common.h"
18 #include "cc/test/web_compositor_initializer.h"
19 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include <public/WebTransformationMatrix.h> 20 #include <public/WebTransformationMatrix.h>
22 21
23 using namespace cc; 22 using namespace cc;
24 using namespace WebKitTests; 23 using namespace WebKitTests;
25 using WebKit::WebTransformationMatrix; 24 using WebKit::WebTransformationMatrix;
26 using ::testing::Mock; 25 using ::testing::Mock;
27 using ::testing::_; 26 using ::testing::_;
28 using ::testing::AtLeast; 27 using ::testing::AtLeast;
(...skipping 23 matching lines...) Expand all
52 51
53 class MockLayerPainter : public LayerPainter { 52 class MockLayerPainter : public LayerPainter {
54 public: 53 public:
55 virtual void paint(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { } 54 virtual void paint(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { }
56 }; 55 };
57 56
58 57
59 class LayerTest : public testing::Test { 58 class LayerTest : public testing::Test {
60 public: 59 public:
61 LayerTest() 60 LayerTest()
62 : m_compositorInitializer(0)
63 { 61 {
64 } 62 }
65 63
66 protected: 64 protected:
67 virtual void SetUp() 65 virtual void SetUp()
68 { 66 {
69 m_layerTreeHost = scoped_ptr<MockLayerImplTreeHost>(new MockLayerImplTre eHost); 67 m_layerTreeHost = scoped_ptr<MockLayerImplTreeHost>(new MockLayerImplTre eHost);
70 } 68 }
71 69
72 virtual void TearDown() 70 virtual void TearDown()
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 m_child1->addChild(m_grandChild2); 126 m_child1->addChild(m_grandChild2);
129 m_child2->addChild(m_grandChild3); 127 m_child2->addChild(m_grandChild3);
130 128
131 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 129 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
132 130
133 verifyTestTreeInitialState(); 131 verifyTestTreeInitialState();
134 } 132 }
135 133
136 scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost; 134 scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost;
137 scoped_refptr<Layer> m_parent, m_child1, m_child2, m_child3, m_grandChild1, m_grandChild2, m_grandChild3; 135 scoped_refptr<Layer> m_parent, m_child1, m_child2, m_child3, m_grandChild1, m_grandChild2, m_grandChild3;
138 WebCompositorInitializer m_compositorInitializer;
139 }; 136 };
140 137
141 TEST_F(LayerTest, basicCreateAndDestroy) 138 TEST_F(LayerTest, basicCreateAndDestroy)
142 { 139 {
143 scoped_refptr<Layer> testLayer = Layer::create(); 140 scoped_refptr<Layer> testLayer = Layer::create();
144 ASSERT_TRUE(testLayer); 141 ASSERT_TRUE(testLayer);
145 142
146 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); 143 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0);
147 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 144 testLayer->setLayerTreeHost(m_layerTreeHost.get());
148 } 145 }
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (layer->maskLayer()) 628 if (layer->maskLayer())
632 assertLayerTreeHostMatchesForSubtree(layer->maskLayer(), host); 629 assertLayerTreeHostMatchesForSubtree(layer->maskLayer(), host);
633 630
634 if (layer->replicaLayer()) 631 if (layer->replicaLayer())
635 assertLayerTreeHostMatchesForSubtree(layer->replicaLayer(), host); 632 assertLayerTreeHostMatchesForSubtree(layer->replicaLayer(), host);
636 } 633 }
637 634
638 635
639 TEST(LayerLayerTreeHostTest, enteringTree) 636 TEST(LayerLayerTreeHostTest, enteringTree)
640 { 637 {
641 WebCompositorInitializer compositorInitializer(0);
642 scoped_refptr<Layer> parent = Layer::create(); 638 scoped_refptr<Layer> parent = Layer::create();
643 scoped_refptr<Layer> child = Layer::create(); 639 scoped_refptr<Layer> child = Layer::create();
644 scoped_refptr<Layer> mask = Layer::create(); 640 scoped_refptr<Layer> mask = Layer::create();
645 scoped_refptr<Layer> replica = Layer::create(); 641 scoped_refptr<Layer> replica = Layer::create();
646 scoped_refptr<Layer> replicaMask = Layer::create(); 642 scoped_refptr<Layer> replicaMask = Layer::create();
647 643
648 // Set up a detached tree of layers. The host pointer should be nil for thes e layers. 644 // Set up a detached tree of layers. The host pointer should be nil for thes e layers.
649 parent->addChild(child); 645 parent->addChild(child);
650 child->setMaskLayer(mask.get()); 646 child->setMaskLayer(mask.get());
651 child->setReplicaLayer(replica.get()); 647 child->setReplicaLayer(replica.get());
652 replica->setMaskLayer(mask.get()); 648 replica->setMaskLayer(mask.get());
653 649
654 assertLayerTreeHostMatchesForSubtree(parent.get(), 0); 650 assertLayerTreeHostMatchesForSubtree(parent.get(), 0);
655 651
656 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 652 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e());
657 // Setting the root layer should set the host pointer for all layers in the tree. 653 // Setting the root layer should set the host pointer for all layers in the tree.
658 layerTreeHost->setRootLayer(parent.get()); 654 layerTreeHost->setRootLayer(parent.get());
659 655
660 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); 656 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
661 657
662 // Clearing the root layer should also clear out the host pointers for all l ayers in the tree. 658 // Clearing the root layer should also clear out the host pointers for all l ayers in the tree.
663 layerTreeHost->setRootLayer(0); 659 layerTreeHost->setRootLayer(0);
664 660
665 assertLayerTreeHostMatchesForSubtree(parent.get(), 0); 661 assertLayerTreeHostMatchesForSubtree(parent.get(), 0);
666 } 662 }
667 663
668 TEST(LayerLayerTreeHostTest, addingLayerSubtree) 664 TEST(LayerLayerTreeHostTest, addingLayerSubtree)
669 { 665 {
670 WebCompositorInitializer compositorInitializer(0);
671 scoped_refptr<Layer> parent = Layer::create(); 666 scoped_refptr<Layer> parent = Layer::create();
672 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 667 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e());
673 668
674 layerTreeHost->setRootLayer(parent.get()); 669 layerTreeHost->setRootLayer(parent.get());
675 670
676 EXPECT_EQ(parent->layerTreeHost(), layerTreeHost.get()); 671 EXPECT_EQ(parent->layerTreeHost(), layerTreeHost.get());
677 672
678 // Adding a subtree to a layer already associated with a host should set the host pointer on all layers in that subtree. 673 // Adding a subtree to a layer already associated with a host should set the host pointer on all layers in that subtree.
679 scoped_refptr<Layer> child = Layer::create(); 674 scoped_refptr<Layer> child = Layer::create();
680 scoped_refptr<Layer> grandChild = Layer::create(); 675 scoped_refptr<Layer> grandChild = Layer::create();
681 child->addChild(grandChild); 676 child->addChild(grandChild);
682 677
683 // Masks, replicas, and replica masks should pick up the new host too. 678 // Masks, replicas, and replica masks should pick up the new host too.
684 scoped_refptr<Layer> childMask = Layer::create(); 679 scoped_refptr<Layer> childMask = Layer::create();
685 child->setMaskLayer(childMask.get()); 680 child->setMaskLayer(childMask.get());
686 scoped_refptr<Layer> childReplica = Layer::create(); 681 scoped_refptr<Layer> childReplica = Layer::create();
687 child->setReplicaLayer(childReplica.get()); 682 child->setReplicaLayer(childReplica.get());
688 scoped_refptr<Layer> childReplicaMask = Layer::create(); 683 scoped_refptr<Layer> childReplicaMask = Layer::create();
689 childReplica->setMaskLayer(childReplicaMask.get()); 684 childReplica->setMaskLayer(childReplicaMask.get());
690 685
691 parent->addChild(child); 686 parent->addChild(child);
692 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); 687 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
693 688
694 layerTreeHost->setRootLayer(0); 689 layerTreeHost->setRootLayer(0);
695 } 690 }
696 691
697 TEST(LayerLayerTreeHostTest, changeHost) 692 TEST(LayerLayerTreeHostTest, changeHost)
698 { 693 {
699 WebCompositorInitializer compositorInitializer(0);
700 scoped_refptr<Layer> parent = Layer::create(); 694 scoped_refptr<Layer> parent = Layer::create();
701 scoped_refptr<Layer> child = Layer::create(); 695 scoped_refptr<Layer> child = Layer::create();
702 scoped_refptr<Layer> mask = Layer::create(); 696 scoped_refptr<Layer> mask = Layer::create();
703 scoped_refptr<Layer> replica = Layer::create(); 697 scoped_refptr<Layer> replica = Layer::create();
704 scoped_refptr<Layer> replicaMask = Layer::create(); 698 scoped_refptr<Layer> replicaMask = Layer::create();
705 699
706 // Same setup as the previous test. 700 // Same setup as the previous test.
707 parent->addChild(child); 701 parent->addChild(child);
708 child->setMaskLayer(mask.get()); 702 child->setMaskLayer(mask.get());
709 child->setReplicaLayer(replica.get()); 703 child->setReplicaLayer(replica.get());
710 replica->setMaskLayer(mask.get()); 704 replica->setMaskLayer(mask.get());
711 705
712 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: create()); 706 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: create());
713 firstLayerTreeHost->setRootLayer(parent.get()); 707 firstLayerTreeHost->setRootLayer(parent.get());
714 708
715 assertLayerTreeHostMatchesForSubtree(parent.get(), firstLayerTreeHost.get()) ; 709 assertLayerTreeHostMatchesForSubtree(parent.get(), firstLayerTreeHost.get()) ;
716 710
717 // Now re-root the tree to a new host (simulating what we do on a context lo st event). 711 // Now re-root the tree to a new host (simulating what we do on a context lo st event).
718 // This should update the host pointers for all layers in the tree. 712 // This should update the host pointers for all layers in the tree.
719 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :create()); 713 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :create());
720 secondLayerTreeHost->setRootLayer(parent.get()); 714 secondLayerTreeHost->setRootLayer(parent.get());
721 715
722 assertLayerTreeHostMatchesForSubtree(parent.get(), secondLayerTreeHost.get() ); 716 assertLayerTreeHostMatchesForSubtree(parent.get(), secondLayerTreeHost.get() );
723 717
724 secondLayerTreeHost->setRootLayer(0); 718 secondLayerTreeHost->setRootLayer(0);
725 } 719 }
726 720
727 TEST(LayerLayerTreeHostTest, changeHostInSubtree) 721 TEST(LayerLayerTreeHostTest, changeHostInSubtree)
728 { 722 {
729 WebCompositorInitializer compositorInitializer(0);
730 scoped_refptr<Layer> firstParent = Layer::create(); 723 scoped_refptr<Layer> firstParent = Layer::create();
731 scoped_refptr<Layer> firstChild = Layer::create(); 724 scoped_refptr<Layer> firstChild = Layer::create();
732 scoped_refptr<Layer> secondParent = Layer::create(); 725 scoped_refptr<Layer> secondParent = Layer::create();
733 scoped_refptr<Layer> secondChild = Layer::create(); 726 scoped_refptr<Layer> secondChild = Layer::create();
734 scoped_refptr<Layer> secondGrandChild = Layer::create(); 727 scoped_refptr<Layer> secondGrandChild = Layer::create();
735 728
736 // First put all children under the first parent and set the first host. 729 // First put all children under the first parent and set the first host.
737 firstParent->addChild(firstChild); 730 firstParent->addChild(firstChild);
738 secondChild->addChild(secondGrandChild); 731 secondChild->addChild(secondGrandChild);
739 firstParent->addChild(secondChild); 732 firstParent->addChild(secondChild);
(...skipping 13 matching lines...) Expand all
753 EXPECT_EQ(secondLayerTreeHost.get(), secondChild->layerTreeHost()); 746 EXPECT_EQ(secondLayerTreeHost.get(), secondChild->layerTreeHost());
754 EXPECT_EQ(secondLayerTreeHost.get(), secondGrandChild->layerTreeHost()); 747 EXPECT_EQ(secondLayerTreeHost.get(), secondGrandChild->layerTreeHost());
755 748
756 // Test over, cleanup time. 749 // Test over, cleanup time.
757 firstLayerTreeHost->setRootLayer(0); 750 firstLayerTreeHost->setRootLayer(0);
758 secondLayerTreeHost->setRootLayer(0); 751 secondLayerTreeHost->setRootLayer(0);
759 } 752 }
760 753
761 TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer) 754 TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer)
762 { 755 {
763 WebCompositorInitializer compositorInitializer(0);
764 scoped_refptr<Layer> parent = Layer::create(); 756 scoped_refptr<Layer> parent = Layer::create();
765 scoped_refptr<Layer> mask = Layer::create(); 757 scoped_refptr<Layer> mask = Layer::create();
766 scoped_refptr<Layer> replica = Layer::create(); 758 scoped_refptr<Layer> replica = Layer::create();
767 scoped_refptr<Layer> maskChild = Layer::create(); 759 scoped_refptr<Layer> maskChild = Layer::create();
768 scoped_refptr<Layer> replicaChild = Layer::create(); 760 scoped_refptr<Layer> replicaChild = Layer::create();
769 scoped_refptr<Layer> maskReplacement = Layer::create(); 761 scoped_refptr<Layer> maskReplacement = Layer::create();
770 scoped_refptr<Layer> replicaReplacement = Layer::create(); 762 scoped_refptr<Layer> replicaReplacement = Layer::create();
771 763
772 parent->setMaskLayer(mask.get()); 764 parent->setMaskLayer(mask.get());
773 parent->setReplicaLayer(replica.get()); 765 parent->setReplicaLayer(replica.get());
(...skipping 14 matching lines...) Expand all
788 parent->setReplicaLayer(replicaReplacement.get()); 780 parent->setReplicaLayer(replicaReplacement.get());
789 EXPECT_EQ(0, replica->layerTreeHost()); 781 EXPECT_EQ(0, replica->layerTreeHost());
790 EXPECT_EQ(0, replicaChild->layerTreeHost()); 782 EXPECT_EQ(0, replicaChild->layerTreeHost());
791 783
792 // Test over, cleanup time. 784 // Test over, cleanup time.
793 layerTreeHost->setRootLayer(0); 785 layerTreeHost->setRootLayer(0);
794 } 786 }
795 787
796 TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer) 788 TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer)
797 { 789 {
798 WebCompositorInitializer compositorInitializer(0);
799 scoped_refptr<Layer> root = Layer::create(); 790 scoped_refptr<Layer> root = Layer::create();
800 scoped_refptr<Layer> child = Layer::create(); 791 scoped_refptr<Layer> child = Layer::create();
801 root->addChild(child); 792 root->addChild(child);
802 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 793 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e());
803 layerTreeHost->setRootLayer(root); 794 layerTreeHost->setRootLayer(root);
804 } 795 }
805 796
806 static bool addTestAnimation(Layer* layer) 797 static bool addTestAnimation(Layer* layer)
807 { 798 {
808 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :create()); 799 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :create());
809 curve->addKeyframe(FloatKeyframe::create(0, 0.3f, scoped_ptr<TimingFunction> ())); 800 curve->addKeyframe(FloatKeyframe::create(0, 0.3f, scoped_ptr<TimingFunction> ()));
810 curve->addKeyframe(FloatKeyframe::create(1, 0.7f, scoped_ptr<TimingFunction> ())); 801 curve->addKeyframe(FloatKeyframe::create(1, 0.7f, scoped_ptr<TimingFunction> ()));
811 scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<A nimationCurve>(), 0, 0, ActiveAnimation::Opacity)); 802 scoped_ptr<ActiveAnimation> animation(ActiveAnimation::create(curve.PassAs<A nimationCurve>(), 0, 0, ActiveAnimation::Opacity));
812 803
813 return layer->addAnimation(animation.Pass()); 804 return layer->addAnimation(animation.Pass());
814 } 805 }
815 806
816 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost) 807 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost)
817 { 808 {
818 // Currently, WebCore assumes that animations will be started immediately / very soon 809 // Currently, WebCore assumes that animations will be started immediately / very soon
819 // if a composited layer's addAnimation() returns true. However, without a l ayerTreeHost, 810 // if a composited layer's addAnimation() returns true. However, without a l ayerTreeHost,
820 // layers cannot actually animate yet. So, to prevent violating this WebCore assumption, 811 // layers cannot actually animate yet. So, to prevent violating this WebCore assumption,
821 // the animation should not be accepted if the layer doesn't already have a layerTreeHost. 812 // the animation should not be accepted if the layer doesn't already have a layerTreeHost.
822 813
823 ScopedSettings scopedSettings; 814 ScopedSettings scopedSettings;
824 Settings::setAcceleratedAnimationEnabled(true); 815 Settings::setAcceleratedAnimationEnabled(true);
825 816
826 WebCompositorInitializer compositorInitializer(0);
827 scoped_refptr<Layer> layer = Layer::create(); 817 scoped_refptr<Layer> layer = Layer::create();
828 818
829 // Case 1: without a layerTreeHost, the animation should not be accepted. 819 // Case 1: without a layerTreeHost, the animation should not be accepted.
830 EXPECT_FALSE(addTestAnimation(layer.get())); 820 EXPECT_FALSE(addTestAnimation(layer.get()));
831 821
832 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 822 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e());
833 layerTreeHost->setRootLayer(layer.get()); 823 layerTreeHost->setRootLayer(layer.get());
834 layer->setLayerTreeHost(layerTreeHost.get()); 824 layer->setLayerTreeHost(layerTreeHost.get());
835 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); 825 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get());
836 826
(...skipping 16 matching lines...) Expand all
853 scoped_refptr<MockLayer> layer(new MockLayer); 843 scoped_refptr<MockLayer> layer(new MockLayer);
854 EXPECT_FALSE(layer->needsDisplay()); 844 EXPECT_FALSE(layer->needsDisplay());
855 layer->setBounds(IntSize(0, 10)); 845 layer->setBounds(IntSize(0, 10));
856 EXPECT_FALSE(layer->needsDisplay()); 846 EXPECT_FALSE(layer->needsDisplay());
857 layer->setBounds(IntSize(10, 10)); 847 layer->setBounds(IntSize(10, 10));
858 EXPECT_TRUE(layer->needsDisplay()); 848 EXPECT_TRUE(layer->needsDisplay());
859 } 849 }
860 850
861 851
862 } // namespace 852 } // namespace
OLDNEW
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/prioritized_texture_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698