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..f39b52bfbcd96aa62167ac1e631426694c263bd5 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,99 @@ 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. |
+ EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, |
+ TestHelper::kServiceDefaultTextureCubemapId)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ |
+ // Expect to restore texture bindings for remaining units. |
+ for (unsigned i = 0; i < group().max_texture_units() - 1; ++i) { |
+ EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1 + i)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, |
+ TestHelper::kServiceDefaultTexture2dId)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, |
+ TestHelper::kServiceDefaultTextureCubemapId)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ } |
+ |
+ // Expect to restore the active texture unit to GL_TEXTURE0. |
+ EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ |
+ GetDecoder()->RestoreAllTextureUnitBindings(NULL); |
+} |
+ |
+TEST_F(GLES2DecoderManualInitTest, RestoreStateWithPreviousState) { |
Ken Russell (switch to Gerrit)
2014/01/08 02:56:28
Could you please add a couple more tests?
- Havi
|
+ 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); |
+ prev_state.texture_units.resize(group().max_texture_units()); |
+ for (uint32 tt = 0; tt < prev_state.texture_units.size(); ++tt) { |
+ TextureRef* ref_cube_map = |
+ group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
+ prev_state.texture_units[tt].bound_texture_cube_map = ref_cube_map; |
+ TextureRef* ref_2d = |
+ group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
+ prev_state.texture_units[tt].bound_texture_2d = ref_2d; |
+ } |
+ prev_state.active_texture_unit = 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|. |
+ EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ |
+ // Expect to restore active texture unit to GL_TEXTURE0. |
+ EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ |
+ GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); |
+} |
+ |
// TODO(gman): Complete this test. |
// TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { |
// } |