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 910cb0104b214ec80de4dd7872f5a70f1904a145..05429cd50df575a0b8d0182fecf92388f24a0054 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc |
| @@ -14,6 +14,7 @@ |
| #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h" |
| #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| #include "gpu/command_buffer/service/context_group.h" |
| +#include "gpu/command_buffer/service/context_state.h" |
| #include "gpu/command_buffer/service/gl_surface_mock.h" |
| #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" |
| #include "gpu/command_buffer/service/gpu_switches.h" |
| @@ -8820,6 +8821,190 @@ TEST_F(GLES2DecoderTest, DiscardFramebufferEXTUnsupported) { |
| EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| } |
| +TEST_F(GLES2DecoderManualInitTest, RestoreState) { |
| + InitDecoder( |
| + "", // extensions |
| + false, // has alpha |
| + false, // has depth |
| + false, // has stencil |
| + false, // request alpha |
| + false, // request depth |
| + false, // request stencil |
| + false); // bind generates resource |
| + SetupTexture(); |
| + |
| + InSequence sequence; |
| + // Expect to restore texture bindings for unit GL_TEXTURE0. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); |
| + AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, |
| + TestHelper::kServiceDefaultTextureCubemapId); |
| + |
| + // Expect to restore texture bindings for remaining units. |
| + for (uint32 i = 1; i < group().max_texture_units() ; ++i) { |
| + AddExpectationsForActiveTexture(GL_TEXTURE0 + i); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, |
| + TestHelper::kServiceDefaultTexture2dId); |
| + AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, |
| + TestHelper::kServiceDefaultTextureCubemapId); |
| + } |
| + |
| + // Expect to restore the active texture unit to GL_TEXTURE0. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + |
| + GetDecoder()->RestoreAllTextureUnitBindings(NULL); |
| +} |
| + |
| +TEST_F(GLES2DecoderManualInitTest, RestoreStateWithPreviousState) { |
| + InitDecoder( |
| + "", // extensions |
| + false, // has alpha |
| + false, // has depth |
| + false, // has stencil |
| + false, // request alpha |
| + false, // request depth |
| + false, // request stencil |
| + false); // bind generates resource |
| + SetupTexture(); |
| + |
| + // Construct a previous ContextState with all texture bindings |
| + // set to default textures. |
| + ContextState prev_state(NULL, NULL); |
| + InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0); |
| + |
| + InSequence sequence; |
| + // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, |
| + // since the rest of the bindings haven't changed between the current |
| + // state and the |prev_state|. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); |
| + |
| + // Expect to restore active texture unit to GL_TEXTURE0. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + |
| + GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); |
| +} |
| + |
| +TEST_F(GLES2DecoderManualInitTest, RestoreStateActiveUnit1) { |
| + InitDecoder( |
| + "", // extensions |
| + false, // has alpha |
| + false, // has depth |
| + false, // has stencil |
| + false, // request alpha |
| + false, // request depth |
| + false, // request stencil |
| + false); // bind generates resource |
| + |
| + // Bind a non-default texture to GL_TEXTURE1 unit. |
| + EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); |
| + SpecializedSetup<ActiveTexture, 0>(true); |
|
no sievers
2014/01/13 22:06:29
I don't see the specialization for this anywhere (
kaanb
2014/01/14 22:04:22
Removed.
|
| + ActiveTexture cmd; |
| + cmd.Init(GL_TEXTURE1); |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| + EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| + SetupTexture(); |
| + |
| + // Construct a previous ContextState with all texture bindings |
| + // set to default textures. |
| + ContextState prev_state(NULL, NULL); |
| + InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0); |
| + |
| + InSequence sequence; |
| + // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit, |
| + // since the rest of the bindings haven't changed between the current |
| + // state and the |prev_state|. |
| + AddExpectationsForActiveTexture(GL_TEXTURE1); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); |
| + |
| + // Expect to restore active texture unit to GL_TEXTURE1. |
| + AddExpectationsForActiveTexture(GL_TEXTURE1); |
| + |
| + GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); |
| +} |
| + |
| +TEST_F(GLES2DecoderManualInitTest, RestoreStateNonDefaultUnit0) { |
| + InitDecoder( |
| + "", // extensions |
| + false, // has alpha |
| + false, // has depth |
| + false, // has stencil |
| + false, // request alpha |
| + false, // request depth |
| + false, // request stencil |
| + false); // bind generates resource |
| + |
| + // Bind a non-default texture to GL_TEXTURE1 unit. |
| + EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); |
| + SpecializedSetup<ActiveTexture, 0>(true); |
| + ActiveTexture cmd; |
| + cmd.Init(GL_TEXTURE1); |
| + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| + EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| + SetupTexture(); |
| + |
| + // Construct a previous ContextState with GL_TEXTURE_2D target in |
| + // GL_TEXTURE0 unit bound to a non-default texture and the rest |
| + // set to default textures. |
| + ContextState prev_state(NULL, NULL); |
| + InitializeContextState(&prev_state, 0, 0); |
|
no sievers
2014/01/13 22:06:29
nit: This would break if kServiceDefaultTexture2dI
kaanb
2014/01/14 22:04:22
Done.
|
| + |
| + InSequence sequence; |
| + // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to |
| + // a default texture. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, |
| + TestHelper::kServiceDefaultTexture2dId); |
| + |
| + // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to |
| + // non-default. |
| + AddExpectationsForActiveTexture(GL_TEXTURE1); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); |
| + |
| + // Expect to restore active texture unit to GL_TEXTURE1. |
| + AddExpectationsForActiveTexture(GL_TEXTURE1); |
| + |
| + GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); |
| +} |
| + |
| +TEST_F(GLES2DecoderManualInitTest, RestoreStateNonDefaultUnit1) { |
| + InitDecoder( |
| + "", // extensions |
| + false, // has alpha |
| + false, // has depth |
| + false, // has stencil |
| + false, // request alpha |
| + false, // request depth |
| + false, // request stencil |
| + false); // bind generates resource |
| + |
| + // Bind a non-default texture to GL_TEXTURE0 unit. |
| + SetupTexture(); |
| + |
| + // Construct a previous ContextState with GL_TEXTURE_2D target in |
| + // GL_TEXTURE1 unit bound to a non-default texture and the rest |
| + // set to default textures. |
| + ContextState prev_state(NULL, NULL); |
| + InitializeContextState(&prev_state, 1, 0); |
|
no sievers
2014/01/13 22:06:29
nit: here also use a real id (not 0).
kaanb
2014/01/14 22:04:22
Done.
|
| + |
| + InSequence sequence; |
| + // Expect to restore GL_TEXTURE_2D binding to the non-default texture |
| + // for GL_TEXTURE0 unit. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); |
| + |
| + // Expect to restore GL_TEXTURE_2D binding to the default texture |
| + // for GL_TEXTURE1 unit. |
| + AddExpectationsForActiveTexture(GL_TEXTURE1); |
| + AddExpectationsForBindTexture(GL_TEXTURE_2D, |
| + TestHelper::kServiceDefaultTexture2dId); |
| + |
| + // Expect to restore active texture unit to GL_TEXTURE0. |
| + AddExpectationsForActiveTexture(GL_TEXTURE0); |
| + |
| + GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); |
| +} |
| + |
| // TODO(gman): Complete this test. |
| // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { |
| // } |