| 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) OVERRIDE { |
| 981 switch (layer_tree_host()->source_frame_number()) { | 951 switch (host_impl->active_tree()->source_frame_number()) { |
| 982 case 2: { | 952 case 2: { |
| 983 // The activate for the 2nd texture should have happened before now. | 953 // The activate for the 2nd texture should have happened before now. |
| 984 base::AutoLock lock(activate_lock_); | |
| 985 EXPECT_EQ(2, activate_count_); | 954 EXPECT_EQ(2, activate_count_); |
| 986 break; | 955 break; |
| 987 } | 956 } |
| 988 case 3: { | 957 case 3: { |
| 989 // The activate to remove the layer should have happened before now. | 958 // The activate to remove the layer should have happened before now. |
| 990 base::AutoLock lock(activate_lock_); | |
| 991 EXPECT_EQ(3, activate_count_); | 959 EXPECT_EQ(3, activate_count_); |
| 992 break; | 960 break; |
| 993 } | 961 } |
| 994 } | 962 } |
| 995 } | 963 } |
| 996 | 964 |
| 997 | |
| 998 virtual void AfterTest() OVERRIDE {} | 965 virtual void AfterTest() OVERRIDE {} |
| 999 | 966 |
| 1000 base::Thread wait_thread_; | |
| 1001 base::WaitableEvent wait_event_; | |
| 1002 base::Lock activate_lock_; | |
| 1003 unsigned texture_; | 967 unsigned texture_; |
| 1004 int activate_count_; | 968 int activate_count_; |
| 1005 scoped_refptr<Layer> root_; | 969 scoped_refptr<Layer> root_; |
| 1006 scoped_refptr<TextureLayer> layer_; | 970 scoped_refptr<TextureLayer> layer_; |
| 1007 }; | 971 }; |
| 1008 | 972 |
| 1009 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 973 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1010 TextureLayerNoMailboxIsActivatedDuringCommit); | 974 TextureLayerNoMailboxIsActivatedDuringCommit); |
| 1011 | 975 |
| 1012 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 976 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
| 1013 protected: | 977 protected: |
| 1014 TextureLayerMailboxIsActivatedDuringCommit() | 978 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
| 1015 : wait_thread_("WAIT"), | |
| 1016 wait_event_(false, false) { | |
| 1017 wait_thread_.Start(); | |
| 1018 } | |
| 1019 | 979 |
| 1020 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} | 980 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} |
| 1021 | 981 |
| 1022 void SetMailbox(char mailbox_char) { | 982 void SetMailbox(char mailbox_char) { |
| 1023 TextureMailbox mailbox(std::string(64, mailbox_char)); | 983 TextureMailbox mailbox(std::string(64, mailbox_char)); |
| 1024 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 984 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 1025 base::Bind( | 985 base::Bind( |
| 1026 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); | 986 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); |
| 1027 layer_->SetTextureMailbox(mailbox, callback.Pass()); | 987 layer_->SetTextureMailbox(mailbox, callback.Pass()); |
| 1028 } | 988 } |
| 1029 | 989 |
| 1030 virtual void BeginTest() OVERRIDE { | 990 virtual void BeginTest() OVERRIDE { |
| 1031 activate_count_ = 0; | |
| 1032 | |
| 1033 gfx::Size bounds(100, 100); | 991 gfx::Size bounds(100, 100); |
| 1034 root_ = Layer::Create(); | 992 root_ = Layer::Create(); |
| 1035 root_->SetAnchorPoint(gfx::PointF()); | 993 root_->SetAnchorPoint(gfx::PointF()); |
| 1036 root_->SetBounds(bounds); | 994 root_->SetBounds(bounds); |
| 1037 | 995 |
| 1038 layer_ = TextureLayer::CreateForMailbox(NULL); | 996 layer_ = TextureLayer::CreateForMailbox(NULL); |
| 1039 layer_->SetIsDrawable(true); | 997 layer_->SetIsDrawable(true); |
| 1040 layer_->SetAnchorPoint(gfx::PointF()); | 998 layer_->SetAnchorPoint(gfx::PointF()); |
| 1041 layer_->SetBounds(bounds); | 999 layer_->SetBounds(bounds); |
| 1042 | 1000 |
| 1043 root_->AddChild(layer_); | 1001 root_->AddChild(layer_); |
| 1044 layer_tree_host()->SetRootLayer(root_); | 1002 layer_tree_host()->SetRootLayer(root_); |
| 1045 layer_tree_host()->SetViewportSize(bounds); | 1003 layer_tree_host()->SetViewportSize(bounds); |
| 1046 SetMailbox('1'); | 1004 SetMailbox('1'); |
| 1047 | 1005 |
| 1048 PostSetNeedsCommitToMainThread(); | 1006 PostSetNeedsCommitToMainThread(); |
| 1049 } | 1007 } |
| 1050 | 1008 |
| 1051 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1009 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_; | 1010 ++activate_count_; |
| 1063 } | 1011 } |
| 1064 | 1012 |
| 1065 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1013 virtual void DidCommit() OVERRIDE { |
| 1066 // The main thread is awake now, and will run DidCommit() immediately. | 1014 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: | 1015 case 1: |
| 1078 // The first mailbox has been activated. Set a new mailbox, and | 1016 // The first mailbox has been activated. Set a new mailbox, and |
| 1079 // expect the next commit to finish *after* it is activated. | 1017 // expect the next commit to finish *after* it is activated. |
| 1080 SetMailbox('2'); | 1018 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; | 1019 break; |
| 1084 case 2: | 1020 case 2: |
| 1085 // The second mailbox has been activated. Remove the layer from | 1021 // The second mailbox has been activated. Remove the layer from |
| 1086 // the tree to cause another commit/activation. The commit should | 1022 // the tree to cause another commit/activation. The commit should |
| 1087 // finish *after* the layer is removed from the active tree. | 1023 // finish *after* the layer is removed from the active tree. |
| 1088 layer_->RemoveFromParent(); | 1024 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; | 1025 break; |
| 1092 case 3: | 1026 case 3: |
| 1093 EndTest(); | 1027 EndTest(); |
| 1094 break; | 1028 break; |
| 1095 } | 1029 } |
| 1096 } | 1030 } |
| 1097 | 1031 |
| 1098 virtual void DidCommit() OVERRIDE { | 1032 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1099 switch (layer_tree_host()->source_frame_number()) { | 1033 switch (host_impl->active_tree()->source_frame_number()) { |
| 1100 case 2: { | 1034 case 2: { |
| 1101 // The activate for the 2nd mailbox should have happened before now. | 1035 // The activate for the 2nd mailbox should have happened before now. |
| 1102 base::AutoLock lock(activate_lock_); | |
| 1103 EXPECT_EQ(2, activate_count_); | 1036 EXPECT_EQ(2, activate_count_); |
| 1104 break; | 1037 break; |
| 1105 } | 1038 } |
| 1106 case 3: { | 1039 case 3: { |
| 1107 // The activate to remove the layer should have happened before now. | 1040 // The activate to remove the layer should have happened before now. |
| 1108 base::AutoLock lock(activate_lock_); | |
| 1109 EXPECT_EQ(3, activate_count_); | 1041 EXPECT_EQ(3, activate_count_); |
| 1110 break; | 1042 break; |
| 1111 } | 1043 } |
| 1112 } | 1044 } |
| 1113 } | 1045 } |
| 1114 | 1046 |
| 1115 | 1047 |
| 1116 virtual void AfterTest() OVERRIDE {} | 1048 virtual void AfterTest() OVERRIDE {} |
| 1117 | 1049 |
| 1118 base::Thread wait_thread_; | |
| 1119 base::WaitableEvent wait_event_; | |
| 1120 base::Lock activate_lock_; | |
| 1121 int activate_count_; | 1050 int activate_count_; |
| 1122 scoped_refptr<Layer> root_; | 1051 scoped_refptr<Layer> root_; |
| 1123 scoped_refptr<TextureLayer> layer_; | 1052 scoped_refptr<TextureLayer> layer_; |
| 1124 }; | 1053 }; |
| 1125 | 1054 |
| 1126 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1055 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1127 TextureLayerMailboxIsActivatedDuringCommit); | 1056 TextureLayerMailboxIsActivatedDuringCommit); |
| 1128 | 1057 |
| 1129 class TextureLayerImplWithMailboxTest : public TextureLayerTest { | 1058 class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
| 1130 protected: | 1059 protected: |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 int callback_count_; | 2084 int callback_count_; |
| 2156 scoped_refptr<Layer> root_; | 2085 scoped_refptr<Layer> root_; |
| 2157 scoped_refptr<TextureLayer> layer_; | 2086 scoped_refptr<TextureLayer> layer_; |
| 2158 }; | 2087 }; |
| 2159 | 2088 |
| 2160 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2089 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 2161 TextureLayerWithMailboxImplThreadDeleted); | 2090 TextureLayerWithMailboxImplThreadDeleted); |
| 2162 | 2091 |
| 2163 } // namespace | 2092 } // namespace |
| 2164 } // namespace cc | 2093 } // namespace cc |
| OLD | NEW |