OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 }; | 879 }; |
880 | 880 |
881 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 881 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
882 TextureLayerImplWithMailboxThreadedCallback); | 882 TextureLayerImplWithMailboxThreadedCallback); |
883 | 883 |
884 | 884 |
885 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, | 885 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, |
886 public TextureLayerClient { | 886 public TextureLayerClient { |
887 protected: | 887 protected: |
888 TextureLayerNoMailboxIsActivatedDuringCommit() | 888 TextureLayerNoMailboxIsActivatedDuringCommit() |
889 : wait_thread_("WAIT"), | 889 : texture_(0u), activate_count_(0) {} |
890 wait_event_(false, false), | |
891 texture_(0u) { | |
892 wait_thread_.Start(); | |
893 } | |
894 | 890 |
895 virtual void BeginTest() OVERRIDE { | 891 virtual void BeginTest() OVERRIDE { |
896 activate_count_ = 0; | |
897 | |
898 gfx::Size bounds(100, 100); | 892 gfx::Size bounds(100, 100); |
899 root_ = Layer::Create(); | 893 root_ = Layer::Create(); |
900 root_->SetAnchorPoint(gfx::PointF()); | 894 root_->SetAnchorPoint(gfx::PointF()); |
901 root_->SetBounds(bounds); | 895 root_->SetBounds(bounds); |
902 | 896 |
903 layer_ = TextureLayer::Create(this); | 897 layer_ = TextureLayer::Create(this); |
904 layer_->SetIsDrawable(true); | 898 layer_->SetIsDrawable(true); |
905 layer_->SetAnchorPoint(gfx::PointF()); | 899 layer_->SetAnchorPoint(gfx::PointF()); |
906 layer_->SetBounds(bounds); | 900 layer_->SetBounds(bounds); |
907 | 901 |
(...skipping 16 matching lines...) Expand all Loading... |
924 return texture_; | 918 return texture_; |
925 } | 919 } |
926 virtual bool PrepareTextureMailbox( | 920 virtual bool PrepareTextureMailbox( |
927 TextureMailbox* mailbox, | 921 TextureMailbox* mailbox, |
928 scoped_ptr<SingleReleaseCallback>* release_callback, | 922 scoped_ptr<SingleReleaseCallback>* release_callback, |
929 bool use_shared_memory) OVERRIDE { | 923 bool use_shared_memory) OVERRIDE { |
930 return false; | 924 return false; |
931 } | 925 } |
932 | 926 |
933 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 927 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
934 // Slow down activation so the main thread DidCommit() will run if | |
935 // not blocked. | |
936 wait_thread_.message_loop()->PostDelayedTask( | |
937 FROM_HERE, | |
938 base::Bind(&base::WaitableEvent::Signal, | |
939 base::Unretained(&wait_event_)), | |
940 base::TimeDelta::FromMilliseconds(10)); | |
941 wait_event_.Wait(); | |
942 | |
943 base::AutoLock lock(activate_lock_); | |
944 ++activate_count_; | 928 ++activate_count_; |
945 } | 929 } |
946 | 930 |
947 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 931 virtual void DidCommit() OVERRIDE { |
948 // The main thread is awake now, and will run DidCommit() immediately. | 932 switch (layer_tree_host()->source_frame_number()) { |
949 // Run DidActivate() afterwards by posting it now. | |
950 proxy()->MainThreadTaskRunner()->PostTask( | |
951 FROM_HERE, | |
952 base::Bind(&TextureLayerNoMailboxIsActivatedDuringCommit::DidActivate, | |
953 base::Unretained(this))); | |
954 } | |
955 | |
956 void DidActivate() { | |
957 base::AutoLock lock(activate_lock_); | |
958 switch (activate_count_) { | |
959 case 1: | 933 case 1: |
960 // The first texture has been activated. Invalidate the layer so it | 934 // The first texture has been activated. Invalidate the layer so it |
961 // grabs a new texture id from the client. | 935 // grabs a new texture id from the client. |
962 layer_->SetNeedsDisplay(); | 936 layer_->SetNeedsDisplay(); |
963 // So this commit number should complete after the second activate. | |
964 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | |
965 break; | 937 break; |
966 case 2: | 938 case 2: |
967 // The second mailbox has been activated. Remove the layer from | 939 // The second mailbox has been activated. Remove the layer from |
968 // the tree to cause another commit/activation. The commit should | 940 // the tree to cause another commit/activation. The commit should |
969 // finish *after* the layer is removed from the active tree. | 941 // finish *after* the layer is removed from the active tree. |
970 layer_->RemoveFromParent(); | 942 layer_->RemoveFromParent(); |
971 // So this commit number should complete after the third activate. | |
972 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | |
973 break; | 943 break; |
974 case 3: | 944 case 3: |
975 EndTest(); | 945 EndTest(); |
976 break; | 946 break; |
977 } | 947 } |
978 } | 948 } |
979 | 949 |
980 virtual void DidCommit() OVERRIDE { | 950 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) |
981 switch (layer_tree_host()->source_frame_number()) { | 951 OVERRIDE { |
| 952 switch (host_impl->active_tree()->source_frame_number()) { |
982 case 2: { | 953 case 2: { |
983 // The activate for the 2nd texture should have happened before now. | 954 // The activate for the 2nd texture should have happened before now. |
984 base::AutoLock lock(activate_lock_); | |
985 EXPECT_EQ(2, activate_count_); | 955 EXPECT_EQ(2, activate_count_); |
986 break; | 956 break; |
987 } | 957 } |
988 case 3: { | 958 case 3: { |
989 // The activate to remove the layer should have happened before now. | 959 // The activate to remove the layer should have happened before now. |
990 base::AutoLock lock(activate_lock_); | |
991 EXPECT_EQ(3, activate_count_); | 960 EXPECT_EQ(3, activate_count_); |
992 break; | 961 break; |
993 } | 962 } |
994 } | 963 } |
995 } | 964 } |
996 | 965 |
997 | |
998 virtual void AfterTest() OVERRIDE {} | 966 virtual void AfterTest() OVERRIDE {} |
999 | 967 |
1000 base::Thread wait_thread_; | |
1001 base::WaitableEvent wait_event_; | |
1002 base::Lock activate_lock_; | |
1003 unsigned texture_; | 968 unsigned texture_; |
1004 int activate_count_; | 969 int activate_count_; |
1005 scoped_refptr<Layer> root_; | 970 scoped_refptr<Layer> root_; |
1006 scoped_refptr<TextureLayer> layer_; | 971 scoped_refptr<TextureLayer> layer_; |
1007 }; | 972 }; |
1008 | 973 |
1009 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 974 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1010 TextureLayerNoMailboxIsActivatedDuringCommit); | 975 TextureLayerNoMailboxIsActivatedDuringCommit); |
1011 | 976 |
1012 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 977 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
1013 protected: | 978 protected: |
1014 TextureLayerMailboxIsActivatedDuringCommit() | 979 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
1015 : wait_thread_("WAIT"), | |
1016 wait_event_(false, false) { | |
1017 wait_thread_.Start(); | |
1018 } | |
1019 | 980 |
1020 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} | 981 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} |
1021 | 982 |
1022 void SetMailbox(char mailbox_char) { | 983 void SetMailbox(char mailbox_char) { |
1023 TextureMailbox mailbox(std::string(64, mailbox_char)); | 984 TextureMailbox mailbox(std::string(64, mailbox_char)); |
1024 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 985 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
1025 base::Bind( | 986 base::Bind( |
1026 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); | 987 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); |
1027 layer_->SetTextureMailbox(mailbox, callback.Pass()); | 988 layer_->SetTextureMailbox(mailbox, callback.Pass()); |
1028 } | 989 } |
1029 | 990 |
1030 virtual void BeginTest() OVERRIDE { | 991 virtual void BeginTest() OVERRIDE { |
1031 activate_count_ = 0; | |
1032 | |
1033 gfx::Size bounds(100, 100); | 992 gfx::Size bounds(100, 100); |
1034 root_ = Layer::Create(); | 993 root_ = Layer::Create(); |
1035 root_->SetAnchorPoint(gfx::PointF()); | 994 root_->SetAnchorPoint(gfx::PointF()); |
1036 root_->SetBounds(bounds); | 995 root_->SetBounds(bounds); |
1037 | 996 |
1038 layer_ = TextureLayer::CreateForMailbox(NULL); | 997 layer_ = TextureLayer::CreateForMailbox(NULL); |
1039 layer_->SetIsDrawable(true); | 998 layer_->SetIsDrawable(true); |
1040 layer_->SetAnchorPoint(gfx::PointF()); | 999 layer_->SetAnchorPoint(gfx::PointF()); |
1041 layer_->SetBounds(bounds); | 1000 layer_->SetBounds(bounds); |
1042 | 1001 |
1043 root_->AddChild(layer_); | 1002 root_->AddChild(layer_); |
1044 layer_tree_host()->SetRootLayer(root_); | 1003 layer_tree_host()->SetRootLayer(root_); |
1045 layer_tree_host()->SetViewportSize(bounds); | 1004 layer_tree_host()->SetViewportSize(bounds); |
1046 SetMailbox('1'); | 1005 SetMailbox('1'); |
1047 | 1006 |
1048 PostSetNeedsCommitToMainThread(); | 1007 PostSetNeedsCommitToMainThread(); |
1049 } | 1008 } |
1050 | 1009 |
1051 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1010 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1052 // Slow down activation so the main thread DidCommit() will run if | |
1053 // not blocked. | |
1054 wait_thread_.message_loop()->PostDelayedTask( | |
1055 FROM_HERE, | |
1056 base::Bind(&base::WaitableEvent::Signal, | |
1057 base::Unretained(&wait_event_)), | |
1058 base::TimeDelta::FromMilliseconds(10)); | |
1059 wait_event_.Wait(); | |
1060 | |
1061 base::AutoLock lock(activate_lock_); | |
1062 ++activate_count_; | 1011 ++activate_count_; |
1063 } | 1012 } |
1064 | 1013 |
1065 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1014 virtual void DidCommit() OVERRIDE { |
1066 // The main thread is awake now, and will run DidCommit() immediately. | 1015 switch (layer_tree_host()->source_frame_number()) { |
1067 // Run DidActivate() afterwards by posting it now. | |
1068 proxy()->MainThreadTaskRunner()->PostTask( | |
1069 FROM_HERE, | |
1070 base::Bind(&TextureLayerMailboxIsActivatedDuringCommit::DidActivate, | |
1071 base::Unretained(this))); | |
1072 } | |
1073 | |
1074 void DidActivate() { | |
1075 base::AutoLock lock(activate_lock_); | |
1076 switch (activate_count_) { | |
1077 case 1: | 1016 case 1: |
1078 // The first mailbox has been activated. Set a new mailbox, and | 1017 // The first mailbox has been activated. Set a new mailbox, and |
1079 // expect the next commit to finish *after* it is activated. | 1018 // expect the next commit to finish *after* it is activated. |
1080 SetMailbox('2'); | 1019 SetMailbox('2'); |
1081 // So this commit number should complete after the second activate. | |
1082 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | |
1083 break; | 1020 break; |
1084 case 2: | 1021 case 2: |
1085 // The second mailbox has been activated. Remove the layer from | 1022 // The second mailbox has been activated. Remove the layer from |
1086 // the tree to cause another commit/activation. The commit should | 1023 // the tree to cause another commit/activation. The commit should |
1087 // finish *after* the layer is removed from the active tree. | 1024 // finish *after* the layer is removed from the active tree. |
1088 layer_->RemoveFromParent(); | 1025 layer_->RemoveFromParent(); |
1089 // So this commit number should complete after the third activate. | |
1090 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | |
1091 break; | 1026 break; |
1092 case 3: | 1027 case 3: |
1093 EndTest(); | 1028 EndTest(); |
1094 break; | 1029 break; |
1095 } | 1030 } |
1096 } | 1031 } |
1097 | 1032 |
1098 virtual void DidCommit() OVERRIDE { | 1033 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) |
1099 switch (layer_tree_host()->source_frame_number()) { | 1034 OVERRIDE { |
| 1035 switch (host_impl->active_tree()->source_frame_number()) { |
1100 case 2: { | 1036 case 2: { |
1101 // The activate for the 2nd mailbox should have happened before now. | 1037 // The activate for the 2nd mailbox should have happened before now. |
1102 base::AutoLock lock(activate_lock_); | |
1103 EXPECT_EQ(2, activate_count_); | 1038 EXPECT_EQ(2, activate_count_); |
1104 break; | 1039 break; |
1105 } | 1040 } |
1106 case 3: { | 1041 case 3: { |
1107 // The activate to remove the layer should have happened before now. | 1042 // The activate to remove the layer should have happened before now. |
1108 base::AutoLock lock(activate_lock_); | |
1109 EXPECT_EQ(3, activate_count_); | 1043 EXPECT_EQ(3, activate_count_); |
1110 break; | 1044 break; |
1111 } | 1045 } |
1112 } | 1046 } |
1113 } | 1047 } |
1114 | 1048 |
1115 | 1049 |
1116 virtual void AfterTest() OVERRIDE {} | 1050 virtual void AfterTest() OVERRIDE {} |
1117 | 1051 |
1118 base::Thread wait_thread_; | |
1119 base::WaitableEvent wait_event_; | |
1120 base::Lock activate_lock_; | |
1121 int activate_count_; | 1052 int activate_count_; |
1122 scoped_refptr<Layer> root_; | 1053 scoped_refptr<Layer> root_; |
1123 scoped_refptr<TextureLayer> layer_; | 1054 scoped_refptr<TextureLayer> layer_; |
1124 }; | 1055 }; |
1125 | 1056 |
1126 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1057 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1127 TextureLayerMailboxIsActivatedDuringCommit); | 1058 TextureLayerMailboxIsActivatedDuringCommit); |
1128 | 1059 |
1129 class TextureLayerImplWithMailboxTest : public TextureLayerTest { | 1060 class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
1130 protected: | 1061 protected: |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 int callback_count_; | 2086 int callback_count_; |
2156 scoped_refptr<Layer> root_; | 2087 scoped_refptr<Layer> root_; |
2157 scoped_refptr<TextureLayer> layer_; | 2088 scoped_refptr<TextureLayer> layer_; |
2158 }; | 2089 }; |
2159 | 2090 |
2160 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2091 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
2161 TextureLayerWithMailboxImplThreadDeleted); | 2092 TextureLayerWithMailboxImplThreadDeleted); |
2162 | 2093 |
2163 } // namespace | 2094 } // namespace |
2164 } // namespace cc | 2095 } // namespace cc |
OLD | NEW |