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

Side by Side Diff: cc/resources/resource_provider_unittest.cc

Issue 23097005: cc: return resources via a ReturnedResource struct rather than TransferableResource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: post-rebase fixes Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
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"
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 { 580 {
581 // Check that transfering again the same resource from the child to the 581 // Check that transfering again the same resource from the child to the
582 // parent works. 582 // parent works.
583 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 583 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
584 resource_ids_to_transfer.push_back(id1); 584 resource_ids_to_transfer.push_back(id1);
585 TransferableResourceArray list; 585 TransferableResourceArray list;
586 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, 586 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
587 &list); 587 &list);
588 EXPECT_EQ(1u, list.size()); 588 EXPECT_EQ(1u, list.size());
589 EXPECT_EQ(id1, list[0].id); 589 EXPECT_EQ(id1, list[0].id);
590 child_resource_provider->ReceiveFromParent(list); 590 ReturnedResourceArray returned;
591 ReturnResources(list, &returned);
592 child_resource_provider->ReceiveFromParent(returned);
591 // id1 was exported twice, we returned it only once, it should still be 593 // id1 was exported twice, we returned it only once, it should still be
592 // in-use. 594 // in-use.
593 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); 595 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1));
594 } 596 }
595 { 597 {
596 // Transfer resources back from the parent to the child. 598 // Transfer resources back from the parent to the child.
597 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 599 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
598 resource_ids_to_transfer.push_back(mapped_id1); 600 resource_ids_to_transfer.push_back(mapped_id1);
599 resource_ids_to_transfer.push_back(mapped_id2); 601 resource_ids_to_transfer.push_back(mapped_id2);
600 TransferableResourceArray list; 602 ReturnedResourceArray list;
601 resource_provider_->PrepareSendToChild( 603 resource_provider_->PrepareSendToChild(
602 child_id, resource_ids_to_transfer, &list); 604 child_id, resource_ids_to_transfer, &list);
603 ASSERT_EQ(2u, list.size()); 605 ASSERT_EQ(2u, list.size());
604 EXPECT_NE(0u, list[0].sync_point); 606 EXPECT_NE(0u, list[0].sync_point);
605 EXPECT_NE(0u, list[1].sync_point); 607 EXPECT_NE(0u, list[1].sync_point);
606 child_resource_provider->ReceiveFromParent(list); 608 child_resource_provider->ReceiveFromParent(list);
607 } 609 }
608 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1)); 610 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1));
609 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2)); 611 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2));
610 612
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 child_resource_provider->DeleteResource(id); 687 child_resource_provider->DeleteResource(id);
686 EXPECT_EQ(1u, child_resource_provider->num_resources()); 688 EXPECT_EQ(1u, child_resource_provider->num_resources());
687 { 689 {
688 // Transfer resources back from the parent to the child. 690 // Transfer resources back from the parent to the child.
689 ResourceProvider::ResourceIdMap resource_map = 691 ResourceProvider::ResourceIdMap resource_map =
690 resource_provider_->GetChildToParentMap(child_id); 692 resource_provider_->GetChildToParentMap(child_id);
691 ResourceProvider::ResourceId mapped_id = resource_map[id]; 693 ResourceProvider::ResourceId mapped_id = resource_map[id];
692 EXPECT_NE(0u, mapped_id); 694 EXPECT_NE(0u, mapped_id);
693 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 695 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
694 resource_ids_to_transfer.push_back(mapped_id); 696 resource_ids_to_transfer.push_back(mapped_id);
695 TransferableResourceArray list; 697 ReturnedResourceArray list;
696 resource_provider_->PrepareSendToChild( 698 resource_provider_->PrepareSendToChild(
697 child_id, resource_ids_to_transfer, &list); 699 child_id, resource_ids_to_transfer, &list);
698 ASSERT_EQ(1u, list.size()); 700 ASSERT_EQ(1u, list.size());
699 EXPECT_NE(0u, list[0].sync_point); 701 EXPECT_NE(0u, list[0].sync_point);
700 child_resource_provider->ReceiveFromParent(list); 702 child_resource_provider->ReceiveFromParent(list);
701 } 703 }
702 EXPECT_EQ(0u, child_resource_provider->num_resources()); 704 EXPECT_EQ(0u, child_resource_provider->num_resources());
703 } 705 }
704 706
705 TEST_P(ResourceProviderTest, TextureFilters) { 707 TEST_P(ResourceProviderTest, TextureFilters) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_NE(0u, mapped_id); 749 EXPECT_NE(0u, mapped_id);
748 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), 750 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST),
749 GetResourceFilter(resource_provider_.get(), mapped_id)); 751 GetResourceFilter(resource_provider_.get(), mapped_id));
750 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); 752 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR);
751 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), 753 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR),
752 GetResourceFilter(resource_provider_.get(), mapped_id)); 754 GetResourceFilter(resource_provider_.get(), mapped_id));
753 { 755 {
754 // Transfer resources back from the parent to the child. 756 // Transfer resources back from the parent to the child.
755 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 757 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
756 resource_ids_to_transfer.push_back(mapped_id); 758 resource_ids_to_transfer.push_back(mapped_id);
757 TransferableResourceArray list; 759 ReturnedResourceArray list;
758 resource_provider_->PrepareSendToChild( 760 resource_provider_->PrepareSendToChild(
759 child_id, resource_ids_to_transfer, &list); 761 child_id, resource_ids_to_transfer, &list);
760 ASSERT_EQ(1u, list.size()); 762 ASSERT_EQ(1u, list.size());
761 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); 763 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter);
762 child_resource_provider->ReceiveFromParent(list); 764 child_resource_provider->ReceiveFromParent(list);
763 } 765 }
764 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), 766 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR),
765 GetResourceFilter(child_resource_provider.get(), id)); 767 GetResourceFilter(child_resource_provider.get(), id));
766 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); 768 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST);
767 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), 769 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 uint8_t test_data[4] = { 0 }; 823 uint8_t test_data[4] = { 0 };
822 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); 824 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
823 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 825 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
824 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 826 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
825 context()->deleteTexture(other_texture); 827 context()->deleteTexture(other_texture);
826 list[0].sync_point = context()->insertSyncPoint(); 828 list[0].sync_point = context()->insertSyncPoint();
827 EXPECT_LT(0u, list[0].sync_point); 829 EXPECT_LT(0u, list[0].sync_point);
828 830
829 // Receive the resource, then delete it, expect the sync points to be 831 // Receive the resource, then delete it, expect the sync points to be
830 // consistent. 832 // consistent.
831 resource_provider_->ReceiveFromParent(list); 833 ReturnedResourceArray returned;
834 ReturnResources(list, &returned);
835 resource_provider_->ReceiveFromParent(returned);
832 EXPECT_EQ(1, context()->texture_count()); 836 EXPECT_EQ(1, context()->texture_count());
833 EXPECT_EQ(0u, release_sync_point); 837 EXPECT_EQ(0u, release_sync_point);
834 838
835 resource_provider_->DeleteResource(resource); 839 resource_provider_->DeleteResource(resource);
836 EXPECT_LE(list[0].sync_point, release_sync_point); 840 EXPECT_LE(list[0].sync_point, release_sync_point);
837 EXPECT_FALSE(lost_resource); 841 EXPECT_FALSE(lost_resource);
838 } 842 }
839 843
840 // We're going to do the same thing as above, but testing the case where we 844 // We're going to do the same thing as above, but testing the case where we
841 // delete the resource before we receive it back. 845 // delete the resource before we receive it back.
(...skipping 28 matching lines...) Expand all
870 list[0].sync_point = context()->insertSyncPoint(); 874 list[0].sync_point = context()->insertSyncPoint();
871 EXPECT_LT(0u, list[0].sync_point); 875 EXPECT_LT(0u, list[0].sync_point);
872 876
873 // Delete the resource, which shouldn't do anything. 877 // Delete the resource, which shouldn't do anything.
874 resource_provider_->DeleteResource(resource); 878 resource_provider_->DeleteResource(resource);
875 EXPECT_EQ(1, context()->texture_count()); 879 EXPECT_EQ(1, context()->texture_count());
876 EXPECT_EQ(0u, release_sync_point); 880 EXPECT_EQ(0u, release_sync_point);
877 881
878 // Then receive the resource which should release the mailbox, expect the 882 // Then receive the resource which should release the mailbox, expect the
879 // sync points to be consistent. 883 // sync points to be consistent.
880 resource_provider_->ReceiveFromParent(list); 884 ReturnedResourceArray returned;
885 ReturnResources(list, &returned);
886 resource_provider_->ReceiveFromParent(returned);
881 EXPECT_LE(list[0].sync_point, release_sync_point); 887 EXPECT_LE(list[0].sync_point, release_sync_point);
882 EXPECT_FALSE(lost_resource); 888 EXPECT_FALSE(lost_resource);
883 } 889 }
884 890
885 context()->waitSyncPoint(release_sync_point); 891 context()->waitSyncPoint(release_sync_point);
886 context()->bindTexture(GL_TEXTURE_2D, texture); 892 context()->bindTexture(GL_TEXTURE_2D, texture);
887 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 893 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
888 context()->deleteTexture(texture); 894 context()->deleteTexture(texture);
889 } 895 }
890 896
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 output_surface.get()); 1745 output_surface.get());
1740 } 1746 }
1741 1747
1742 INSTANTIATE_TEST_CASE_P( 1748 INSTANTIATE_TEST_CASE_P(
1743 ResourceProviderTests, 1749 ResourceProviderTests,
1744 ResourceProviderTest, 1750 ResourceProviderTest,
1745 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); 1751 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap));
1746 1752
1747 } // namespace 1753 } // namespace
1748 } // namespace cc 1754 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698