| 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/output/copy_output_request.h" | 5 #include "cc/output/copy_output_request.h" |
| 6 #include "cc/output/copy_output_result.h" | 6 #include "cc/output/copy_output_result.h" |
| 7 #include "cc/test/fake_content_layer.h" | 7 #include "cc/test/fake_content_layer.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/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 // The layers have been pushed to the impl side. The layer textures have | 579 // The layers have been pushed to the impl side. The layer textures have |
| 580 // been allocated. | 580 // been allocated. |
| 581 | 581 |
| 582 // Request a copy of the layer. This will use another texture. | 582 // Request a copy of the layer. This will use another texture. |
| 583 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( | 583 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 584 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: | 584 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
| 585 CopyOutputCallback, | 585 CopyOutputCallback, |
| 586 base::Unretained(this)))); | 586 base::Unretained(this)))); |
| 587 break; | 587 break; |
| 588 case 4: | 588 case 4: |
| 589 // With SingleThreadProxy it takes two commits to finally swap after a | 589 if (HasImplThread()) |
| 590 // context loss. | 590 CheckAndReleaseCopyOutput(); |
| 591 break; |
| 591 case 5: | 592 case 5: |
| 592 // Now destroy the CopyOutputResult, releasing the texture inside back | 593 // With SingleThreadProxy it takes two commits to finally swap after a |
| 593 // to the compositor. | 594 // context loss. |
| 594 EXPECT_TRUE(result_); | 595 if (!HasImplThread()) |
| 595 result_.reset(); | 596 CheckAndReleaseCopyOutput(); |
| 596 | |
| 597 // Check that it is released. | |
| 598 ImplThreadTaskRunner()->PostTask( | |
| 599 FROM_HERE, | |
| 600 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: | |
| 601 CheckNumTextures, | |
| 602 base::Unretained(this), | |
| 603 num_textures_after_loss_ - 1)); | |
| 604 break; | 597 break; |
| 605 } | 598 } |
| 606 } | 599 } |
| 607 | 600 |
| 601 void CheckAndReleaseCopyOutput() { |
| 602 // Now destroy the CopyOutputResult, releasing the texture inside back |
| 603 // to the compositor. |
| 604 EXPECT_TRUE(result_); |
| 605 result_.reset(); |
| 606 |
| 607 // Check that it is released. |
| 608 ImplThreadTaskRunner()->PostTask( |
| 609 FROM_HERE, |
| 610 base::Bind( |
| 611 &LayerTreeHostCopyRequestTestLostOutputSurface::CheckNumTextures, |
| 612 base::Unretained(this), |
| 613 num_textures_after_loss_ - 1)); |
| 614 } |
| 615 |
| 608 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, | 616 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, |
| 609 bool result) OVERRIDE { | 617 bool result) OVERRIDE { |
| 610 switch (impl->active_tree()->source_frame_number()) { | 618 switch (impl->active_tree()->source_frame_number()) { |
| 611 case 0: | 619 case 0: |
| 612 // The layers have been drawn, so their textures have been allocated. | 620 // The layers have been drawn, so their textures have been allocated. |
| 613 EXPECT_FALSE(result_); | 621 EXPECT_FALSE(result_); |
| 614 num_textures_without_readback_ = | 622 num_textures_without_readback_ = |
| 615 first_context_provider_->TestContext3d()->NumTextures(); | 623 first_context_provider_->TestContext3d()->NumTextures(); |
| 616 break; | 624 break; |
| 617 case 1: | 625 case 1: |
| 618 // We did a readback, so there will be a readback texture around now. | 626 // We did a readback, so there will be a readback texture around now. |
| 619 EXPECT_LT(num_textures_without_readback_, | 627 EXPECT_LT(num_textures_without_readback_, |
| 620 first_context_provider_->TestContext3d()->NumTextures()); | 628 first_context_provider_->TestContext3d()->NumTextures()); |
| 621 break; | 629 break; |
| 622 case 2: | 630 case 2: |
| 623 // The readback texture is collected. | 631 // The readback texture is collected. |
| 624 EXPECT_TRUE(result_); | 632 EXPECT_TRUE(result_); |
| 625 | 633 |
| 626 // Lose the output surface. | 634 // Lose the output surface. |
| 627 first_context_provider_->TestContext3d()->loseContextCHROMIUM( | 635 first_context_provider_->TestContext3d()->loseContextCHROMIUM( |
| 628 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 636 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 629 break; | 637 break; |
| 630 case 3: | 638 case 3: |
| 631 // With SingleThreadProxy it takes two commits to finally swap after a | 639 if (HasImplThread()) |
| 632 // context loss. | 640 CheckSecondContextCreated(); |
| 641 break; |
| 633 case 4: | 642 case 4: |
| 634 // The output surface has been recreated. | 643 // With SingleThreadProxy it takes two commits to finally swap after a |
| 635 EXPECT_TRUE(second_context_provider_.get()); | 644 // context loss. |
| 636 | 645 if (!HasImplThread()) |
| 637 num_textures_after_loss_ = | 646 CheckSecondContextCreated(); |
| 638 first_context_provider_->TestContext3d()->NumTextures(); | |
| 639 break; | 647 break; |
| 640 } | 648 } |
| 641 } | 649 } |
| 642 | 650 |
| 651 void CheckSecondContextCreated() { |
| 652 // The output surface has been recreated. |
| 653 EXPECT_TRUE(second_context_provider_.get()); |
| 654 |
| 655 num_textures_after_loss_ = |
| 656 first_context_provider_->TestContext3d()->NumTextures(); |
| 657 } |
| 658 |
| 643 void CheckNumTextures(size_t expected_num_textures) { | 659 void CheckNumTextures(size_t expected_num_textures) { |
| 644 EXPECT_EQ(expected_num_textures, | 660 EXPECT_EQ(expected_num_textures, |
| 645 first_context_provider_->TestContext3d()->NumTextures()); | 661 first_context_provider_->TestContext3d()->NumTextures()); |
| 646 EndTest(); | 662 EndTest(); |
| 647 } | 663 } |
| 648 | 664 |
| 649 virtual void AfterTest() OVERRIDE {} | 665 virtual void AfterTest() OVERRIDE {} |
| 650 | 666 |
| 651 scoped_refptr<TestContextProvider> first_context_provider_; | 667 scoped_refptr<TestContextProvider> first_context_provider_; |
| 652 scoped_refptr<TestContextProvider> second_context_provider_; | 668 scoped_refptr<TestContextProvider> second_context_provider_; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 FakeContentLayerClient client_; | 981 FakeContentLayerClient client_; |
| 966 scoped_refptr<FakeContentLayer> root_; | 982 scoped_refptr<FakeContentLayer> root_; |
| 967 scoped_refptr<FakeContentLayer> copy_layer_; | 983 scoped_refptr<FakeContentLayer> copy_layer_; |
| 968 }; | 984 }; |
| 969 | 985 |
| 970 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 986 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 971 LayerTreeHostCopyRequestTestShutdownBeforeCopy); | 987 LayerTreeHostCopyRequestTestShutdownBeforeCopy); |
| 972 | 988 |
| 973 } // namespace | 989 } // namespace |
| 974 } // namespace cc | 990 } // namespace cc |
| OLD | NEW |