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

Side by Side Diff: cc/layers/texture_layer_unittest.cc

Issue 23530003: cc: Block commit on activate by setting a flag on LayerTreeHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blockcommit: fix flake Created 7 years, 3 months 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/layers/texture_layer.cc ('k') | cc/layers/tiled_layer.h » ('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 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 <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/thread.h"
12 #include "base/time/time.h"
11 #include "cc/debug/test_web_graphics_context_3d.h" 13 #include "cc/debug/test_web_graphics_context_3d.h"
12 #include "cc/layers/texture_layer_client.h" 14 #include "cc/layers/texture_layer_client.h"
13 #include "cc/layers/texture_layer_impl.h" 15 #include "cc/layers/texture_layer_impl.h"
14 #include "cc/resources/returned_resource.h" 16 #include "cc/resources/returned_resource.h"
15 #include "cc/test/fake_impl_proxy.h" 17 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_client.h" 18 #include "cc/test/fake_layer_tree_host_client.h"
17 #include "cc/test/fake_layer_tree_host_impl.h" 19 #include "cc/test/fake_layer_tree_host_impl.h"
18 #include "cc/test/fake_output_surface.h" 20 #include "cc/test/fake_output_surface.h"
19 #include "cc/test/layer_test_common.h" 21 #include "cc/test/layer_test_common.h"
20 #include "cc/test/layer_tree_test.h" 22 #include "cc/test/layer_tree_test.h"
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 base::ThreadChecker main_thread_; 856 base::ThreadChecker main_thread_;
855 int callback_count_; 857 int callback_count_;
856 int commit_count_; 858 int commit_count_;
857 scoped_refptr<Layer> root_; 859 scoped_refptr<Layer> root_;
858 scoped_refptr<TextureLayer> layer_; 860 scoped_refptr<TextureLayer> layer_;
859 }; 861 };
860 862
861 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 863 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
862 TextureLayerImplWithMailboxThreadedCallback); 864 TextureLayerImplWithMailboxThreadedCallback);
863 865
866
867 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest,
868 public TextureLayerClient {
869 protected:
870 TextureLayerNoMailboxIsActivatedDuringCommit()
871 : wait_thread_("WAIT"),
872 wait_event_(false, false) {
873 wait_thread_.Start();
874 }
875
876 virtual void BeginTest() OVERRIDE {
877 activate_count_ = 0;
878
879 gfx::Size bounds(100, 100);
880 root_ = Layer::Create();
881 root_->SetAnchorPoint(gfx::PointF());
882 root_->SetBounds(bounds);
883
884 layer_ = TextureLayer::Create(this);
885 layer_->SetIsDrawable(true);
886 layer_->SetAnchorPoint(gfx::PointF());
887 layer_->SetBounds(bounds);
888
889 root_->AddChild(layer_);
890 layer_tree_host()->SetRootLayer(root_);
891 layer_tree_host()->SetViewportSize(bounds);
892
893 PostSetNeedsCommitToMainThread();
894 }
895
896 // TextureLayerClient implementation.
897 virtual unsigned PrepareTexture() OVERRIDE {
898 return OffscreenContextProviderForMainThread()
899 ->Context3d()->createTexture();
900 }
901 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE {
902 return OffscreenContextProviderForMainThread()->Context3d();
903 }
904 virtual bool PrepareTextureMailbox(TextureMailbox* mailbox,
905 bool use_shared_memory) OVERRIDE {
906 return false;
907 }
908
909 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
910 // Slow down activation so the main thread DidCommit() will run if
911 // not blocked.
912 wait_thread_.message_loop()->PostDelayedTask(
913 FROM_HERE,
914 base::Bind(&base::WaitableEvent::Signal,
915 base::Unretained(&wait_event_)),
916 base::TimeDelta::FromMilliseconds(10));
917 wait_event_.Wait();
918
919 base::AutoLock lock(activate_lock_);
920 ++activate_count_;
921 }
922
923 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
924 // The main thread is awake now, and will run DidCommit() immediately.
925 // Run DidActivate() afterwards by posting it now.
926 proxy()->MainThreadTaskRunner()->PostTask(
927 FROM_HERE,
928 base::Bind(&TextureLayerNoMailboxIsActivatedDuringCommit::DidActivate,
929 base::Unretained(this)));
930 }
931
932 void DidActivate() {
933 base::AutoLock lock(activate_lock_);
934 switch (activate_count_) {
935 case 1:
936 // The first texture has been activated. Invalidate the layer so it
937 // grabs a new texture id from the client.
938 layer_->SetNeedsDisplay();
939 // So this commit number should complete after the second activate.
940 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
941 break;
942 case 2:
943 // The second mailbox has been activated. Remove the layer from
944 // the tree to cause another commit/activation. The commit should
945 // finish *after* the layer is removed from the active tree.
946 layer_->RemoveFromParent();
947 // So this commit number should complete after the third activate.
948 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
949 break;
950 case 3:
951 EndTest();
952 break;
953 }
954 }
955
956 virtual void DidCommit() OVERRIDE {
957 switch (layer_tree_host()->source_frame_number()) {
958 case 2: {
959 // The activate for the 2nd texture should have happened before now.
960 base::AutoLock lock(activate_lock_);
961 EXPECT_EQ(2, activate_count_);
962 break;
963 }
964 case 3: {
965 // The activate to remove the layer should have happened before now.
966 base::AutoLock lock(activate_lock_);
967 EXPECT_EQ(3, activate_count_);
968 break;
969 }
970 }
971 }
972
973
974 virtual void AfterTest() OVERRIDE {}
975
976 base::Thread wait_thread_;
977 base::WaitableEvent wait_event_;
978 base::Lock activate_lock_;
979 int activate_count_;
980 int activate_commit_;
981 scoped_refptr<Layer> root_;
982 scoped_refptr<TextureLayer> layer_;
983 };
984
985 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
986 TextureLayerNoMailboxIsActivatedDuringCommit);
987
988 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest {
989 protected:
990 TextureLayerMailboxIsActivatedDuringCommit()
991 : wait_thread_("WAIT"),
992 wait_event_(false, false) {
993 wait_thread_.Start();
994 }
995
996 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {}
997
998 void SetMailbox(char mailbox_char) {
999 TextureMailbox mailbox(
1000 std::string(64, mailbox_char),
1001 base::Bind(
1002 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback));
1003 layer_->SetTextureMailbox(mailbox);
1004 }
1005
1006 virtual void BeginTest() OVERRIDE {
1007 activate_count_ = 0;
1008
1009 gfx::Size bounds(100, 100);
1010 root_ = Layer::Create();
1011 root_->SetAnchorPoint(gfx::PointF());
1012 root_->SetBounds(bounds);
1013
1014 layer_ = TextureLayer::CreateForMailbox(NULL);
1015 layer_->SetIsDrawable(true);
1016 layer_->SetAnchorPoint(gfx::PointF());
1017 layer_->SetBounds(bounds);
1018
1019 root_->AddChild(layer_);
1020 layer_tree_host()->SetRootLayer(root_);
1021 layer_tree_host()->SetViewportSize(bounds);
1022 SetMailbox('1');
1023
1024 PostSetNeedsCommitToMainThread();
1025 }
1026
1027 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1028 // Slow down activation so the main thread DidCommit() will run if
1029 // not blocked.
1030 wait_thread_.message_loop()->PostDelayedTask(
1031 FROM_HERE,
1032 base::Bind(&base::WaitableEvent::Signal,
1033 base::Unretained(&wait_event_)),
1034 base::TimeDelta::FromMilliseconds(10));
1035 wait_event_.Wait();
1036
1037 base::AutoLock lock(activate_lock_);
1038 ++activate_count_;
1039 }
1040
1041 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1042 // The main thread is awake now, and will run DidCommit() immediately.
1043 // Run DidActivate() afterwards by posting it now.
1044 proxy()->MainThreadTaskRunner()->PostTask(
1045 FROM_HERE,
1046 base::Bind(&TextureLayerMailboxIsActivatedDuringCommit::DidActivate,
1047 base::Unretained(this)));
1048 }
1049
1050 void DidActivate() {
1051 base::AutoLock lock(activate_lock_);
1052 switch (activate_count_) {
1053 case 1:
1054 // The first mailbox has been activated. Set a new mailbox, and
1055 // expect the next commit to finish *after* it is activated.
1056 SetMailbox('2');
1057 // So this commit number should complete after the second activate.
1058 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
1059 break;
1060 case 2:
1061 // The second mailbox has been activated. Remove the layer from
1062 // the tree to cause another commit/activation. The commit should
1063 // finish *after* the layer is removed from the active tree.
1064 layer_->RemoveFromParent();
1065 // So this commit number should complete after the third activate.
1066 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
1067 break;
1068 case 3:
1069 EndTest();
1070 break;
1071 }
1072 }
1073
1074 virtual void DidCommit() OVERRIDE {
1075 switch (layer_tree_host()->source_frame_number()) {
1076 case 2: {
1077 // The activate for the 2nd mailbox should have happened before now.
1078 base::AutoLock lock(activate_lock_);
1079 EXPECT_EQ(2, activate_count_);
1080 break;
1081 }
1082 case 3: {
1083 // The activate to remove the layer should have happened before now.
1084 base::AutoLock lock(activate_lock_);
1085 EXPECT_EQ(3, activate_count_);
1086 break;
1087 }
1088 }
1089 }
1090
1091
1092 virtual void AfterTest() OVERRIDE {}
1093
1094 base::Thread wait_thread_;
1095 base::WaitableEvent wait_event_;
1096 base::Lock activate_lock_;
1097 int activate_count_;
1098 scoped_refptr<Layer> root_;
1099 scoped_refptr<TextureLayer> layer_;
1100 };
1101
1102 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1103 TextureLayerMailboxIsActivatedDuringCommit);
1104
864 class TextureLayerImplWithMailboxTest : public TextureLayerTest { 1105 class TextureLayerImplWithMailboxTest : public TextureLayerTest {
865 protected: 1106 protected:
866 TextureLayerImplWithMailboxTest() 1107 TextureLayerImplWithMailboxTest()
867 : fake_client_( 1108 : fake_client_(
868 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {} 1109 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {}
869 1110
870 virtual void SetUp() { 1111 virtual void SetUp() {
871 TextureLayerTest::SetUp(); 1112 TextureLayerTest::SetUp();
872 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); 1113 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_));
873 EXPECT_TRUE(host_impl_.InitializeRenderer(CreateFakeOutputSurface())); 1114 EXPECT_TRUE(host_impl_.InitializeRenderer(CreateFakeOutputSurface()));
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 int callback_count_; 1672 int callback_count_;
1432 scoped_refptr<Layer> root_; 1673 scoped_refptr<Layer> root_;
1433 scoped_refptr<TextureLayer> layer_; 1674 scoped_refptr<TextureLayer> layer_;
1434 }; 1675 };
1435 1676
1436 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 1677 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1437 TextureLayerWithMailboxImplThreadDeleted); 1678 TextureLayerWithMailboxImplThreadDeleted);
1438 1679
1439 } // namespace 1680 } // namespace
1440 } // namespace cc 1681 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/texture_layer.cc ('k') | cc/layers/tiled_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698