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

Side by Side Diff: cc/trees/layer_tree_host_unittest_copyrequest.cc

Issue 888663003: cc: Fix flakiness in LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « cc/test/layer_tree_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/layer_iterator.h" 5 #include "cc/layers/layer_iterator.h"
6 #include "cc/output/copy_output_request.h" 6 #include "cc/output/copy_output_request.h"
7 #include "cc/output/copy_output_result.h" 7 #include "cc/output/copy_output_result.h"
8 #include "cc/test/fake_content_layer.h" 8 #include "cc/test/fake_content_layer.h"
9 #include "cc/test/fake_content_layer_client.h" 9 #include "cc/test/fake_content_layer_client.h"
10 #include "cc/test/fake_output_surface.h" 10 #include "cc/test/fake_output_surface.h"
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 960
961 int callback_count_; 961 int callback_count_;
962 FakeContentLayerClient client_; 962 FakeContentLayerClient client_;
963 scoped_refptr<FakeContentLayer> root_; 963 scoped_refptr<FakeContentLayer> root_;
964 scoped_refptr<FakeContentLayer> copy_layer_; 964 scoped_refptr<FakeContentLayer> copy_layer_;
965 }; 965 };
966 966
967 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 967 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
968 LayerTreeHostCopyRequestTestShutdownBeforeCopy); 968 LayerTreeHostCopyRequestTestShutdownBeforeCopy);
969 969
970 class LayerTreeHostCopyRequestTestMultipleDrawsWithHiddenCopyRequest 970 class LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest
971 : public LayerTreeHostCopyRequestTest { 971 : public LayerTreeHostCopyRequestTest {
972 protected: 972 protected:
973 void SetupTree() override { 973 void SetupTree() override {
974 scoped_refptr<FakeContentLayer> root = FakeContentLayer::Create(&client_); 974 scoped_refptr<FakeContentLayer> root = FakeContentLayer::Create(&client_);
975 root->SetBounds(gfx::Size(20, 20)); 975 root->SetBounds(gfx::Size(20, 20));
976 976
977 child_ = FakeContentLayer::Create(&client_); 977 child_ = FakeContentLayer::Create(&client_);
978 child_->SetBounds(gfx::Size(10, 10)); 978 child_->SetBounds(gfx::Size(10, 10));
979 root->AddChild(child_); 979 root->AddChild(child_);
980 child_->SetHideLayerAndSubtree(true); 980 child_->SetHideLayerAndSubtree(true);
981 981
982 layer_tree_host()->SetRootLayer(root); 982 layer_tree_host()->SetRootLayer(root);
983 LayerTreeHostCopyRequestTest::SetupTree(); 983 LayerTreeHostCopyRequestTest::SetupTree();
984 } 984 }
985 985
986 void BeginTest() override { 986 void BeginTest() override {
987 num_draws_ = 0; 987 num_draws_ = 0;
988 copy_happened_ = false; 988 copy_happened_ = false;
989 draw_happened_ = false;
989 PostSetNeedsCommitToMainThread(); 990 PostSetNeedsCommitToMainThread();
990 } 991 }
991 992
992 void DidCommitAndDrawFrame() override { 993 void DidCommitAndDrawFrame() override {
993 // Send a copy request after the first commit. 994 // Send a copy request after the first commit.
994 if (layer_tree_host()->source_frame_number() == 1) { 995 if (layer_tree_host()->source_frame_number() == 1) {
995 child_->RequestCopyOfOutput( 996 child_->RequestCopyOfOutput(
996 CopyOutputRequest::CreateBitmapRequest(base::Bind( 997 CopyOutputRequest::CreateBitmapRequest(base::Bind(
997 &LayerTreeHostCopyRequestTestMultipleDrawsWithHiddenCopyRequest:: 998 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest::
998 CopyOutputCallback, 999 CopyOutputCallback,
999 base::Unretained(this)))); 1000 base::Unretained(this))));
1000 } 1001 }
1001 } 1002 }
1002 1003
1003 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 1004 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
1004 LayerTreeHostImpl::FrameData* frame_data, 1005 LayerTreeHostImpl::FrameData* frame_data,
1005 DrawResult draw_result) override { 1006 DrawResult draw_result) override {
1006 LayerImpl* root = host_impl->active_tree()->root_layer(); 1007 LayerImpl* root = host_impl->active_tree()->root_layer();
1007 LayerImpl* child = root->children()[0]; 1008 LayerImpl* child = root->children()[0];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 host_impl->SetNeedsRedrawRect(gfx::Rect(1, 1)); 1041 host_impl->SetNeedsRedrawRect(gfx::Rect(1, 1));
1041 break; 1042 break;
1042 case 3: 1043 case 3:
1043 // If LayerTreeHostImpl does the wrong thing, it will try to draw the 1044 // If LayerTreeHostImpl does the wrong thing, it will try to draw the
1044 // layer which had a copy request. But only the root should draw. 1045 // layer which had a copy request. But only the root should draw.
1045 EXPECT_TRUE(saw_root); 1046 EXPECT_TRUE(saw_root);
1046 EXPECT_FALSE(saw_child); 1047 EXPECT_FALSE(saw_child);
1047 1048
1048 // End the test! Don't race with copy request callbacks, so post the end 1049 // End the test! Don't race with copy request callbacks, so post the end
1049 // to the main thread. 1050 // to the main thread.
1050 EXPECT_TRUE(copy_happened_); 1051 draw_happened_ = true;
1051 PostEndTestToMainThread(); 1052 MainThreadTaskRunner()->PostTask(
1053 FROM_HERE,
1054 base::Bind(
1055 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest::
1056 TryEndTest,
1057 base::Unretained(this)));
1052 break; 1058 break;
1053 } 1059 }
1054 return draw_result; 1060 return draw_result;
1055 } 1061 }
1056 1062
1057 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { 1063 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
1058 EXPECT_FALSE(TestEnded()); 1064 EXPECT_FALSE(TestEnded());
1059 copy_happened_ = true; 1065 copy_happened_ = true;
1066 TryEndTest();
1067 }
1068
1069 void TryEndTest() {
1070 if (draw_happened_ && copy_happened_)
1071 EndTest();
1060 } 1072 }
1061 1073
1062 void AfterTest() override {} 1074 void AfterTest() override {}
1063 1075
1064 scoped_refptr<FakeContentLayer> child_; 1076 scoped_refptr<FakeContentLayer> child_;
1065 FakeContentLayerClient client_; 1077 FakeContentLayerClient client_;
1066 int num_draws_; 1078 int num_draws_;
1067 bool copy_happened_; 1079 bool copy_happened_;
1080 bool draw_happened_;
1068 }; 1081 };
1069 1082
1070 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1083 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1071 LayerTreeHostCopyRequestTestMultipleDrawsWithHiddenCopyRequest); 1084 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest);
1072 1085
1073 } // namespace 1086 } // namespace
1074 } // namespace cc 1087 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698