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

Side by Side Diff: cc/resource_provider_unittest.cc

Issue 12315046: cc: Make ResourceProvider correctly handle transferring mailbox-created resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 10 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
« no previous file with comments | « cc/resource_provider.cc ('k') | no next file » | 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/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
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
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
588 // All the logic below assumes that the sync points are all positive.
589 EXPECT_LT(0u, syncPoint);
590
591 unsigned releaseSyncPoint = 0;
592 TextureMailbox::ReleaseCallback callback = base::Bind(ReleaseTextureMailbox, &releaseSyncPoint);
593 ResourceProvider::ResourceId resource = m_resourceProvider->createResourceFr omTextureMailbox(TextureMailbox(mailbox, callback, syncPoint));
594 EXPECT_EQ(1u, context()->textureCount());
595 EXPECT_EQ(0u, releaseSyncPoint);
596
597 {
598 // Transfer the resource, expect the sync points to be consistent.
599 ResourceProvider::ResourceIdArray resourceIdsToTransfer;
600 resourceIdsToTransfer.push_back(resource);
601 TransferableResourceList list;
602 m_resourceProvider->prepareSendToParent(resourceIdsToTransfer, &list);
603 EXPECT_LE(syncPoint, list.sync_point);
604 EXPECT_EQ(1u, list.resources.size());
605 EXPECT_EQ(0u, memcmp(mailbox.name, list.resources[0].mailbox.name, sizeo f(mailbox.name)));
606 EXPECT_EQ(0u, releaseSyncPoint);
607
608 context()->waitSyncPoint(list.sync_point);
609 unsigned otherTexture = context()->createTexture();
610 context()->bindTexture(GL_TEXTURE_2D, otherTexture);
611 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
612 uint8_t testData[4] = {0};
613 context()->getPixels(gfx::Size(1, 1), GL_RGBA, testData);
614 EXPECT_EQ(0u, memcmp(data, testData, sizeof(data)));
615 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
616 context()->deleteTexture(otherTexture);
617 list.sync_point = context()->insertSyncPoint();
618 EXPECT_LT(0u, list.sync_point);
619
620 // Receive the resource, then delete it, expect the sync points to be co nsistent.
621 m_resourceProvider->receiveFromParent(list);
622 EXPECT_EQ(1u, context()->textureCount());
623 EXPECT_EQ(0u, releaseSyncPoint);
624
625 m_resourceProvider->deleteResource(resource);
626 EXPECT_LE(list.sync_point, releaseSyncPoint);
627 }
628
629
630 // We're going to do the same thing as above, but testing the case where we
631 // delete the resource before we receive it back.
632 syncPoint = releaseSyncPoint;
633 EXPECT_LT(0u, syncPoint);
634 releaseSyncPoint = 0;
635 resource = m_resourceProvider->createResourceFromTextureMailbox(TextureMailb ox(mailbox, callback, syncPoint));
636 EXPECT_EQ(1u, context()->textureCount());
637 EXPECT_EQ(0u, releaseSyncPoint);
638
639 {
640 // Transfer the resource, expect the sync points to be consistent.
641 ResourceProvider::ResourceIdArray resourceIdsToTransfer;
642 resourceIdsToTransfer.push_back(resource);
643 TransferableResourceList list;
644 m_resourceProvider->prepareSendToParent(resourceIdsToTransfer, &list);
645 EXPECT_LE(syncPoint, list.sync_point);
646 EXPECT_EQ(1u, list.resources.size());
647 EXPECT_EQ(0u, memcmp(mailbox.name, list.resources[0].mailbox.name, sizeo f(mailbox.name)));
648 EXPECT_EQ(0u, releaseSyncPoint);
649
650 context()->waitSyncPoint(list.sync_point);
651 unsigned otherTexture = context()->createTexture();
652 context()->bindTexture(GL_TEXTURE_2D, otherTexture);
653 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
654 uint8_t testData[4] = {0};
655 context()->getPixels(gfx::Size(1, 1), GL_RGBA, testData);
656 EXPECT_EQ(0u, memcmp(data, testData, sizeof(data)));
657 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
658 context()->deleteTexture(otherTexture);
659 list.sync_point = context()->insertSyncPoint();
660 EXPECT_LT(0u, list.sync_point);
661
662 // Delete the resource, which shouldn't do anything.
663 m_resourceProvider->deleteResource(resource);
664 EXPECT_EQ(1u, context()->textureCount());
665 EXPECT_EQ(0u, releaseSyncPoint);
666
667 // Then receive the resource which should release the mailbox, expect th e sync points to be consistent.
668 m_resourceProvider->receiveFromParent(list);
669 EXPECT_LE(list.sync_point, releaseSyncPoint);
670 }
671
672 context()->waitSyncPoint(releaseSyncPoint);
673 context()->bindTexture(GL_TEXTURE_2D, texture);
674 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
675 context()->deleteTexture(texture);
676 }
677
567 class TextureStateTrackingContext : public TestWebGraphicsContext3D { 678 class TextureStateTrackingContext : public TestWebGraphicsContext3D {
568 public: 679 public:
569 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); 680 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture));
570 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); 681 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
571 682
572 // Force all textures to be "1" so we can test for them. 683 // Force all textures to be "1" so we can test for them.
573 virtual WebKit::WebGLId NextTextureId() { return 1; } 684 virtual WebKit::WebGLId NextTextureId() { return 1; }
574 }; 685 };
575 686
576 TEST_P(ResourceProviderTest, ScopedSampler) 687 TEST_P(ResourceProviderTest, ScopedSampler)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 Mock::VerifyAndClearExpectations(context); 847 Mock::VerifyAndClearExpectations(context);
737 } 848 }
738 849
739 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, 850 INSTANTIATE_TEST_CASE_P(ResourceProviderTests,
740 ResourceProviderTest, 851 ResourceProviderTest,
741 ::testing::Values(ResourceProvider::GLTexture, 852 ::testing::Values(ResourceProvider::GLTexture,
742 ResourceProvider::Bitmap)); 853 ResourceProvider::Bitmap));
743 854
744 } // namespace 855 } // namespace
745 } // namespace cc 856 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resource_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698