OLD | NEW |
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/output/copy_output_request.h" | 6 #include "cc/output/copy_output_request.h" |
6 #include "cc/output/copy_output_result.h" | 7 #include "cc/output/copy_output_result.h" |
7 #include "cc/test/fake_content_layer.h" | 8 #include "cc/test/fake_content_layer.h" |
8 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
9 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/layer_tree_test.h" | 11 #include "cc/test/layer_tree_test.h" |
11 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
12 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
13 | 14 |
14 namespace cc { | 15 namespace cc { |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 | 960 |
960 int callback_count_; | 961 int callback_count_; |
961 FakeContentLayerClient client_; | 962 FakeContentLayerClient client_; |
962 scoped_refptr<FakeContentLayer> root_; | 963 scoped_refptr<FakeContentLayer> root_; |
963 scoped_refptr<FakeContentLayer> copy_layer_; | 964 scoped_refptr<FakeContentLayer> copy_layer_; |
964 }; | 965 }; |
965 | 966 |
966 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 967 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
967 LayerTreeHostCopyRequestTestShutdownBeforeCopy); | 968 LayerTreeHostCopyRequestTestShutdownBeforeCopy); |
968 | 969 |
| 970 class LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest |
| 971 : public LayerTreeHostCopyRequestTest { |
| 972 protected: |
| 973 void SetupTree() override { |
| 974 scoped_refptr<FakeContentLayer> root = FakeContentLayer::Create(&client_); |
| 975 root->SetBounds(gfx::Size(20, 20)); |
| 976 |
| 977 child_ = FakeContentLayer::Create(&client_); |
| 978 child_->SetBounds(gfx::Size(10, 10)); |
| 979 root->AddChild(child_); |
| 980 child_->SetHideLayerAndSubtree(true); |
| 981 |
| 982 layer_tree_host()->SetRootLayer(root); |
| 983 LayerTreeHostCopyRequestTest::SetupTree(); |
| 984 } |
| 985 |
| 986 void BeginTest() override { |
| 987 num_draws_ = 0; |
| 988 copy_happened_ = false; |
| 989 draw_happened_ = false; |
| 990 PostSetNeedsCommitToMainThread(); |
| 991 } |
| 992 |
| 993 void DidCommitAndDrawFrame() override { |
| 994 // Send a copy request after the first commit. |
| 995 if (layer_tree_host()->source_frame_number() == 1) { |
| 996 child_->RequestCopyOfOutput( |
| 997 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 998 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest:: |
| 999 CopyOutputCallback, |
| 1000 base::Unretained(this)))); |
| 1001 } |
| 1002 } |
| 1003 |
| 1004 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 1005 LayerTreeHostImpl::FrameData* frame_data, |
| 1006 DrawResult draw_result) override { |
| 1007 LayerImpl* root = host_impl->active_tree()->root_layer(); |
| 1008 LayerImpl* child = root->children()[0]; |
| 1009 |
| 1010 bool saw_root = false; |
| 1011 bool saw_child = false; |
| 1012 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin( |
| 1013 frame_data->render_surface_layer_list); |
| 1014 it != LayerIterator<LayerImpl>::End( |
| 1015 frame_data->render_surface_layer_list); |
| 1016 ++it) { |
| 1017 if (it.represents_itself()) { |
| 1018 if (*it == root) |
| 1019 saw_root = true; |
| 1020 else if (*it == child) |
| 1021 saw_child = true; |
| 1022 else |
| 1023 NOTREACHED(); |
| 1024 } |
| 1025 } |
| 1026 |
| 1027 ++num_draws_; |
| 1028 // The first draw has no copy request. The 2nd draw has a copy request, the |
| 1029 // 3rd should not again. |
| 1030 switch (num_draws_) { |
| 1031 case 1: |
| 1032 // Only the root layer draws, the child is hidden. |
| 1033 EXPECT_TRUE(saw_root); |
| 1034 EXPECT_FALSE(saw_child); |
| 1035 break; |
| 1036 case 2: |
| 1037 // Copy happening here, the child will draw. |
| 1038 EXPECT_TRUE(saw_root); |
| 1039 EXPECT_TRUE(saw_child); |
| 1040 // Make another draw happen after doing the copy request. |
| 1041 host_impl->SetNeedsRedrawRect(gfx::Rect(1, 1)); |
| 1042 break; |
| 1043 case 3: |
| 1044 // If LayerTreeHostImpl does the wrong thing, it will try to draw the |
| 1045 // layer which had a copy request. But only the root should draw. |
| 1046 EXPECT_TRUE(saw_root); |
| 1047 EXPECT_FALSE(saw_child); |
| 1048 |
| 1049 // End the test! Don't race with copy request callbacks, so post the end |
| 1050 // to the main thread. |
| 1051 draw_happened_ = true; |
| 1052 MainThreadTaskRunner()->PostTask( |
| 1053 FROM_HERE, |
| 1054 base::Bind( |
| 1055 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest:: |
| 1056 TryEndTest, |
| 1057 base::Unretained(this))); |
| 1058 break; |
| 1059 } |
| 1060 return draw_result; |
| 1061 } |
| 1062 |
| 1063 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 1064 EXPECT_FALSE(TestEnded()); |
| 1065 copy_happened_ = true; |
| 1066 TryEndTest(); |
| 1067 } |
| 1068 |
| 1069 void TryEndTest() { |
| 1070 if (draw_happened_ && copy_happened_) |
| 1071 EndTest(); |
| 1072 } |
| 1073 |
| 1074 void AfterTest() override {} |
| 1075 |
| 1076 scoped_refptr<FakeContentLayer> child_; |
| 1077 FakeContentLayerClient client_; |
| 1078 int num_draws_; |
| 1079 bool copy_happened_; |
| 1080 bool draw_happened_; |
| 1081 }; |
| 1082 |
| 1083 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1084 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
| 1085 |
969 } // namespace | 1086 } // namespace |
970 } // namespace cc | 1087 } // namespace cc |
OLD | NEW |