Index: cc/resources/resource_provider_unittest.cc |
diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc |
index 9c47cb2dc437b9c782d3b5626236d24791dab825..4896c524b705de0c5491da1b6072ffad9a123f3d 100644 |
--- a/cc/resources/resource_provider_unittest.cc |
+++ b/cc/resources/resource_provider_unittest.cc |
@@ -664,6 +664,7 @@ TEST_P(ResourceProviderTest, TransferGLResources) { |
EXPECT_NE(list[0].mailbox_holder.sync_point, |
context3d_->last_waited_sync_point()); |
{ |
+ resource_provider_->WaitSyncPointIfNeeded(list[0].id); |
ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), |
list[0].id); |
} |
@@ -753,6 +754,7 @@ TEST_P(ResourceProviderTest, TransferGLResources) { |
EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id4)); |
{ |
+ child_resource_provider_->WaitSyncPointIfNeeded(id1); |
ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), |
id1); |
ASSERT_NE(0U, lock.texture_id()); |
@@ -761,6 +763,7 @@ TEST_P(ResourceProviderTest, TransferGLResources) { |
EXPECT_EQ(0, memcmp(data1, result, pixel_size)); |
} |
{ |
+ child_resource_provider_->WaitSyncPointIfNeeded(id2); |
ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), |
id2); |
ASSERT_NE(0U, lock.texture_id()); |
@@ -769,6 +772,7 @@ TEST_P(ResourceProviderTest, TransferGLResources) { |
EXPECT_EQ(0, memcmp(data2, result, pixel_size)); |
} |
{ |
+ child_resource_provider_->WaitSyncPointIfNeeded(id3); |
ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), |
id3); |
ASSERT_NE(0U, lock.texture_id()); |
@@ -2518,9 +2522,13 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { |
Mock::VerifyAndClearExpectations(context); |
{ |
+ // Mailbox sync point WaitSyncPoint before using the texture. |
+ EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
+ resource_provider->WaitSyncPointIfNeeded(id); |
+ Mock::VerifyAndClearExpectations(context); |
+ |
// Using the texture does a consume of the mailbox. |
EXPECT_CALL(*context, bindTexture(target, texture_id)); |
- EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); |
EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
@@ -2582,9 +2590,13 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { |
Mock::VerifyAndClearExpectations(context); |
{ |
+ // Mailbox sync point WaitSyncPoint before using the texture. |
+ EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
+ resource_provider->WaitSyncPointIfNeeded(id); |
+ Mock::VerifyAndClearExpectations(context); |
+ |
// Using the texture does a consume of the mailbox. |
EXPECT_CALL(*context, bindTexture(target, texture_id)); |
- EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); |
EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
@@ -2604,6 +2616,108 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { |
} |
} |
+TEST_P(ResourceProviderTest, |
+ TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { |
+ // Mailboxing is only supported for GL textures. |
+ if (GetParam() != ResourceProvider::GLTexture) |
+ return; |
+ |
+ scoped_ptr<TextureStateTrackingContext> context_owned( |
+ new TextureStateTrackingContext); |
+ TextureStateTrackingContext* context = context_owned.get(); |
+ |
+ FakeOutputSurfaceClient output_surface_client; |
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
+ context_owned.PassAs<TestWebGraphicsContext3D>())); |
+ CHECK(output_surface->BindToClient(&output_surface_client)); |
+ |
+ scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
+ output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); |
+ |
+ uint32 sync_point = 30; |
+ unsigned target = GL_TEXTURE_2D; |
+ |
+ EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
+ EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
+ EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
+ EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
+ EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
+ |
+ gpu::Mailbox gpu_mailbox; |
+ memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
+ scoped_ptr<SingleReleaseCallback> callback = |
+ SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback)); |
+ |
+ TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
+ |
+ ResourceProvider::ResourceId id = |
+ resource_provider->CreateResourceFromTextureMailbox(mailbox, |
+ callback.Pass()); |
+ EXPECT_NE(0u, id); |
+ |
+ Mock::VerifyAndClearExpectations(context); |
+ |
+ { |
+ // First call to WaitSyncPointIfNeeded should call waitSyncPoint. |
+ EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
+ resource_provider->WaitSyncPointIfNeeded(id); |
+ Mock::VerifyAndClearExpectations(context); |
+ |
+ // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint. |
+ EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
+ resource_provider->WaitSyncPointIfNeeded(id); |
+ Mock::VerifyAndClearExpectations(context); |
+ } |
+} |
+ |
+TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) { |
+ // Mailboxing is only supported for GL textures. |
+ if (GetParam() != ResourceProvider::GLTexture) |
+ return; |
+ |
+ scoped_ptr<TextureStateTrackingContext> context_owned( |
+ new TextureStateTrackingContext); |
+ TextureStateTrackingContext* context = context_owned.get(); |
+ |
+ FakeOutputSurfaceClient output_surface_client; |
+ scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
+ context_owned.PassAs<TestWebGraphicsContext3D>())); |
+ CHECK(output_surface->BindToClient(&output_surface_client)); |
+ |
+ scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
+ output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); |
+ |
+ uint32 sync_point = 0; |
+ unsigned target = GL_TEXTURE_2D; |
+ |
+ EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
+ EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
+ EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
+ EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
+ EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
+ |
+ gpu::Mailbox gpu_mailbox; |
+ memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
+ scoped_ptr<SingleReleaseCallback> callback = |
+ SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback)); |
+ |
+ TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
+ |
+ ResourceProvider::ResourceId id = |
+ resource_provider->CreateResourceFromTextureMailbox(mailbox, |
+ callback.Pass()); |
+ EXPECT_NE(0u, id); |
+ |
+ Mock::VerifyAndClearExpectations(context); |
+ |
+ { |
+ // WaitSyncPointIfNeeded with sync_point == 0 shouldn't call waitSyncPoint. |
+ EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
+ resource_provider->WaitSyncPointIfNeeded(id); |
+ Mock::VerifyAndClearExpectations(context); |
+ } |
+} |
+ |
class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
public: |
MOCK_METHOD0(NextTextureId, GLuint()); |