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/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_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/fake_picture_layer.h" | 10 #include "cc/test/fake_picture_layer.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 grand_child->SetBounds(gfx::Size(5, 5)); | 34 grand_child->SetBounds(gfx::Size(5, 5)); |
35 child->AddChild(grand_child); | 35 child->AddChild(grand_child); |
36 | 36 |
37 layer_tree_host()->SetRootLayer(root); | 37 layer_tree_host()->SetRootLayer(root); |
38 LayerTreeHostCopyRequestTest::SetupTree(); | 38 LayerTreeHostCopyRequestTest::SetupTree(); |
39 client_.set_bounds(root->bounds()); | 39 client_.set_bounds(root->bounds()); |
40 } | 40 } |
41 | 41 |
42 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 42 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
43 | 43 |
44 void DidCommitAndDrawFrame() override { WaitForCallback(); } | 44 void DidCommit() override { WaitForCallback(); } |
45 | 45 |
46 void WaitForCallback() { | 46 void WaitForCallback() { |
47 base::MessageLoop::current()->PostTask( | 47 base::MessageLoop::current()->PostTask( |
48 FROM_HERE, | 48 FROM_HERE, |
49 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests::NextStep, | 49 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests::NextStep, |
50 base::Unretained(this))); | 50 base::Unretained(this))); |
51 } | 51 } |
52 | 52 |
53 void NextStep() { | 53 void NextStep() { |
54 int frame = layer_tree_host()->source_frame_number(); | 54 int frame = layer_tree_host()->source_frame_number(); |
55 switch (frame) { | 55 switch (frame) { |
56 case 1: | 56 case 1: |
57 child->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 57 child->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
58 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: | 58 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: |
59 CopyOutputCallback, | 59 CopyOutputCallback, |
60 base::Unretained(this), 0))); | 60 base::Unretained(this), 0))); |
61 EXPECT_EQ(0u, callbacks_.size()); | 61 EXPECT_EQ(0u, callbacks_.size()); |
62 break; | 62 break; |
63 case 2: | 63 case 2: |
| 64 // This commit is triggered by the copy request having been completed. |
| 65 break; |
| 66 case 3: |
64 if (callbacks_.size() < 1u) { | 67 if (callbacks_.size() < 1u) { |
65 WaitForCallback(); | 68 WaitForCallback(); |
66 return; | 69 return; |
67 } | 70 } |
68 EXPECT_EQ(1u, callbacks_.size()); | 71 EXPECT_EQ(1u, callbacks_.size()); |
69 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); | 72 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); |
70 | 73 |
71 child->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 74 child->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
72 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: | 75 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: |
73 CopyOutputCallback, | 76 CopyOutputCallback, |
74 base::Unretained(this), 1))); | 77 base::Unretained(this), 1))); |
75 root->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 78 root->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
76 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: | 79 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: |
77 CopyOutputCallback, | 80 CopyOutputCallback, |
78 base::Unretained(this), 2))); | 81 base::Unretained(this), 2))); |
79 grand_child->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 82 grand_child->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
80 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: | 83 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests:: |
81 CopyOutputCallback, | 84 CopyOutputCallback, |
82 base::Unretained(this), 3))); | 85 base::Unretained(this), 3))); |
83 EXPECT_EQ(1u, callbacks_.size()); | 86 EXPECT_EQ(1u, callbacks_.size()); |
84 break; | 87 break; |
85 case 3: | 88 case 4: |
| 89 // This commit is triggered by the copy request having been completed. |
| 90 break; |
| 91 case 5: |
86 if (callbacks_.size() < 4u) { | 92 if (callbacks_.size() < 4u) { |
87 WaitForCallback(); | 93 WaitForCallback(); |
88 return; | 94 return; |
89 } | 95 } |
90 EXPECT_EQ(4u, callbacks_.size()); | 96 EXPECT_EQ(4u, callbacks_.size()); |
91 | 97 |
92 // The |child| was copied to a bitmap and passed back in Case 1. | 98 // The |child| was copied to a bitmap and passed back in Case 1. |
93 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); | 99 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); |
94 | 100 |
95 // The |child| was copied to a bitmap and passed back in Case 2. | 101 // The |child| was copied to a bitmap and passed back in Case 2. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 use_gl_renderer_ = false; | 174 use_gl_renderer_ = false; |
169 RunTest(false, false); | 175 RunTest(false, false); |
170 } | 176 } |
171 | 177 |
172 TEST_F(LayerTreeHostCopyRequestTestMultipleRequests, | 178 TEST_F(LayerTreeHostCopyRequestTestMultipleRequests, |
173 SoftwareRenderer_RunMultiThread) { | 179 SoftwareRenderer_RunMultiThread) { |
174 use_gl_renderer_ = false; | 180 use_gl_renderer_ = false; |
175 RunTest(true, false); | 181 RunTest(true, false); |
176 } | 182 } |
177 | 183 |
| 184 // TODO(crbug.com/564832): Remove this test when the workaround it tests is no |
| 185 // longer needed. |
| 186 class LayerTreeHostCopyRequestCompletionCausesCommit |
| 187 : public LayerTreeHostCopyRequestTest { |
| 188 protected: |
| 189 void SetupTree() override { |
| 190 root_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 191 root_->SetBounds(gfx::Size(20, 20)); |
| 192 |
| 193 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 194 layer_->SetBounds(gfx::Size(15, 15)); |
| 195 root_->AddChild(layer_); |
| 196 |
| 197 layer_tree_host()->SetRootLayer(root_); |
| 198 LayerTreeHostCopyRequestTest::SetupTree(); |
| 199 client_.set_bounds(root_->bounds()); |
| 200 } |
| 201 |
| 202 void BeginTest() override { |
| 203 callback_count_ = 0; |
| 204 PostSetNeedsCommitToMainThread(); |
| 205 } |
| 206 |
| 207 void DidCommit() override { |
| 208 int frame = layer_tree_host()->source_frame_number(); |
| 209 switch (frame) { |
| 210 case 1: |
| 211 layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
| 212 base::Bind(&LayerTreeHostCopyRequestCompletionCausesCommit:: |
| 213 CopyOutputCallback, |
| 214 base::Unretained(this)))); |
| 215 EXPECT_EQ(0, callback_count_); |
| 216 break; |
| 217 case 2: |
| 218 // This commit was triggered by the copy request. |
| 219 break; |
| 220 case 3: |
| 221 // This commit was triggered by the completion of the copy request. |
| 222 EXPECT_EQ(1, callback_count_); |
| 223 EndTest(); |
| 224 break; |
| 225 } |
| 226 } |
| 227 |
| 228 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 229 EXPECT_FALSE(result->IsEmpty()); |
| 230 ++callback_count_; |
| 231 } |
| 232 |
| 233 void AfterTest() override {} |
| 234 |
| 235 int callback_count_; |
| 236 FakeContentLayerClient client_; |
| 237 scoped_refptr<FakePictureLayer> root_; |
| 238 scoped_refptr<FakePictureLayer> layer_; |
| 239 }; |
| 240 |
| 241 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 242 LayerTreeHostCopyRequestCompletionCausesCommit); |
| 243 |
178 class LayerTreeHostCopyRequestTestLayerDestroyed | 244 class LayerTreeHostCopyRequestTestLayerDestroyed |
179 : public LayerTreeHostCopyRequestTest { | 245 : public LayerTreeHostCopyRequestTest { |
180 protected: | 246 protected: |
181 void SetupTree() override { | 247 void SetupTree() override { |
182 root_ = FakePictureLayer::Create(layer_settings(), &client_); | 248 root_ = FakePictureLayer::Create(layer_settings(), &client_); |
183 root_->SetBounds(gfx::Size(20, 20)); | 249 root_->SetBounds(gfx::Size(20, 20)); |
184 | 250 |
185 main_destroyed_ = FakePictureLayer::Create(layer_settings(), &client_); | 251 main_destroyed_ = FakePictureLayer::Create(layer_settings(), &client_); |
186 main_destroyed_->SetBounds(gfx::Size(15, 15)); | 252 main_destroyed_->SetBounds(gfx::Size(15, 15)); |
187 root_->AddChild(main_destroyed_); | 253 root_->AddChild(main_destroyed_); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 LayerImpl* parent = grand_parent->children()[0].get(); | 486 LayerImpl* parent = grand_parent->children()[0].get(); |
421 LayerImpl* copy_layer = parent->children()[0].get(); | 487 LayerImpl* copy_layer = parent->children()[0].get(); |
422 | 488 |
423 // |parent| owns a surface, but it was hidden and not part of the copy | 489 // |parent| owns a surface, but it was hidden and not part of the copy |
424 // request so it should not allocate any resource. | 490 // request so it should not allocate any resource. |
425 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( | 491 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( |
426 parent->render_surface()->GetRenderPassId())); | 492 parent->render_surface()->GetRenderPassId())); |
427 | 493 |
428 // |copy_layer| should have been rendered to a texture since it was needed | 494 // |copy_layer| should have been rendered to a texture since it was needed |
429 // for a copy request. | 495 // for a copy request. |
430 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( | 496 if (did_draw_) { |
431 copy_layer->render_surface()->GetRenderPassId())); | 497 // TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy |
| 498 // completion. This can be removed when the extra commit is removed. |
| 499 EXPECT_FALSE(copy_layer->render_surface()); |
| 500 } else { |
| 501 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( |
| 502 copy_layer->render_surface()->GetRenderPassId())); |
| 503 } |
432 | 504 |
433 did_draw_ = true; | 505 did_draw_ = true; |
434 } | 506 } |
435 | 507 |
436 void AfterTest() override { EXPECT_TRUE(did_draw_); } | 508 void AfterTest() override { EXPECT_TRUE(did_draw_); } |
437 | 509 |
438 FakeContentLayerClient client_; | 510 FakeContentLayerClient client_; |
439 bool did_draw_; | 511 bool did_draw_; |
440 scoped_refptr<FakePictureLayer> root_; | 512 scoped_refptr<FakePictureLayer> root_; |
441 scoped_refptr<FakePictureLayer> grand_parent_layer_; | 513 scoped_refptr<FakePictureLayer> grand_parent_layer_; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 | 860 |
789 void BeginTest() override { | 861 void BeginTest() override { |
790 num_textures_without_readback_ = 0; | 862 num_textures_without_readback_ = 0; |
791 num_textures_with_readback_ = 0; | 863 num_textures_with_readback_ = 0; |
792 waited_sync_token_after_readback_.Clear(); | 864 waited_sync_token_after_readback_.Clear(); |
793 PostSetNeedsCommitToMainThread(); | 865 PostSetNeedsCommitToMainThread(); |
794 } | 866 } |
795 | 867 |
796 virtual void RequestCopy(Layer* layer) = 0; | 868 virtual void RequestCopy(Layer* layer) = 0; |
797 | 869 |
798 void DidCommitAndDrawFrame() override { | 870 void DidCommit() override { |
799 switch (layer_tree_host()->source_frame_number()) { | 871 switch (layer_tree_host()->source_frame_number()) { |
800 case 1: | 872 case 1: |
801 // The layers have been pushed to the impl side. The layer textures have | 873 // The layers have been pushed to the impl side. The layer textures have |
802 // been allocated. | 874 // been allocated. |
803 RequestCopy(copy_layer_.get()); | 875 RequestCopy(copy_layer_.get()); |
804 break; | 876 break; |
805 } | 877 } |
806 } | 878 } |
807 | 879 |
808 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { | 880 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 client_.set_bounds(root->bounds()); | 1165 client_.set_bounds(root->bounds()); |
1094 } | 1166 } |
1095 | 1167 |
1096 void BeginTest() override { | 1168 void BeginTest() override { |
1097 num_draws_ = 0; | 1169 num_draws_ = 0; |
1098 copy_happened_ = false; | 1170 copy_happened_ = false; |
1099 draw_happened_ = false; | 1171 draw_happened_ = false; |
1100 PostSetNeedsCommitToMainThread(); | 1172 PostSetNeedsCommitToMainThread(); |
1101 } | 1173 } |
1102 | 1174 |
1103 void DidCommitAndDrawFrame() override { | 1175 void DidCommit() override { |
1104 // Send a copy request after the first commit. | 1176 // Send a copy request after the first commit. |
1105 if (layer_tree_host()->source_frame_number() == 1) { | 1177 if (layer_tree_host()->source_frame_number() == 1) { |
1106 child_->RequestCopyOfOutput( | 1178 child_->RequestCopyOfOutput( |
1107 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 1179 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
1108 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest:: | 1180 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest:: |
1109 CopyOutputCallback, | 1181 CopyOutputCallback, |
1110 base::Unretained(this)))); | 1182 base::Unretained(this)))); |
1111 } | 1183 } |
1112 } | 1184 } |
1113 | 1185 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 int num_draws_; | 1259 int num_draws_; |
1188 bool copy_happened_; | 1260 bool copy_happened_; |
1189 bool draw_happened_; | 1261 bool draw_happened_; |
1190 }; | 1262 }; |
1191 | 1263 |
1192 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1264 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1193 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1265 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
1194 | 1266 |
1195 } // namespace | 1267 } // namespace |
1196 } // namespace cc | 1268 } // namespace cc |
OLD | NEW |