Chromium Code Reviews| Index: cc/resources/resource_provider_unittest.cc |
| diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc |
| index c3ac798d58074308f83675975c649d2015dfc3e5..e4d29ce5030292b5faea33785883ec1ac1b22e0c 100644 |
| --- a/cc/resources/resource_provider_unittest.cc |
| +++ b/cc/resources/resource_provider_unittest.cc |
| @@ -26,6 +26,7 @@ using testing::NiceMock; |
| using testing::Return; |
| using testing::StrictMock; |
| using testing::_; |
| +using WebKit::WGC3Dboolean; |
|
reveman
2013/05/17 01:48:08
what is this for?
kaanb
2013/05/17 21:27:36
Removed.
|
| using WebKit::WGC3Dbyte; |
| using WebKit::WGC3Denum; |
| using WebKit::WGC3Dint; |
| @@ -1235,7 +1236,13 @@ class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
| WGC3Denum format, |
| WGC3Denum type, |
| const void* pixels)); |
| - MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum target)); |
| + MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum)); |
| + MOCK_METHOD3(createImageCHROMIUM, WGC3Duint(WGC3Dsizei, WGC3Dsizei, |
| + WGC3Denum)); |
| + MOCK_METHOD1(destroyImageCHROMIUM, void(WGC3Duint)); |
| + MOCK_METHOD2(mapImageCHROMIUM, void*(WGC3Duint, WGC3Denum)); |
| + MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); |
| + MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); |
| }; |
| TEST_P(ResourceProviderTest, TextureAllocation) { |
| @@ -1417,6 +1424,72 @@ TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
| Mock::VerifyAndClearExpectations(context); |
| } |
| +TEST_P(ResourceProviderTest, GpuMemoryBuffers) { |
| + // Only for GL textures. |
| + if (GetParam() != ResourceProvider::GLTexture) |
| + return; |
| + scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( |
| + static_cast<WebKit::WebGraphicsContext3D*>( |
| + new StrictMock<AllocationTrackingContext3D>)); |
| + scoped_ptr<OutputSurface> output_surface( |
| + FakeOutputSurface::Create3d(mock_context.Pass())); |
| + |
| + const int kWidth = 2; |
| + const int kHeight = 2; |
| + gfx::Size size(kWidth, kHeight); |
| + WGC3Denum format = GL_RGBA; |
| + ResourceProvider::ResourceId id = 0; |
| + const unsigned kTextureId = 123u; |
| + const unsigned kImageId = 234u; |
| + |
| + AllocationTrackingContext3D* context = |
| + static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); |
| + scoped_ptr<ResourceProvider> resource_provider( |
| + ResourceProvider::Create(output_surface.get(), 0)); |
| + resource_provider->SetUseGpuMemoryBuffers(true); |
| + |
| + EXPECT_CALL(*context, createTexture()).WillOnce(Return(kTextureId)) |
| + .RetiresOnSaturation(); |
| + // First bindTexture call is within CreateResource, second is within |
| + // BeginSetPixels. |
| + EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) |
| + .RetiresOnSaturation(); |
| + id = resource_provider->CreateResource( |
| + size, format, ResourceProvider::TextureUsageAny); |
| + EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
| + .WillOnce(Return(kImageId)); |
| + resource_provider->AcquirePixelBuffer(id); |
| + |
| + EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) |
| + .RetiresOnSaturation(); |
| + EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
| + .Times(1) |
| + .RetiresOnSaturation(); |
| + resource_provider->BeginSetPixels(id); |
| + |
| + void* dummy_mapped_buffer_address = NULL; |
| + EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_WRITE_ONLY)) |
| + .WillOnce(Return(dummy_mapped_buffer_address)) |
| + .RetiresOnSaturation(); |
| + resource_provider->MapPixelBuffer(id); |
| + |
| + EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
| + .Times(1) |
| + .RetiresOnSaturation(); |
| + resource_provider->UnmapPixelBuffer(id); |
| + |
| + EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) |
| + .Times(1) |
| + .RetiresOnSaturation(); |
| + resource_provider->ReleasePixelBuffer(id); |
| + |
| + // Texture will be deleted when ResourceProvider destructor is |
| + // called when it goes out of scope when this method returns. |
| + EXPECT_CALL(*context, deleteTexture(kTextureId)) |
| + .Times(1) |
| + .RetiresOnSaturation(); |
| +} |
| + |
| INSTANTIATE_TEST_CASE_P( |
| ResourceProviderTests, |
| ResourceProviderTest, |