Chromium Code Reviews| 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/resource_provider.h" | 5 #include "cc/resource_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "cc/output_surface.h" | 9 #include "cc/output_surface.h" |
| 9 #include "cc/scoped_ptr_deque.h" | 10 #include "cc/scoped_ptr_deque.h" |
| 10 #include "cc/scoped_ptr_hash_map.h" | 11 #include "cc/scoped_ptr_hash_map.h" |
| 11 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/test_web_graphics_context_3d.h" | 13 #include "cc/test/test_web_graphics_context_3d.h" |
| 13 #include "gpu/GLES2/gl2extchromium.h" | 14 #include "gpu/GLES2/gl2extchromium.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 | 77 |
| 77 scoped_ptr<Texture> consumeTexture(const WGC3Dbyte* mailboxName, unsigned sy ncPoint) | 78 scoped_ptr<Texture> consumeTexture(const WGC3Dbyte* mailboxName, unsigned sy ncPoint) |
| 78 { | 79 { |
| 79 unsigned mailbox = 0; | 80 unsigned mailbox = 0; |
| 80 memcpy(&mailbox, mailboxName, sizeof(mailbox)); | 81 memcpy(&mailbox, mailboxName, sizeof(mailbox)); |
| 81 DCHECK(mailbox && mailbox < m_nextMailBox); | 82 DCHECK(mailbox && mailbox < m_nextMailBox); |
| 82 | 83 |
| 83 // If the latest sync point the context has waited on is before the sync | 84 // If the latest sync point the context has waited on is before the sync |
| 84 // point for when the mailbox was set, pretend we never saw that | 85 // point for when the mailbox was set, pretend we never saw that |
| 85 // produceTexture. | 86 // produceTexture. |
| 86 if (m_syncPointForMailbox[mailbox] < syncPoint) | 87 if (m_syncPointForMailbox[mailbox] > syncPoint) { |
| 88 NOTREACHED(); | |
| 87 return scoped_ptr<Texture>(); | 89 return scoped_ptr<Texture>(); |
| 90 } | |
| 88 return m_textures.take(mailbox); | 91 return m_textures.take(mailbox); |
| 89 } | 92 } |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 ContextSharedData() | 95 ContextSharedData() |
| 93 : m_nextSyncPoint(1) | 96 : m_nextSyncPoint(1) |
| 94 , m_nextMailBox(1) | 97 , m_nextMailBox(1) |
| 95 { } | 98 { } |
| 96 | 99 |
| 97 unsigned m_nextSyncPoint; | 100 unsigned m_nextSyncPoint; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 resourceIdsToTransfer.push_back(mappedId); | 560 resourceIdsToTransfer.push_back(mappedId); |
| 558 TransferableResourceList list; | 561 TransferableResourceList list; |
| 559 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, & list); | 562 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, & list); |
| 560 EXPECT_NE(0u, list.sync_point); | 563 EXPECT_NE(0u, list.sync_point); |
| 561 EXPECT_EQ(1u, list.resources.size()); | 564 EXPECT_EQ(1u, list.resources.size()); |
| 562 childResourceProvider->receiveFromParent(list); | 565 childResourceProvider->receiveFromParent(list); |
| 563 } | 566 } |
| 564 EXPECT_EQ(0u, childResourceProvider->numResources()); | 567 EXPECT_EQ(0u, childResourceProvider->numResources()); |
| 565 } | 568 } |
| 566 | 569 |
| 570 void ReleaseTextureMailbox(unsigned* releaseSyncPoint, unsigned syncPoint) { | |
| 571 *releaseSyncPoint = syncPoint; | |
| 572 } | |
| 573 | |
| 574 TEST_P(ResourceProviderTest, TransferMailboxResources) | |
| 575 { | |
| 576 // Resource transfer is only supported with GL textures for now. | |
| 577 if (GetParam() != ResourceProvider::GLTexture) | |
| 578 return; | |
| 579 unsigned texture = context()->createTexture(); | |
| 580 context()->bindTexture(GL_TEXTURE_2D, texture); | |
| 581 uint8_t data[4] = {1, 2, 3, 4}; | |
| 582 context()->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGN ED_BYTE, &data); | |
| 583 Mailbox mailbox; | |
| 584 context()->genMailboxCHROMIUM(mailbox.name); | |
| 585 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 586 unsigned syncPoint = context()->insertSyncPoint(); | |
| 587 unsigned releaseSyncPoint = 0; | |
| 588 TextureMailbox::ReleaseCallback callback = base::Bind(ReleaseTextureMailbox, &releaseSyncPoint); | |
|
danakj
2013/02/22 03:50:43
i love Bind() so much..
| |
| 589 ResourceProvider::ResourceId resource = m_resourceProvider->createResourceFr omTextureMailbox(TextureMailbox(mailbox, callback, syncPoint)); | |
| 590 EXPECT_EQ(1u, context()->textureCount()); | |
| 591 EXPECT_EQ(0u, releaseSyncPoint); | |
| 592 | |
| 593 { | |
| 594 // Transfer the resource, expect the sync points to be consistent. | |
| 595 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | |
| 596 resourceIdsToTransfer.push_back(resource); | |
| 597 TransferableResourceList list; | |
| 598 m_resourceProvider->prepareSendToParent(resourceIdsToTransfer, &list); | |
| 599 EXPECT_LE(syncPoint, list.sync_point); | |
|
danakj
2013/02/22 03:50:43
if all the sync points were 0 i think this would p
piman
2013/02/22 05:12:08
I added a check for 0 < syncPoint higher up.
| |
| 600 EXPECT_EQ(1u, list.resources.size()); | |
| 601 EXPECT_EQ(0u, memcmp(mailbox.name, list.resources[0].mailbox.name, sizeo f(mailbox.name))); | |
| 602 EXPECT_EQ(0u, releaseSyncPoint); | |
| 603 | |
| 604 context()->waitSyncPoint(list.sync_point); | |
| 605 unsigned otherTexture = context()->createTexture(); | |
| 606 context()->bindTexture(GL_TEXTURE_2D, otherTexture); | |
| 607 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 608 uint8_t testData[4] = {0}; | |
| 609 context()->getPixels(gfx::Size(1, 1), GL_RGBA, testData); | |
| 610 EXPECT_EQ(0u, memcmp(data, testData, sizeof(data))); | |
| 611 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 612 context()->deleteTexture(otherTexture); | |
| 613 list.sync_point = context()->insertSyncPoint(); | |
| 614 | |
| 615 // Receive the resource, then delete it, expect the sync points to be co nsistent. | |
| 616 m_resourceProvider->receiveFromParent(list); | |
| 617 EXPECT_EQ(1u, context()->textureCount()); | |
| 618 EXPECT_EQ(0u, releaseSyncPoint); | |
| 619 | |
| 620 m_resourceProvider->deleteResource(resource); | |
| 621 EXPECT_LE(list.sync_point, releaseSyncPoint); | |
|
danakj
2013/02/22 03:50:43
and EXPECT_NE(0u, list.sync_point) here?
piman
2013/02/22 05:12:08
Added above (_LT)
| |
| 622 } | |
| 623 | |
| 624 syncPoint = releaseSyncPoint; | |
|
danakj
2013/02/22 03:50:43
We do this whole thing a second time here to make
piman
2013/02/22 05:12:08
Done.
| |
| 625 releaseSyncPoint = 0; | |
| 626 resource = m_resourceProvider->createResourceFromTextureMailbox(TextureMailb ox(mailbox, callback, syncPoint)); | |
| 627 EXPECT_EQ(1u, context()->textureCount()); | |
| 628 EXPECT_EQ(0u, releaseSyncPoint); | |
| 629 | |
| 630 { | |
| 631 // Transfer the resource, expect the sync points to be consistent. | |
| 632 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | |
| 633 resourceIdsToTransfer.push_back(resource); | |
| 634 TransferableResourceList list; | |
| 635 m_resourceProvider->prepareSendToParent(resourceIdsToTransfer, &list); | |
| 636 EXPECT_LE(syncPoint, list.sync_point); | |
|
danakj
2013/02/22 03:50:43
add EXPECT_NE here also
piman
2013/02/22 05:12:08
Added above (_LT)
| |
| 637 EXPECT_EQ(1u, list.resources.size()); | |
| 638 EXPECT_EQ(0u, memcmp(mailbox.name, list.resources[0].mailbox.name, sizeo f(mailbox.name))); | |
| 639 EXPECT_EQ(0u, releaseSyncPoint); | |
| 640 | |
| 641 context()->waitSyncPoint(list.sync_point); | |
| 642 unsigned otherTexture = context()->createTexture(); | |
| 643 context()->bindTexture(GL_TEXTURE_2D, otherTexture); | |
| 644 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 645 uint8_t testData[4] = {0}; | |
| 646 context()->getPixels(gfx::Size(1, 1), GL_RGBA, testData); | |
| 647 EXPECT_EQ(0u, memcmp(data, testData, sizeof(data))); | |
| 648 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 649 context()->deleteTexture(otherTexture); | |
| 650 list.sync_point = context()->insertSyncPoint(); | |
| 651 | |
| 652 // Delete the resource, which shouldn't do anything. | |
| 653 m_resourceProvider->deleteResource(resource); | |
| 654 EXPECT_EQ(1u, context()->textureCount()); | |
| 655 EXPECT_EQ(0u, releaseSyncPoint); | |
| 656 | |
| 657 // Then receive the resource which should release the mailbox, expect th e sync points to be consistent. | |
| 658 m_resourceProvider->receiveFromParent(list); | |
| 659 EXPECT_LE(list.sync_point, releaseSyncPoint); | |
|
danakj
2013/02/22 03:50:43
add EXPECT_NE here also
piman
2013/02/22 05:12:08
Added above (_LT)
| |
| 660 } | |
| 661 | |
| 662 context()->waitSyncPoint(releaseSyncPoint); | |
| 663 context()->bindTexture(GL_TEXTURE_2D, texture); | |
| 664 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 665 context()->deleteTexture(texture); | |
| 666 } | |
| 667 | |
| 567 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 668 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
| 568 public: | 669 public: |
| 569 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 670 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 570 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); | 671 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); |
| 571 | 672 |
| 572 // Force all textures to be "1" so we can test for them. | 673 // Force all textures to be "1" so we can test for them. |
| 573 virtual WebKit::WebGLId NextTextureId() { return 1; } | 674 virtual WebKit::WebGLId NextTextureId() { return 1; } |
| 574 }; | 675 }; |
| 575 | 676 |
| 576 TEST_P(ResourceProviderTest, ScopedSampler) | 677 TEST_P(ResourceProviderTest, ScopedSampler) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 Mock::VerifyAndClearExpectations(context); | 837 Mock::VerifyAndClearExpectations(context); |
| 737 } | 838 } |
| 738 | 839 |
| 739 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 840 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
| 740 ResourceProviderTest, | 841 ResourceProviderTest, |
| 741 ::testing::Values(ResourceProvider::GLTexture, | 842 ::testing::Values(ResourceProvider::GLTexture, |
| 742 ResourceProvider::Bitmap)); | 843 ResourceProvider::Bitmap)); |
| 743 | 844 |
| 744 } // namespace | 845 } // namespace |
| 745 } // namespace cc | 846 } // namespace cc |
| OLD | NEW |