Chromium Code Reviews| Index: gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc |
| diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc |
| index 1c0ec4e0dc1ee2d2c4f261cf1bddc7aef81eef24..a875f675f427fd1f374f7a4500ff16fc88f3ebf3 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| #include "gpu/command_buffer/common/id_allocator.h" |
| +#include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" |
| #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| #include "gpu/command_buffer/service/context_group.h" |
| #include "gpu/command_buffer/service/gl_surface_mock.h" |
| @@ -7935,6 +7936,125 @@ TEST_F(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) { |
| EXPECT_TRUE(info->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
| } |
| +TEST_F(GLES2DecoderManualInitTest, AsyncPixelsTransfers) { |
| + InitDecoder( |
| + "GL_CHROMIUM_async_pixel_transfers", // extensions |
| + false, false, false, // has alpha/depth/stencil |
| + false, false, false, // request alpha/depth/stencil |
| + true); // bind generates resource |
| + |
| + // Set up the texture. |
| + DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| + TextureManager::TextureInfo* info = GetTextureInfo(client_texture_id_); |
| + |
| + // Set a mock AsyncPixelTransferDelegate |
| + StrictMock<gfx::MockAsyncPixelTransferDelegate>* delegate = |
| + new StrictMock<gfx::MockAsyncPixelTransferDelegate>; |
| + decoder_->SetAsyncPixelTransferDelegate(delegate); |
| + |
| + // Set a default mock AsyncPixelTransferState |
| + scoped_refptr<StrictMock<gfx::MockAsyncPixelTransferState> > state = |
| + new StrictMock<gfx::MockAsyncPixelTransferState>; |
| + testing::DefaultValue< |
| + scoped_refptr<gfx::AsyncPixelTransferState> >::Set(state); |
| + |
| + // Tex(Sub)Image2D upload commands. |
| + AsyncTexImage2DCHROMIUM texImagecmd; |
|
greggman
2012/12/12 03:51:36
style: variables are under_score
epennerAtGoogle
2012/12/12 04:49:49
Done.
|
| + texImagecmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, |
| + GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset); |
| + AsyncTexSubImage2DCHROMIUM texSubImagecmd; |
|
greggman
2012/12/12 03:51:36
style: variables are under_score
epennerAtGoogle
2012/12/12 04:49:49
Done.
|
| + texSubImagecmd.Init(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGBA, |
| + GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset); |
| + |
| + // No transfer state exists initially. |
| + EXPECT_FALSE(info->GetAsyncTransferState()); |
| + |
| + // AsyncTexImage2D |
| + { |
| + // Create transfer state since it doesn't exist. |
| + EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId)) |
| + .WillOnce(Return(state)) |
| + .RetiresOnSaturation(); |
| + EXPECT_CALL(*delegate, AsyncTexImage2D(state.get(), _, _)) |
| + .RetiresOnSaturation(); |
| + // Command succeeds. |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(texImagecmd)); |
| + EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| + EXPECT_TRUE(info->GetAsyncTransferState()); |
| + EXPECT_TRUE(info->IsImmutable()); |
| + EXPECT_TRUE(info->SafeToRenderFrom()); |
| + } |
| + { |
| + // Async redefinitions are not allowed! |
| + // Command fails. |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(texImagecmd)); |
| + EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| + EXPECT_TRUE(info->GetAsyncTransferState()); |
| + EXPECT_TRUE(info->IsImmutable()); |
| + EXPECT_TRUE(info->SafeToRenderFrom()); |
| + } |
| + |
| + // AsyncTexSubImage2D |
| + info->SetAsyncTransferState(NULL); |
| + info->SetImmutable(false); |
| + { |
| + // Create transfer state since it doesn't exist. |
| + EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId)) |
| + .WillOnce(Return(state)) |
| + .RetiresOnSaturation(); |
| + EXPECT_CALL(*delegate, AsyncTexSubImage2D(state.get(), _, _)) |
| + .RetiresOnSaturation(); |
| + // Command succeeds. |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(texSubImagecmd)); |
| + EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| + EXPECT_TRUE(info->GetAsyncTransferState()); |
| + EXPECT_TRUE(info->IsImmutable()); |
| + EXPECT_TRUE(info->SafeToRenderFrom()); |
| + } |
| + { |
| + // No transfer is in progress. |
| + EXPECT_CALL(*state.get(), TransferIsInProgress()) |
| + .WillOnce(Return(false)) |
| + .RetiresOnSaturation(); |
| + EXPECT_CALL(*delegate, AsyncTexSubImage2D(state.get(), _, _)) |
| + .RetiresOnSaturation(); |
| + // Command succeeds. |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(texSubImagecmd)); |
| + EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| + EXPECT_TRUE(info->GetAsyncTransferState()); |
| + EXPECT_TRUE(info->IsImmutable()); |
| + EXPECT_TRUE(info->SafeToRenderFrom()); |
| + } |
| + { |
| + // A transfer is still in progress! |
| + EXPECT_CALL(*state.get(), TransferIsInProgress()) |
| + .WillOnce(Return(true)) |
| + .RetiresOnSaturation(); |
| + // No async call, command fails. |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(texSubImagecmd)); |
| + EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| + EXPECT_TRUE(info->GetAsyncTransferState()); |
| + EXPECT_TRUE(info->IsImmutable()); |
| + EXPECT_TRUE(info->SafeToRenderFrom()); |
| + } |
| + |
| + // Lazy binding of the async transfer |
| + { |
| + // We should get a real glBindTexture, followed by |
| + // a lazy bind call on the async state. |
| + testing::InSequence dummy; |
| + EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)); |
| + EXPECT_CALL(*state.get(), BindAsyncTransferToTexture(GL_TEXTURE_2D)); |
| + |
| + BindTexture bindCmd; |
|
greggman
2012/12/12 03:51:36
style: variables are under_score
epennerAtGoogle
2012/12/12 04:49:49
Done.
|
| + bindCmd.Init(GL_TEXTURE_2D, client_texture_id_); |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(bindCmd)); |
| + EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| + EXPECT_TRUE(info->SafeToRenderFrom()); |
| + } |
| +} |
| + |
| + |
| // TODO(gman): Complete this test. |
| // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { |
| // } |