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

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

Issue 69343011: cc: Rationalize sync points and lost status for returned resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/transferable_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 gfx::Size size, 74 gfx::Size size,
75 uint32_t value) { 75 uint32_t value) {
76 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); 76 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
77 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); 77 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea()));
78 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); 78 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory());
79 CHECK(pixels); 79 CHECK(pixels);
80 std::fill_n(pixels, size.GetArea(), value); 80 std::fill_n(pixels, size.GetArea(), value);
81 return shared_memory.Pass(); 81 return shared_memory.Pass();
82 } 82 }
83 83
84 void ForceUseChildTextures(ResourceProvider* resource_provider,
85 int child_id,
86 const TransferableResourceArray& resources) {
87 ResourceProvider::ResourceIdMap resource_map =
88 resource_provider->GetChildToParentMap(child_id);
89 for (size_t i = 0; i < resources.size(); ++i) {
90 ResourceProvider::ResourceId mapped_id = resource_map[resources[i].id];
91 ResourceProvider::ScopedReadLockGL lock(resource_provider, mapped_id);
92 EXPECT_NE(0U, lock.texture_id());
93 }
94 }
95
84 class TextureStateTrackingContext : public TestWebGraphicsContext3D { 96 class TextureStateTrackingContext : public TestWebGraphicsContext3D {
85 public: 97 public:
86 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); 98 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture));
87 MOCK_METHOD3(texParameteri, 99 MOCK_METHOD3(texParameteri,
88 void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); 100 void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
89 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point)); 101 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point));
90 MOCK_METHOD0(insertSyncPoint, unsigned(void)); 102 MOCK_METHOD0(insertSyncPoint, unsigned(void));
91 MOCK_METHOD2(produceTextureCHROMIUM, void(WGC3Denum target, 103 MOCK_METHOD2(produceTextureCHROMIUM, void(WGC3Denum target,
92 const WGC3Dbyte* mailbox)); 104 const WGC3Dbyte* mailbox));
93 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target, 105 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target,
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); 728 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target);
717 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[2].target); 729 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[2].target);
718 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 730 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
719 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 731 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
720 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); 732 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3));
721 resource_provider_->ReceiveFromChild(child_id, list); 733 resource_provider_->ReceiveFromChild(child_id, list);
722 resource_provider_->DeclareUsedResourcesFromChild(child_id, 734 resource_provider_->DeclareUsedResourcesFromChild(child_id,
723 resource_ids_to_transfer); 735 resource_ids_to_transfer);
724 } 736 }
725 737
726 EXPECT_EQ(3u, resource_provider_->num_resources()); 738 uint8_t result[4] = { 0 };
727 ResourceProvider::ResourceIdMap resource_map = 739 {
728 resource_provider_->GetChildToParentMap(child_id); 740 EXPECT_EQ(3u, resource_provider_->num_resources());
729 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; 741 ResourceProvider::ResourceIdMap resource_map =
730 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; 742 resource_provider_->GetChildToParentMap(child_id);
731 ResourceProvider::ResourceId mapped_id3 = resource_map[id3]; 743 ResourceProvider::ResourceId mapped_id1 = resource_map[id1];
732 EXPECT_NE(0u, mapped_id1); 744 ResourceProvider::ResourceId mapped_id2 = resource_map[id2];
733 EXPECT_NE(0u, mapped_id2); 745 ResourceProvider::ResourceId mapped_id3 = resource_map[id3];
734 EXPECT_NE(0u, mapped_id3); 746 EXPECT_NE(0u, mapped_id1);
735 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); 747 EXPECT_NE(0u, mapped_id2);
736 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); 748 EXPECT_NE(0u, mapped_id3);
737 EXPECT_FALSE(resource_provider_->InUseByConsumer(id3)); 749 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1));
750 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2));
751 EXPECT_FALSE(resource_provider_->InUseByConsumer(id3));
738 752
739 uint8_t result[4] = { 0 }; 753 GetResourcePixels(
740 GetResourcePixels( 754 resource_provider_.get(), context(), mapped_id1, size, format, result);
741 resource_provider_.get(), context(), mapped_id1, size, format, result); 755 EXPECT_EQ(0, memcmp(data1, result, pixel_size));
742 EXPECT_EQ(0, memcmp(data1, result, pixel_size));
743 756
744 GetResourcePixels( 757 GetResourcePixels(
745 resource_provider_.get(), context(), mapped_id2, size, format, result); 758 resource_provider_.get(), context(), mapped_id2, size, format, result);
746 EXPECT_EQ(0, memcmp(data2, result, pixel_size)); 759 EXPECT_EQ(0, memcmp(data2, result, pixel_size));
760
761 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
762 mapped_id3);
763 EXPECT_NE(0U, lock.texture_id());
764 }
747 765
748 { 766 {
749 // Check that transfering again the same resource from the child to the 767 // Check that transfering again the same resource from the child to the
750 // parent works. 768 // parent works.
751 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 769 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
752 resource_ids_to_transfer.push_back(id1); 770 resource_ids_to_transfer.push_back(id1);
753 TransferableResourceArray list; 771 TransferableResourceArray list;
754 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 772 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
755 &list); 773 &list);
756 EXPECT_EQ(1u, list.size()); 774 EXPECT_EQ(1u, list.size());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 EXPECT_NE(0u, list[2].sync_point); 837 EXPECT_NE(0u, list[2].sync_point);
820 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target); 838 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[0].target);
821 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target); 839 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), list[1].target);
822 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[2].target); 840 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), list[2].target);
823 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 841 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
824 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 842 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
825 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); 843 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3));
826 resource_provider_->ReceiveFromChild(child_id, list); 844 resource_provider_->ReceiveFromChild(child_id, list);
827 resource_provider_->DeclareUsedResourcesFromChild(child_id, 845 resource_provider_->DeclareUsedResourcesFromChild(child_id,
828 resource_ids_to_transfer); 846 resource_ids_to_transfer);
847 // Lock resources in child to make sure they get "used".
848 ForceUseChildTextures(resource_provider_.get(), child_id, list);
829 } 849 }
830 850
831 EXPECT_EQ(0u, returned_to_child.size()); 851 EXPECT_EQ(0u, returned_to_child.size());
832 852
833 EXPECT_EQ(3u, resource_provider_->num_resources()); 853 EXPECT_EQ(3u, resource_provider_->num_resources());
834 resource_provider_->DestroyChild(child_id); 854 resource_provider_->DestroyChild(child_id);
835 EXPECT_EQ(0u, resource_provider_->num_resources()); 855 EXPECT_EQ(0u, resource_provider_->num_resources());
836 856
837 ASSERT_EQ(3u, returned_to_child.size()); 857 ASSERT_EQ(3u, returned_to_child.size());
838 EXPECT_NE(0u, returned_to_child[0].sync_point); 858 EXPECT_NE(0u, returned_to_child[0].sync_point);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 EXPECT_EQ(0u, returned_to_child.size()); 1274 EXPECT_EQ(0u, returned_to_child.size());
1255 EXPECT_EQ(2u, resource_provider_->num_resources()); 1275 EXPECT_EQ(2u, resource_provider_->num_resources());
1256 1276
1257 // Return the resources from the grandparent to the parent. They should be 1277 // Return the resources from the grandparent to the parent. They should be
1258 // returned to the child then. 1278 // returned to the child then.
1259 EXPECT_EQ(2u, list.size()); 1279 EXPECT_EQ(2u, list.size());
1260 EXPECT_EQ(mapped_id1, list[0].id); 1280 EXPECT_EQ(mapped_id1, list[0].id);
1261 EXPECT_EQ(mapped_id2, list[1].id); 1281 EXPECT_EQ(mapped_id2, list[1].id);
1262 ReturnedResourceArray returned; 1282 ReturnedResourceArray returned;
1263 TransferableResource::ReturnResources(list, &returned); 1283 TransferableResource::ReturnResources(list, &returned);
1284 EXPECT_EQ(2u, returned.size());
1285 if (GetParam() == ResourceProvider::GLTexture) {
1286 returned[0].sync_point = 3;
1287 returned[1].sync_point = 4;
1288 }
1264 resource_provider_->ReceiveReturnsFromParent(returned); 1289 resource_provider_->ReceiveReturnsFromParent(returned);
1265 1290
1266 EXPECT_EQ(0u, resource_provider_->num_resources()); 1291 EXPECT_EQ(0u, resource_provider_->num_resources());
1267 ASSERT_EQ(2u, returned_to_child.size()); 1292 ASSERT_EQ(2u, returned_to_child.size());
1268 if (GetParam() == ResourceProvider::GLTexture) { 1293 if (GetParam() == ResourceProvider::GLTexture) {
1269 EXPECT_NE(0u, returned_to_child[0].sync_point); 1294 EXPECT_NE(0u, returned_to_child[0].sync_point);
1270 EXPECT_NE(0u, returned_to_child[1].sync_point); 1295 EXPECT_NE(0u, returned_to_child[1].sync_point);
1271 } 1296 }
1272 EXPECT_FALSE(returned_to_child[0].lost); 1297 EXPECT_FALSE(returned_to_child[0].lost);
1273 EXPECT_FALSE(returned_to_child[1].lost); 1298 EXPECT_FALSE(returned_to_child[1].lost);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 // Return a resource from the grandparent, it should be returned at this 1382 // Return a resource from the grandparent, it should be returned at this
1358 // point. 1383 // point.
1359 EXPECT_EQ(2u, list.size()); 1384 EXPECT_EQ(2u, list.size());
1360 EXPECT_EQ(mapped_id1, list[0].id); 1385 EXPECT_EQ(mapped_id1, list[0].id);
1361 EXPECT_EQ(mapped_id2, list[1].id); 1386 EXPECT_EQ(mapped_id2, list[1].id);
1362 TransferableResourceArray return_list; 1387 TransferableResourceArray return_list;
1363 return_list.push_back(list[1]); 1388 return_list.push_back(list[1]);
1364 list.pop_back(); 1389 list.pop_back();
1365 ReturnedResourceArray returned; 1390 ReturnedResourceArray returned;
1366 TransferableResource::ReturnResources(return_list, &returned); 1391 TransferableResource::ReturnResources(return_list, &returned);
1392 EXPECT_EQ(1u, returned.size());
1393 if (GetParam() == ResourceProvider::GLTexture)
1394 returned[0].sync_point = 3;
1367 resource_provider_->ReceiveReturnsFromParent(returned); 1395 resource_provider_->ReceiveReturnsFromParent(returned);
1368 1396
1369 EXPECT_EQ(1u, resource_provider_->num_resources()); 1397 EXPECT_EQ(1u, resource_provider_->num_resources());
1370 ASSERT_EQ(1u, returned_to_child.size()); 1398 ASSERT_EQ(1u, returned_to_child.size());
1371 if (GetParam() == ResourceProvider::GLTexture) { 1399 if (GetParam() == ResourceProvider::GLTexture)
1372 EXPECT_NE(0u, returned_to_child[0].sync_point); 1400 EXPECT_NE(0u, returned_to_child[0].sync_point);
1373 }
1374 EXPECT_FALSE(returned_to_child[0].lost); 1401 EXPECT_FALSE(returned_to_child[0].lost);
1375 returned_to_child.clear(); 1402 returned_to_child.clear();
1376 1403
1377 // Destroy the parent resource provider. The resource that's left should be 1404 // Destroy the parent resource provider. The resource that's left should be
1378 // lost at this point, and returned. 1405 // lost at this point, and returned.
1379 resource_provider_.reset(); 1406 resource_provider_.reset();
1380 ASSERT_EQ(1u, returned_to_child.size()); 1407 ASSERT_EQ(1u, returned_to_child.size());
1381 if (GetParam() == ResourceProvider::GLTexture) {
1382 EXPECT_NE(0u, returned_to_child[0].sync_point);
1383 }
1384 EXPECT_TRUE(returned_to_child[0].lost); 1408 EXPECT_TRUE(returned_to_child[0].lost);
1385 } 1409 }
1386 } 1410 }
1387 1411
1388 TEST_P(ResourceProviderTest, DeleteTransferredResources) { 1412 TEST_P(ResourceProviderTest, DeleteTransferredResources) {
1389 gfx::Size size(1, 1); 1413 gfx::Size size(1, 1);
1390 ResourceFormat format = RGBA_8888; 1414 ResourceFormat format = RGBA_8888;
1391 size_t pixel_size = TextureSizeBytes(size, format); 1415 size_t pixel_size = TextureSizeBytes(size, format);
1392 ASSERT_EQ(4U, pixel_size); 1416 ASSERT_EQ(4U, pixel_size);
1393 1417
(...skipping 13 matching lines...) Expand all
1407 TransferableResourceArray list; 1431 TransferableResourceArray list;
1408 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1432 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1409 &list); 1433 &list);
1410 ASSERT_EQ(1u, list.size()); 1434 ASSERT_EQ(1u, list.size());
1411 if (GetParam() == ResourceProvider::GLTexture) 1435 if (GetParam() == ResourceProvider::GLTexture)
1412 EXPECT_NE(0u, list[0].sync_point); 1436 EXPECT_NE(0u, list[0].sync_point);
1413 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id)); 1437 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id));
1414 resource_provider_->ReceiveFromChild(child_id, list); 1438 resource_provider_->ReceiveFromChild(child_id, list);
1415 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1439 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1416 resource_ids_to_transfer); 1440 resource_ids_to_transfer);
1441 if (GetParam() == ResourceProvider::GLTexture)
1442 ForceUseChildTextures(resource_provider_.get(), child_id, list);
1417 } 1443 }
1418 1444
1419 // Delete textures in the child, while they are transfered. 1445 // Delete textures in the child, while they are transfered.
1420 child_resource_provider_->DeleteResource(id); 1446 child_resource_provider_->DeleteResource(id);
1421 EXPECT_EQ(1u, child_resource_provider_->num_resources()); 1447 EXPECT_EQ(1u, child_resource_provider_->num_resources());
1422 { 1448 {
1423 EXPECT_EQ(0u, returned_to_child.size()); 1449 EXPECT_EQ(0u, returned_to_child.size());
1424 1450
1425 // Transfer resources back from the parent to the child. Set no resources as 1451 // Transfer resources back from the parent to the child. Set no resources as
1426 // being in use. 1452 // being in use.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 EXPECT_CALL(*child_context, 1560 EXPECT_CALL(*child_context,
1535 produceTextureCHROMIUM(GL_TEXTURE_2D, _)); 1561 produceTextureCHROMIUM(GL_TEXTURE_2D, _));
1536 EXPECT_CALL(*child_context, insertSyncPoint()); 1562 EXPECT_CALL(*child_context, insertSyncPoint());
1537 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, 1563 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
1538 &list); 1564 &list);
1539 Mock::VerifyAndClearExpectations(child_context); 1565 Mock::VerifyAndClearExpectations(child_context);
1540 1566
1541 ASSERT_EQ(1u, list.size()); 1567 ASSERT_EQ(1u, list.size());
1542 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter); 1568 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter);
1543 1569
1570 parent_resource_provider->ReceiveFromChild(child_id, list);
1571
1544 EXPECT_CALL(*parent_context, 1572 EXPECT_CALL(*parent_context,
1545 bindTexture(GL_TEXTURE_2D, parent_texture_id)); 1573 bindTexture(GL_TEXTURE_2D, parent_texture_id));
1546 EXPECT_CALL(*parent_context, consumeTextureCHROMIUM(GL_TEXTURE_2D, _)); 1574 EXPECT_CALL(*parent_context, consumeTextureCHROMIUM(GL_TEXTURE_2D, _));
1547 parent_resource_provider->ReceiveFromChild(child_id, list); 1575 ForceUseChildTextures(parent_resource_provider.get(), child_id, list);
1548 Mock::VerifyAndClearExpectations(parent_context); 1576 Mock::VerifyAndClearExpectations(parent_context);
1549 1577
1550 parent_resource_provider->DeclareUsedResourcesFromChild( 1578 parent_resource_provider->DeclareUsedResourcesFromChild(
1551 child_id, resource_ids_to_transfer); 1579 child_id, resource_ids_to_transfer);
1552 Mock::VerifyAndClearExpectations(parent_context); 1580 Mock::VerifyAndClearExpectations(parent_context);
1553 } 1581 }
1554 ResourceProvider::ResourceIdMap resource_map = 1582 ResourceProvider::ResourceIdMap resource_map =
1555 parent_resource_provider->GetChildToParentMap(child_id); 1583 parent_resource_provider->GetChildToParentMap(child_id);
1556 ResourceProvider::ResourceId mapped_id = resource_map[id]; 1584 ResourceProvider::ResourceId mapped_id = resource_map[id];
1557 EXPECT_NE(0u, mapped_id); 1585 EXPECT_NE(0u, mapped_id);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 context()->waitSyncPoint(list[0].sync_point); 1681 context()->waitSyncPoint(list[0].sync_point);
1654 unsigned other_texture = context()->createTexture(); 1682 unsigned other_texture = context()->createTexture();
1655 context()->bindTexture(GL_TEXTURE_2D, other_texture); 1683 context()->bindTexture(GL_TEXTURE_2D, other_texture);
1656 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1684 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1657 uint8_t test_data[4] = { 0 }; 1685 uint8_t test_data[4] = { 0 };
1658 context()->GetPixels( 1686 context()->GetPixels(
1659 gfx::Size(1, 1), RGBA_8888, test_data); 1687 gfx::Size(1, 1), RGBA_8888, test_data);
1660 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 1688 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
1661 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1689 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1662 context()->deleteTexture(other_texture); 1690 context()->deleteTexture(other_texture);
1663 list[0].sync_point = context()->insertSyncPoint(); 1691 unsigned return_sync_point = context()->insertSyncPoint();
1664 EXPECT_LT(0u, list[0].sync_point); 1692 EXPECT_LT(0u, return_sync_point);
1665 1693
1666 // Receive the resource, then delete it, expect the sync points to be 1694 // Receive the resource, then delete it, expect the sync points to be
1667 // consistent. 1695 // consistent.
1668 ReturnedResourceArray returned; 1696 ReturnedResourceArray returned;
1669 TransferableResource::ReturnResources(list, &returned); 1697 TransferableResource::ReturnResources(list, &returned);
1698 EXPECT_EQ(1u, returned.size());
1699 returned[0].sync_point = return_sync_point;
1700
1670 resource_provider_->ReceiveReturnsFromParent(returned); 1701 resource_provider_->ReceiveReturnsFromParent(returned);
1671 EXPECT_EQ(1u, context()->NumTextures()); 1702 EXPECT_EQ(1u, context()->NumTextures());
1672 EXPECT_EQ(0u, release_sync_point); 1703 EXPECT_EQ(0u, release_sync_point);
1673 1704
1674 resource_provider_->DeleteResource(resource); 1705 resource_provider_->DeleteResource(resource);
1675 EXPECT_LE(list[0].sync_point, release_sync_point); 1706 EXPECT_LE(returned[0].sync_point, release_sync_point);
1676 EXPECT_FALSE(lost_resource); 1707 EXPECT_FALSE(lost_resource);
1677 } 1708 }
1678 1709
1679 // We're going to do the same thing as above, but testing the case where we 1710 // We're going to do the same thing as above, but testing the case where we
1680 // delete the resource before we receive it back. 1711 // delete the resource before we receive it back.
1681 sync_point = release_sync_point; 1712 sync_point = release_sync_point;
1682 EXPECT_LT(0u, sync_point); 1713 EXPECT_LT(0u, sync_point);
1683 release_sync_point = 0; 1714 release_sync_point = 0;
1684 resource = resource_provider_->CreateResourceFromTextureMailbox( 1715 resource = resource_provider_->CreateResourceFromTextureMailbox(
1685 TextureMailbox(mailbox, sync_point), 1716 TextureMailbox(mailbox, sync_point),
(...skipping 15 matching lines...) Expand all
1701 context()->waitSyncPoint(list[0].sync_point); 1732 context()->waitSyncPoint(list[0].sync_point);
1702 unsigned other_texture = context()->createTexture(); 1733 unsigned other_texture = context()->createTexture();
1703 context()->bindTexture(GL_TEXTURE_2D, other_texture); 1734 context()->bindTexture(GL_TEXTURE_2D, other_texture);
1704 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1735 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1705 uint8_t test_data[4] = { 0 }; 1736 uint8_t test_data[4] = { 0 };
1706 context()->GetPixels( 1737 context()->GetPixels(
1707 gfx::Size(1, 1), RGBA_8888, test_data); 1738 gfx::Size(1, 1), RGBA_8888, test_data);
1708 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 1739 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
1709 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1740 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1710 context()->deleteTexture(other_texture); 1741 context()->deleteTexture(other_texture);
1711 list[0].sync_point = context()->insertSyncPoint(); 1742 unsigned return_sync_point = context()->insertSyncPoint();
1712 EXPECT_LT(0u, list[0].sync_point); 1743 EXPECT_LT(0u, return_sync_point);
1713 1744
1714 // Delete the resource, which shouldn't do anything. 1745 // Delete the resource, which shouldn't do anything.
1715 resource_provider_->DeleteResource(resource); 1746 resource_provider_->DeleteResource(resource);
1716 EXPECT_EQ(1u, context()->NumTextures()); 1747 EXPECT_EQ(1u, context()->NumTextures());
1717 EXPECT_EQ(0u, release_sync_point); 1748 EXPECT_EQ(0u, release_sync_point);
1718 1749
1719 // Then receive the resource which should release the mailbox, expect the 1750 // Then receive the resource which should release the mailbox, expect the
1720 // sync points to be consistent. 1751 // sync points to be consistent.
1721 ReturnedResourceArray returned; 1752 ReturnedResourceArray returned;
1722 TransferableResource::ReturnResources(list, &returned); 1753 TransferableResource::ReturnResources(list, &returned);
1754 EXPECT_EQ(1u, returned.size());
1755 returned[0].sync_point = return_sync_point;
1756
1723 resource_provider_->ReceiveReturnsFromParent(returned); 1757 resource_provider_->ReceiveReturnsFromParent(returned);
1724 EXPECT_LE(list[0].sync_point, release_sync_point); 1758 EXPECT_LE(list[0].sync_point, release_sync_point);
1725 EXPECT_FALSE(lost_resource); 1759 EXPECT_FALSE(lost_resource);
1726 } 1760 }
1727 1761
1728 context()->waitSyncPoint(release_sync_point); 1762 context()->waitSyncPoint(release_sync_point);
1729 context()->bindTexture(GL_TEXTURE_2D, texture); 1763 context()->bindTexture(GL_TEXTURE_2D, texture);
1730 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1764 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1731 context()->deleteTexture(texture); 1765 context()->deleteTexture(texture);
1732 } 1766 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 // Delete the resource in the child. Expect the resource to be lost. 2010 // Delete the resource in the child. Expect the resource to be lost.
1977 child_resource_provider_->DeleteResource(resource); 2011 child_resource_provider_->DeleteResource(resource);
1978 EXPECT_TRUE(lost_resource); 2012 EXPECT_TRUE(lost_resource);
1979 } 2013 }
1980 2014
1981 TEST_P(ResourceProviderTest, Shutdown) { 2015 TEST_P(ResourceProviderTest, Shutdown) {
1982 unsigned release_sync_point = 0; 2016 unsigned release_sync_point = 0;
1983 bool lost_resource = false; 2017 bool lost_resource = false;
1984 bool release_called = false; 2018 bool release_called = false;
1985 unsigned sync_point = 0; 2019 unsigned sync_point = 0;
1986 CreateChildMailbox( 2020 ResourceProvider::ResourceId resource = CreateChildMailbox(
1987 &release_sync_point, &lost_resource, &release_called, &sync_point); 2021 &release_sync_point, &lost_resource, &release_called, &sync_point);
1988 2022
1989 EXPECT_EQ(0u, release_sync_point); 2023 EXPECT_EQ(0u, release_sync_point);
1990 EXPECT_FALSE(lost_resource); 2024 EXPECT_FALSE(lost_resource);
1991 2025
2026 if (GetParam() == ResourceProvider::GLTexture) {
2027 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(),
2028 resource);
2029 }
2030
1992 child_resource_provider_.reset(); 2031 child_resource_provider_.reset();
1993 2032
1994 if (GetParam() == ResourceProvider::GLTexture) { 2033 if (GetParam() == ResourceProvider::GLTexture) {
1995 EXPECT_LE(sync_point, release_sync_point); 2034 EXPECT_LE(sync_point, release_sync_point);
1996 } 2035 }
1997 EXPECT_TRUE(release_called); 2036 EXPECT_TRUE(release_called);
1998 EXPECT_FALSE(lost_resource); 2037 EXPECT_FALSE(lost_resource);
1999 } 2038 }
2000 2039
2001 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { 2040 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 context()->genMailboxCHROMIUM(mailbox.name); 2072 context()->genMailboxCHROMIUM(mailbox.name);
2034 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 2073 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
2035 unsigned sync_point = context()->insertSyncPoint(); 2074 unsigned sync_point = context()->insertSyncPoint();
2036 2075
2037 EXPECT_LT(0u, sync_point); 2076 EXPECT_LT(0u, sync_point);
2038 2077
2039 unsigned release_sync_point = 0; 2078 unsigned release_sync_point = 0;
2040 bool lost_resource = false; 2079 bool lost_resource = false;
2041 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( 2080 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create(
2042 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource)); 2081 base::Bind(ReleaseTextureMailbox, &release_sync_point, &lost_resource));
2043 resource_provider_->CreateResourceFromTextureMailbox( 2082 ResourceProvider::ResourceId resource =
2044 TextureMailbox(mailbox, sync_point), 2083 resource_provider_->CreateResourceFromTextureMailbox(
2045 callback.Pass()); 2084 TextureMailbox(mailbox, sync_point), callback.Pass());
2046 2085
2047 EXPECT_EQ(0u, release_sync_point); 2086 EXPECT_EQ(0u, release_sync_point);
2048 EXPECT_FALSE(lost_resource); 2087 EXPECT_FALSE(lost_resource);
2049 2088
2089 if (GetParam() == ResourceProvider::GLTexture) {
2090 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), resource);
2091 }
2092
2050 resource_provider_->DidLoseOutputSurface(); 2093 resource_provider_->DidLoseOutputSurface();
2051 resource_provider_.reset(); 2094 resource_provider_.reset();
2052 2095
2053 EXPECT_LE(sync_point, release_sync_point); 2096 EXPECT_EQ(0u, release_sync_point);
2054 EXPECT_TRUE(lost_resource); 2097 EXPECT_TRUE(lost_resource);
2055 } 2098 }
2056 2099
2057 TEST_P(ResourceProviderTest, ScopedSampler) { 2100 TEST_P(ResourceProviderTest, ScopedSampler) {
2058 // Sampling is only supported for GL textures. 2101 // Sampling is only supported for GL textures.
2059 if (GetParam() != ResourceProvider::GLTexture) 2102 if (GetParam() != ResourceProvider::GLTexture)
2060 return; 2103 return;
2061 2104
2062 scoped_ptr<TextureStateTrackingContext> context_owned( 2105 scoped_ptr<TextureStateTrackingContext> context_owned(
2063 new TextureStateTrackingContext); 2106 new TextureStateTrackingContext);
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 resource_provider->AllocateForTesting(id); 3054 resource_provider->AllocateForTesting(id);
3012 Mock::VerifyAndClearExpectations(context); 3055 Mock::VerifyAndClearExpectations(context);
3013 3056
3014 DCHECK_EQ(10u, context->PeekTextureId()); 3057 DCHECK_EQ(10u, context->PeekTextureId());
3015 resource_provider->DeleteResource(id); 3058 resource_provider->DeleteResource(id);
3016 } 3059 }
3017 } 3060 }
3018 3061
3019 } // namespace 3062 } // namespace
3020 } // namespace cc 3063 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/transferable_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698