OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 scoped_ptr<Layer> l1(CreateLayer(LAYER_SOLID_COLOR)); | 720 scoped_ptr<Layer> l1(CreateLayer(LAYER_SOLID_COLOR)); |
721 l1->SetFillsBoundsOpaquely(true); | 721 l1->SetFillsBoundsOpaquely(true); |
722 l1->SetForceRenderSurface(true); | 722 l1->SetForceRenderSurface(true); |
723 l1->SetVisible(false); | 723 l1->SetVisible(false); |
724 l1->SetBounds(gfx::Rect(4, 5)); | 724 l1->SetBounds(gfx::Rect(4, 5)); |
725 | 725 |
726 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); | 726 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); |
727 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); | 727 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
728 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); | 728 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
729 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); | 729 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
730 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 730 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
731 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); | 731 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
732 | 732 |
733 cc::Layer* before_layer = l1->cc_layer_for_testing(); | 733 cc::Layer* before_layer = l1->cc_layer_for_testing(); |
734 | 734 |
735 bool callback1_run = false; | 735 bool callback1_run = false; |
736 cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); | 736 cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); |
737 l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( | 737 l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( |
738 base::Bind(ReturnMailbox, &callback1_run)), | 738 base::Bind(ReturnMailbox, &callback1_run)), |
739 gfx::Size(10, 10)); | 739 gfx::Size(10, 10)); |
740 | 740 |
741 EXPECT_NE(before_layer, l1->cc_layer_for_testing()); | 741 EXPECT_NE(before_layer, l1->cc_layer_for_testing()); |
742 | 742 |
743 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); | 743 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); |
744 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); | 744 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
745 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); | 745 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
746 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); | 746 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
747 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 747 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
748 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); | 748 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
749 EXPECT_FALSE(callback1_run); | 749 EXPECT_FALSE(callback1_run); |
750 | 750 |
751 bool callback2_run = false; | 751 bool callback2_run = false; |
752 mailbox = cc::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); | 752 mailbox = cc::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); |
753 l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( | 753 l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( |
754 base::Bind(ReturnMailbox, &callback2_run)), | 754 base::Bind(ReturnMailbox, &callback2_run)), |
755 gfx::Size(10, 10)); | 755 gfx::Size(10, 10)); |
756 EXPECT_TRUE(callback1_run); | 756 EXPECT_TRUE(callback1_run); |
757 EXPECT_FALSE(callback2_run); | 757 EXPECT_FALSE(callback2_run); |
758 | 758 |
759 // Show solid color instead. | 759 // Show solid color instead. |
760 l1->SetShowSolidColorContent(); | 760 l1->SetShowSolidColorContent(); |
761 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); | 761 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); |
762 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); | 762 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
763 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); | 763 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
764 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); | 764 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
765 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 765 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
766 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); | 766 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
767 EXPECT_TRUE(callback2_run); | 767 EXPECT_TRUE(callback2_run); |
768 | 768 |
769 before_layer = l1->cc_layer_for_testing(); | 769 before_layer = l1->cc_layer_for_testing(); |
770 | 770 |
771 // Back to a texture, without changing the bounds of the layer or the texture. | 771 // Back to a texture, without changing the bounds of the layer or the texture. |
772 bool callback3_run = false; | 772 bool callback3_run = false; |
773 mailbox = cc::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); | 773 mailbox = cc::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); |
774 l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( | 774 l1->SetTextureMailbox(mailbox, cc::SingleReleaseCallback::Create( |
775 base::Bind(ReturnMailbox, &callback3_run)), | 775 base::Bind(ReturnMailbox, &callback3_run)), |
776 gfx::Size(10, 10)); | 776 gfx::Size(10, 10)); |
777 | 777 |
778 EXPECT_NE(before_layer, l1->cc_layer_for_testing()); | 778 EXPECT_NE(before_layer, l1->cc_layer_for_testing()); |
779 | 779 |
780 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); | 780 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); |
781 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); | 781 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
782 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); | 782 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
783 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); | 783 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
784 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 784 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
785 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); | 785 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
786 EXPECT_FALSE(callback3_run); | 786 EXPECT_FALSE(callback3_run); |
787 | 787 |
788 // Release the on |l1| mailbox to clean up the test. | 788 // Release the on |l1| mailbox to clean up the test. |
789 l1->SetShowSolidColorContent(); | 789 l1->SetShowSolidColorContent(); |
790 } | 790 } |
791 | 791 |
792 // Various visibile/drawn assertions. | 792 // Various visibile/drawn assertions. |
793 TEST_F(LayerWithNullDelegateTest, Visibility) { | 793 TEST_F(LayerWithNullDelegateTest, Visibility) { |
794 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); | 794 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); |
795 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); | 795 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); |
796 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); | 796 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); |
797 l1->Add(l2.get()); | 797 l1->Add(l2.get()); |
798 l2->Add(l3.get()); | 798 l2->Add(l3.get()); |
799 | 799 |
800 NullLayerDelegate delegate; | 800 NullLayerDelegate delegate; |
801 l1->set_delegate(&delegate); | 801 l1->set_delegate(&delegate); |
802 l2->set_delegate(&delegate); | 802 l2->set_delegate(&delegate); |
803 l3->set_delegate(&delegate); | 803 l3->set_delegate(&delegate); |
804 | 804 |
805 // Layers should initially be drawn. | 805 // Layers should initially be drawn. |
806 EXPECT_TRUE(l1->IsDrawn()); | 806 EXPECT_TRUE(l1->IsDrawn()); |
807 EXPECT_TRUE(l2->IsDrawn()); | 807 EXPECT_TRUE(l2->IsDrawn()); |
808 EXPECT_TRUE(l3->IsDrawn()); | 808 EXPECT_TRUE(l3->IsDrawn()); |
809 EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 809 EXPECT_NE(l1->cc_layer_for_testing()->opacity(), 0.f); |
810 EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); | 810 EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
811 EXPECT_FALSE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); | 811 EXPECT_NE(l3->cc_layer_for_testing()->opacity(), 0.f); |
812 | 812 |
813 compositor()->SetRootLayer(l1.get()); | 813 compositor()->SetRootLayer(l1.get()); |
814 | 814 |
815 Draw(); | 815 Draw(); |
816 | 816 |
817 l1->SetVisible(false); | 817 l1->SetVisible(false); |
818 EXPECT_FALSE(l1->IsDrawn()); | 818 EXPECT_FALSE(l1->IsDrawn()); |
819 EXPECT_FALSE(l2->IsDrawn()); | 819 EXPECT_FALSE(l2->IsDrawn()); |
820 EXPECT_FALSE(l3->IsDrawn()); | 820 EXPECT_FALSE(l3->IsDrawn()); |
821 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 821 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
822 EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); | 822 EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
823 EXPECT_FALSE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); | 823 EXPECT_NE(l3->cc_layer_for_testing()->opacity(), 0.f); |
824 | 824 |
825 l3->SetVisible(false); | 825 l3->SetVisible(false); |
826 EXPECT_FALSE(l1->IsDrawn()); | 826 EXPECT_FALSE(l1->IsDrawn()); |
827 EXPECT_FALSE(l2->IsDrawn()); | 827 EXPECT_FALSE(l2->IsDrawn()); |
828 EXPECT_FALSE(l3->IsDrawn()); | 828 EXPECT_FALSE(l3->IsDrawn()); |
829 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 829 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
830 EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); | 830 EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
831 EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); | 831 EXPECT_EQ(l3->cc_layer_for_testing()->opacity(), 0.f); |
832 | 832 |
833 l1->SetVisible(true); | 833 l1->SetVisible(true); |
834 EXPECT_TRUE(l1->IsDrawn()); | 834 EXPECT_TRUE(l1->IsDrawn()); |
835 EXPECT_TRUE(l2->IsDrawn()); | 835 EXPECT_TRUE(l2->IsDrawn()); |
836 EXPECT_FALSE(l3->IsDrawn()); | 836 EXPECT_FALSE(l3->IsDrawn()); |
837 EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 837 EXPECT_NE(l1->cc_layer_for_testing()->opacity(), 0.f); |
838 EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); | 838 EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
839 EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); | 839 EXPECT_EQ(l3->cc_layer_for_testing()->opacity(), 0.f); |
840 } | |
841 | |
842 TEST_F(LayerWithNullDelegateTest, Opacity) { | |
weiliangc
2016/01/15 19:30:24
Preferably with more descriptive test name.
jaydasika
2016/01/19 20:02:49
Done.
| |
843 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); | |
844 | |
845 NullLayerDelegate delegate; | |
846 l1->set_delegate(&delegate); | |
847 | |
848 // Initially, the layer should be fully opaque. | |
849 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 1.f); | |
850 | |
851 compositor()->SetRootLayer(l1.get()); | |
852 | |
853 Draw(); | |
854 | |
855 // When a layer is invisble, the corresponding cc_layer should be completely | |
856 // transparent, but the ui layer should store the original opacity of cc | |
857 // layer. | |
858 l1->SetVisible(false); | |
859 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); | |
860 EXPECT_EQ(l1->opacity(), 1.f); | |
861 | |
862 // Any changes to opacity when the layer is invisble is cached by the ui | |
863 // layer and set on the corresponding cc layer only when it becomes visible. | |
864 l1->SetOpacity(0.5f); | |
865 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); | |
866 EXPECT_EQ(l1->opacity(), 0.5f); | |
867 l1->SetVisible(true); | |
868 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.5f); | |
869 | |
870 // The original opacity should be restored when invisible layer becomes | |
871 // visible. | |
872 l1->SetOpacity(0.2f); | |
873 l1->SetVisible(false); | |
874 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); | |
875 l1->SetVisible(true); | |
876 EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.2f); | |
840 } | 877 } |
841 | 878 |
842 // Checks that stacking-related methods behave as advertised. | 879 // Checks that stacking-related methods behave as advertised. |
843 TEST_F(LayerWithNullDelegateTest, Stacking) { | 880 TEST_F(LayerWithNullDelegateTest, Stacking) { |
844 scoped_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN)); | 881 scoped_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN)); |
845 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); | 882 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); |
846 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); | 883 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); |
847 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); | 884 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); |
848 l1->set_name("1"); | 885 l1->set_name("1"); |
849 l2->set_name("2"); | 886 l2->set_name("2"); |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1878 root->SetOpacity(0.5f); | 1915 root->SetOpacity(0.5f); |
1879 WaitForSwap(); | 1916 WaitForSwap(); |
1880 EXPECT_EQ(1u, animation_observer.animation_step_count()); | 1917 EXPECT_EQ(1u, animation_observer.animation_step_count()); |
1881 | 1918 |
1882 EXPECT_FALSE(animation_observer.shutdown()); | 1919 EXPECT_FALSE(animation_observer.shutdown()); |
1883 ResetCompositor(); | 1920 ResetCompositor(); |
1884 EXPECT_TRUE(animation_observer.shutdown()); | 1921 EXPECT_TRUE(animation_observer.shutdown()); |
1885 } | 1922 } |
1886 | 1923 |
1887 } // namespace ui | 1924 } // namespace ui |
OLD | NEW |