| OLD | NEW |
| 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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "cc/base/scoped_ptr_deque.h" | 13 #include "cc/base/scoped_ptr_deque.h" |
| 14 #include "cc/debug/test_web_graphics_context_3d.h" | 14 #include "cc/debug/test_web_graphics_context_3d.h" |
| 15 #include "cc/output/output_surface.h" | 15 #include "cc/output/output_surface.h" |
| 16 #include "cc/resources/returned_resource.h" |
| 16 #include "cc/test/fake_output_surface.h" | 17 #include "cc/test/fake_output_surface.h" |
| 17 #include "cc/test/fake_output_surface_client.h" | 18 #include "cc/test/fake_output_surface_client.h" |
| 18 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 22 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 22 #include "third_party/khronos/GLES2/gl2.h" | 23 #include "third_party/khronos/GLES2/gl2.h" |
| 23 #include "third_party/khronos/GLES2/gl2ext.h" | 24 #include "third_party/khronos/GLES2/gl2ext.h" |
| 24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 25 | 26 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 { | 596 { |
| 596 // Check that transfering again the same resource from the child to the | 597 // Check that transfering again the same resource from the child to the |
| 597 // parent works. | 598 // parent works. |
| 598 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 599 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 599 resource_ids_to_transfer.push_back(id1); | 600 resource_ids_to_transfer.push_back(id1); |
| 600 TransferableResourceArray list; | 601 TransferableResourceArray list; |
| 601 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, | 602 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, |
| 602 &list); | 603 &list); |
| 603 EXPECT_EQ(1u, list.size()); | 604 EXPECT_EQ(1u, list.size()); |
| 604 EXPECT_EQ(id1, list[0].id); | 605 EXPECT_EQ(id1, list[0].id); |
| 605 child_resource_provider->ReceiveFromParent(list); | 606 ReturnedResourceArray returned; |
| 607 TransferableResource::ReturnResources(list, &returned); |
| 608 child_resource_provider->ReceiveReturnsFromParent(returned); |
| 606 // id1 was exported twice, we returned it only once, it should still be | 609 // id1 was exported twice, we returned it only once, it should still be |
| 607 // in-use. | 610 // in-use. |
| 608 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); | 611 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); |
| 609 } | 612 } |
| 610 { | 613 { |
| 611 // Transfer resources back from the parent to the child. | 614 // Transfer resources back from the parent to the child. |
| 612 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 615 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 613 resource_ids_to_transfer.push_back(mapped_id1); | 616 resource_ids_to_transfer.push_back(mapped_id1); |
| 614 resource_ids_to_transfer.push_back(mapped_id2); | 617 resource_ids_to_transfer.push_back(mapped_id2); |
| 615 TransferableResourceArray list; | 618 ReturnedResourceArray list; |
| 616 resource_provider_->PrepareSendToChild( | 619 resource_provider_->PrepareSendReturnsToChild( |
| 617 child_id, resource_ids_to_transfer, &list); | 620 child_id, resource_ids_to_transfer, &list); |
| 618 ASSERT_EQ(2u, list.size()); | 621 ASSERT_EQ(2u, list.size()); |
| 619 EXPECT_NE(0u, list[0].sync_point); | 622 EXPECT_NE(0u, list[0].sync_point); |
| 620 EXPECT_NE(0u, list[1].sync_point); | 623 EXPECT_NE(0u, list[1].sync_point); |
| 621 child_resource_provider->ReceiveFromParent(list); | 624 child_resource_provider->ReceiveReturnsFromParent(list); |
| 622 } | 625 } |
| 623 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1)); | 626 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1)); |
| 624 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2)); | 627 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2)); |
| 625 | 628 |
| 626 { | 629 { |
| 627 ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id1); | 630 ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id1); |
| 628 ASSERT_NE(0U, lock.texture_id()); | 631 ASSERT_NE(0U, lock.texture_id()); |
| 629 child_context->bindTexture(GL_TEXTURE_2D, lock.texture_id()); | 632 child_context->bindTexture(GL_TEXTURE_2D, lock.texture_id()); |
| 630 child_context->GetPixels(size, format, result); | 633 child_context->GetPixels(size, format, result); |
| 631 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); | 634 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 child_resource_provider->DeleteResource(id); | 707 child_resource_provider->DeleteResource(id); |
| 705 EXPECT_EQ(1u, child_resource_provider->num_resources()); | 708 EXPECT_EQ(1u, child_resource_provider->num_resources()); |
| 706 { | 709 { |
| 707 // Transfer resources back from the parent to the child. | 710 // Transfer resources back from the parent to the child. |
| 708 ResourceProvider::ResourceIdMap resource_map = | 711 ResourceProvider::ResourceIdMap resource_map = |
| 709 resource_provider_->GetChildToParentMap(child_id); | 712 resource_provider_->GetChildToParentMap(child_id); |
| 710 ResourceProvider::ResourceId mapped_id = resource_map[id]; | 713 ResourceProvider::ResourceId mapped_id = resource_map[id]; |
| 711 EXPECT_NE(0u, mapped_id); | 714 EXPECT_NE(0u, mapped_id); |
| 712 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 715 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 713 resource_ids_to_transfer.push_back(mapped_id); | 716 resource_ids_to_transfer.push_back(mapped_id); |
| 714 TransferableResourceArray list; | 717 ReturnedResourceArray list; |
| 715 resource_provider_->PrepareSendToChild( | 718 resource_provider_->PrepareSendReturnsToChild( |
| 716 child_id, resource_ids_to_transfer, &list); | 719 child_id, resource_ids_to_transfer, &list); |
| 717 ASSERT_EQ(1u, list.size()); | 720 ASSERT_EQ(1u, list.size()); |
| 718 EXPECT_NE(0u, list[0].sync_point); | 721 EXPECT_NE(0u, list[0].sync_point); |
| 719 child_resource_provider->ReceiveFromParent(list); | 722 child_resource_provider->ReceiveReturnsFromParent(list); |
| 720 } | 723 } |
| 721 EXPECT_EQ(0u, child_resource_provider->num_resources()); | 724 EXPECT_EQ(0u, child_resource_provider->num_resources()); |
| 722 } | 725 } |
| 723 | 726 |
| 724 TEST_P(ResourceProviderTest, TextureFilters) { | 727 TEST_P(ResourceProviderTest, TextureFilters) { |
| 725 // Resource transfer is only supported with GL textures for now. | 728 // Resource transfer is only supported with GL textures for now. |
| 726 if (GetParam() != ResourceProvider::GLTexture) | 729 if (GetParam() != ResourceProvider::GLTexture) |
| 727 return; | 730 return; |
| 728 | 731 |
| 729 scoped_ptr<ResourceProviderContext> child_context_owned( | 732 scoped_ptr<ResourceProviderContext> child_context_owned( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 EXPECT_NE(0u, mapped_id); | 779 EXPECT_NE(0u, mapped_id); |
| 777 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), | 780 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 778 GetResourceFilter(resource_provider_.get(), context(), mapped_id)); | 781 GetResourceFilter(resource_provider_.get(), context(), mapped_id)); |
| 779 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); | 782 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); |
| 780 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), | 783 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 781 GetResourceFilter(resource_provider_.get(), context(), mapped_id)); | 784 GetResourceFilter(resource_provider_.get(), context(), mapped_id)); |
| 782 { | 785 { |
| 783 // Transfer resources back from the parent to the child. | 786 // Transfer resources back from the parent to the child. |
| 784 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 787 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 785 resource_ids_to_transfer.push_back(mapped_id); | 788 resource_ids_to_transfer.push_back(mapped_id); |
| 786 TransferableResourceArray list; | 789 ReturnedResourceArray list; |
| 787 resource_provider_->PrepareSendToChild( | 790 resource_provider_->PrepareSendReturnsToChild( |
| 788 child_id, resource_ids_to_transfer, &list); | 791 child_id, resource_ids_to_transfer, &list); |
| 789 ASSERT_EQ(1u, list.size()); | 792 ASSERT_EQ(1u, list.size()); |
| 790 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); | 793 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); |
| 791 child_resource_provider->ReceiveFromParent(list); | 794 child_resource_provider->ReceiveReturnsFromParent(list); |
| 792 } | 795 } |
| 793 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), | 796 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 794 GetResourceFilter(child_resource_provider.get(), | 797 GetResourceFilter(child_resource_provider.get(), |
| 795 child_context, | 798 child_context, |
| 796 id)); | 799 id)); |
| 797 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); | 800 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); |
| 798 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), | 801 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 799 GetResourceFilter(child_resource_provider.get(), | 802 GetResourceFilter(child_resource_provider.get(), |
| 800 child_context, | 803 child_context, |
| 801 id)); | 804 id)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 uint8_t test_data[4] = { 0 }; | 857 uint8_t test_data[4] = { 0 }; |
| 855 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); | 858 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); |
| 856 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | 859 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); |
| 857 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 860 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 858 context()->deleteTexture(other_texture); | 861 context()->deleteTexture(other_texture); |
| 859 list[0].sync_point = context()->insertSyncPoint(); | 862 list[0].sync_point = context()->insertSyncPoint(); |
| 860 EXPECT_LT(0u, list[0].sync_point); | 863 EXPECT_LT(0u, list[0].sync_point); |
| 861 | 864 |
| 862 // Receive the resource, then delete it, expect the sync points to be | 865 // Receive the resource, then delete it, expect the sync points to be |
| 863 // consistent. | 866 // consistent. |
| 864 resource_provider_->ReceiveFromParent(list); | 867 ReturnedResourceArray returned; |
| 868 TransferableResource::ReturnResources(list, &returned); |
| 869 resource_provider_->ReceiveReturnsFromParent(returned); |
| 865 EXPECT_EQ(1, context()->texture_count()); | 870 EXPECT_EQ(1, context()->texture_count()); |
| 866 EXPECT_EQ(0u, release_sync_point); | 871 EXPECT_EQ(0u, release_sync_point); |
| 867 | 872 |
| 868 resource_provider_->DeleteResource(resource); | 873 resource_provider_->DeleteResource(resource); |
| 869 EXPECT_LE(list[0].sync_point, release_sync_point); | 874 EXPECT_LE(list[0].sync_point, release_sync_point); |
| 870 EXPECT_FALSE(lost_resource); | 875 EXPECT_FALSE(lost_resource); |
| 871 } | 876 } |
| 872 | 877 |
| 873 // We're going to do the same thing as above, but testing the case where we | 878 // We're going to do the same thing as above, but testing the case where we |
| 874 // delete the resource before we receive it back. | 879 // delete the resource before we receive it back. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 903 list[0].sync_point = context()->insertSyncPoint(); | 908 list[0].sync_point = context()->insertSyncPoint(); |
| 904 EXPECT_LT(0u, list[0].sync_point); | 909 EXPECT_LT(0u, list[0].sync_point); |
| 905 | 910 |
| 906 // Delete the resource, which shouldn't do anything. | 911 // Delete the resource, which shouldn't do anything. |
| 907 resource_provider_->DeleteResource(resource); | 912 resource_provider_->DeleteResource(resource); |
| 908 EXPECT_EQ(1, context()->texture_count()); | 913 EXPECT_EQ(1, context()->texture_count()); |
| 909 EXPECT_EQ(0u, release_sync_point); | 914 EXPECT_EQ(0u, release_sync_point); |
| 910 | 915 |
| 911 // Then receive the resource which should release the mailbox, expect the | 916 // Then receive the resource which should release the mailbox, expect the |
| 912 // sync points to be consistent. | 917 // sync points to be consistent. |
| 913 resource_provider_->ReceiveFromParent(list); | 918 ReturnedResourceArray returned; |
| 919 TransferableResource::ReturnResources(list, &returned); |
| 920 resource_provider_->ReceiveReturnsFromParent(returned); |
| 914 EXPECT_LE(list[0].sync_point, release_sync_point); | 921 EXPECT_LE(list[0].sync_point, release_sync_point); |
| 915 EXPECT_FALSE(lost_resource); | 922 EXPECT_FALSE(lost_resource); |
| 916 } | 923 } |
| 917 | 924 |
| 918 context()->waitSyncPoint(release_sync_point); | 925 context()->waitSyncPoint(release_sync_point); |
| 919 context()->bindTexture(GL_TEXTURE_2D, texture); | 926 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 920 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 927 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 921 context()->deleteTexture(texture); | 928 context()->deleteTexture(texture); |
| 922 } | 929 } |
| 923 | 930 |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 output_surface.get()); | 1810 output_surface.get()); |
| 1804 } | 1811 } |
| 1805 | 1812 |
| 1806 INSTANTIATE_TEST_CASE_P( | 1813 INSTANTIATE_TEST_CASE_P( |
| 1807 ResourceProviderTests, | 1814 ResourceProviderTests, |
| 1808 ResourceProviderTest, | 1815 ResourceProviderTest, |
| 1809 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1816 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 1810 | 1817 |
| 1811 } // namespace | 1818 } // namespace |
| 1812 } // namespace cc | 1819 } // namespace cc |
| OLD | NEW |