Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 11 #include "gpu/command_buffer/common/id_allocator.h" | 11 #include "gpu/command_buffer/common/id_allocator.h" |
| 12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" | 12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" |
| 13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" | 13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
| 14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h" | 14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h" |
| 15 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 15 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 16 #include "gpu/command_buffer/service/context_group.h" | 16 #include "gpu/command_buffer/service/context_group.h" |
| 17 #include "gpu/command_buffer/service/context_state.h" | |
| 17 #include "gpu/command_buffer/service/gl_surface_mock.h" | 18 #include "gpu/command_buffer/service/gl_surface_mock.h" |
| 18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" | 19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" |
| 19 #include "gpu/command_buffer/service/gpu_switches.h" | 20 #include "gpu/command_buffer/service/gpu_switches.h" |
| 20 #include "gpu/command_buffer/service/image_manager.h" | 21 #include "gpu/command_buffer/service/image_manager.h" |
| 21 #include "gpu/command_buffer/service/mailbox_manager.h" | 22 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 22 #include "gpu/command_buffer/service/mocks.h" | 23 #include "gpu/command_buffer/service/mocks.h" |
| 23 #include "gpu/command_buffer/service/program_manager.h" | 24 #include "gpu/command_buffer/service/program_manager.h" |
| 24 #include "gpu/command_buffer/service/stream_texture_manager_mock.h" | 25 #include "gpu/command_buffer/service/stream_texture_manager_mock.h" |
| 25 #include "gpu/command_buffer/service/stream_texture_mock.h" | 26 #include "gpu/command_buffer/service/stream_texture_mock.h" |
| 26 #include "gpu/command_buffer/service/test_helper.h" | 27 #include "gpu/command_buffer/service/test_helper.h" |
| (...skipping 8786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8813 DiscardFramebufferEXTImmediate& cmd = | 8814 DiscardFramebufferEXTImmediate& cmd = |
| 8814 *GetImmediateAs<DiscardFramebufferEXTImmediate>(); | 8815 *GetImmediateAs<DiscardFramebufferEXTImmediate>(); |
| 8815 cmd.Init(target, count, attachments); | 8816 cmd.Init(target, count, attachments); |
| 8816 | 8817 |
| 8817 // Should not result into a call into GL. | 8818 // Should not result into a call into GL. |
| 8818 EXPECT_EQ(error::kNoError, | 8819 EXPECT_EQ(error::kNoError, |
| 8819 ExecuteImmediateCmd(cmd, sizeof(attachments))); | 8820 ExecuteImmediateCmd(cmd, sizeof(attachments))); |
| 8820 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); | 8821 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 8821 } | 8822 } |
| 8822 | 8823 |
| 8824 TEST_F(GLES2DecoderManualInitTest, RestoreState) { | |
| 8825 InitDecoder( | |
| 8826 "", // extensions | |
| 8827 false, // has alpha | |
| 8828 false, // has depth | |
| 8829 false, // has stencil | |
| 8830 false, // request alpha | |
| 8831 false, // request depth | |
| 8832 false, // request stencil | |
| 8833 false); // bind generates resource | |
| 8834 SetupTexture(); | |
| 8835 | |
| 8836 InSequence sequence; | |
| 8837 // Expect to restore texture bindings for unit GL_TEXTURE0. | |
| 8838 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 8839 .Times(1) | |
| 8840 .RetiresOnSaturation(); | |
| 8841 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) | |
| 8842 .Times(1) | |
| 8843 .RetiresOnSaturation(); | |
| 8844 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, | |
| 8845 TestHelper::kServiceDefaultTextureCubemapId)) | |
| 8846 .Times(1) | |
| 8847 .RetiresOnSaturation(); | |
| 8848 | |
| 8849 // Expect to restore texture bindings for remaining units. | |
| 8850 for (unsigned i = 0; i < group().max_texture_units() - 1; ++i) { | |
| 8851 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1 + i)) | |
| 8852 .Times(1) | |
| 8853 .RetiresOnSaturation(); | |
| 8854 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, | |
| 8855 TestHelper::kServiceDefaultTexture2dId)) | |
| 8856 .Times(1) | |
| 8857 .RetiresOnSaturation(); | |
| 8858 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, | |
| 8859 TestHelper::kServiceDefaultTextureCubemapId)) | |
| 8860 .Times(1) | |
| 8861 .RetiresOnSaturation(); | |
| 8862 } | |
| 8863 | |
| 8864 // Expect to restore the active texture unit to GL_TEXTURE0. | |
| 8865 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 8866 .Times(1) | |
| 8867 .RetiresOnSaturation(); | |
| 8868 | |
| 8869 GetDecoder()->RestoreAllTextureUnitBindings(NULL); | |
| 8870 } | |
| 8871 | |
| 8872 TEST_F(GLES2DecoderManualInitTest, RestoreStateWithPreviousState) { | |
| 8873 InitDecoder( | |
| 8874 "", // extensions | |
| 8875 false, // has alpha | |
| 8876 false, // has depth | |
| 8877 false, // has stencil | |
| 8878 false, // request alpha | |
| 8879 false, // request depth | |
| 8880 false, // request stencil | |
| 8881 false); // bind generates resource | |
| 8882 SetupTexture(); | |
| 8883 | |
| 8884 // Construct a previous ContextState with all texture bindings | |
| 8885 // set to default textures. | |
| 8886 ContextState prev_state(NULL, NULL); | |
| 8887 prev_state.texture_units.resize(group().max_texture_units()); | |
| 8888 for (uint32 tt = 0; tt < prev_state.texture_units.size(); ++tt) { | |
| 8889 TextureRef* ref_cube_map = | |
| 8890 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); | |
| 8891 prev_state.texture_units[tt].bound_texture_cube_map = ref_cube_map; | |
| 8892 TextureRef* ref_2d = | |
| 8893 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | |
| 8894 prev_state.texture_units[tt].bound_texture_2d = ref_2d; | |
| 8895 } | |
| 8896 prev_state.active_texture_unit = 0; | |
| 8897 | |
| 8898 InSequence sequence; | |
| 8899 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, | |
| 8900 // since the rest of the bindings haven't changed between the current | |
| 8901 // state and the |prev_state|. | |
| 8902 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 8903 .Times(1) | |
| 8904 .RetiresOnSaturation(); | |
| 8905 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) | |
| 8906 .Times(1) | |
| 8907 .RetiresOnSaturation(); | |
| 8908 | |
| 8909 // Expect to restore active texture unit to GL_TEXTURE0. | |
| 8910 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 8911 .Times(1) | |
| 8912 .RetiresOnSaturation(); | |
| 8913 | |
| 8914 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); | |
|
Ken Russell (switch to Gerrit)
2014/01/09 00:09:08
These tests look good but there's a lot of duplica
Ken Russell (switch to Gerrit)
2014/01/09 00:11:02
Also, in case it's helpful, see calls to Mock::Ver
| |
| 8915 } | |
| 8916 | |
| 8917 TEST_F(GLES2DecoderManualInitTest, RestoreStateActiveUnit1) { | |
| 8918 InitDecoder( | |
| 8919 "", // extensions | |
| 8920 false, // has alpha | |
| 8921 false, // has depth | |
| 8922 false, // has stencil | |
| 8923 false, // request alpha | |
| 8924 false, // request depth | |
| 8925 false, // request stencil | |
| 8926 false); // bind generates resource | |
| 8927 | |
| 8928 // Bind a non-default texture to GL_TEXTURE1 unit. | |
| 8929 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); | |
| 8930 SpecializedSetup<ActiveTexture, 0>(true); | |
| 8931 ActiveTexture cmd; | |
| 8932 cmd.Init(GL_TEXTURE1); | |
| 8933 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | |
| 8934 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | |
| 8935 SetupTexture(); | |
| 8936 | |
| 8937 // Construct a previous ContextState with all texture bindings | |
| 8938 // set to default textures. | |
| 8939 ContextState prev_state(NULL, NULL); | |
| 8940 prev_state.texture_units.resize(group().max_texture_units()); | |
| 8941 for (uint32 tt = 0; tt < prev_state.texture_units.size(); ++tt) { | |
| 8942 TextureRef* ref_cube_map = | |
| 8943 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); | |
| 8944 prev_state.texture_units[tt].bound_texture_cube_map = ref_cube_map; | |
| 8945 TextureRef* ref_2d = | |
| 8946 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | |
| 8947 prev_state.texture_units[tt].bound_texture_2d = ref_2d; | |
| 8948 } | |
| 8949 prev_state.active_texture_unit = 0; | |
| 8950 | |
| 8951 InSequence sequence; | |
| 8952 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit, | |
| 8953 // since the rest of the bindings haven't changed between the current | |
| 8954 // state and the |prev_state|. | |
| 8955 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)) | |
| 8956 .Times(1) | |
| 8957 .RetiresOnSaturation(); | |
| 8958 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) | |
| 8959 .Times(1) | |
| 8960 .RetiresOnSaturation(); | |
| 8961 | |
| 8962 // Expect to restore active texture unit to GL_TEXTURE1. | |
| 8963 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)) | |
| 8964 .Times(1) | |
| 8965 .RetiresOnSaturation(); | |
| 8966 | |
| 8967 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); | |
| 8968 } | |
| 8969 | |
| 8970 TEST_F(GLES2DecoderManualInitTest, RestoreStateNonDefaultUnit0) { | |
| 8971 InitDecoder( | |
| 8972 "", // extensions | |
| 8973 false, // has alpha | |
| 8974 false, // has depth | |
| 8975 false, // has stencil | |
| 8976 false, // request alpha | |
| 8977 false, // request depth | |
| 8978 false, // request stencil | |
| 8979 false); // bind generates resource | |
| 8980 | |
| 8981 // Bind a non-default texture to GL_TEXTURE1 unit. | |
| 8982 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); | |
| 8983 SpecializedSetup<ActiveTexture, 0>(true); | |
| 8984 ActiveTexture cmd; | |
| 8985 cmd.Init(GL_TEXTURE1); | |
| 8986 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | |
| 8987 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | |
| 8988 SetupTexture(); | |
| 8989 | |
| 8990 // Construct a previous ContextState with GL_TEXTURE_2D target in | |
| 8991 // GL_TEXTURE0 unit bound to a non-default texture and the rest | |
| 8992 // set to default textures. | |
| 8993 ContextState prev_state(NULL, NULL); | |
| 8994 prev_state.texture_units.resize(group().max_texture_units()); | |
| 8995 for (uint32 tt = 0; tt < prev_state.texture_units.size(); ++tt) { | |
| 8996 TextureRef* ref_cube_map = | |
| 8997 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); | |
| 8998 prev_state.texture_units[tt].bound_texture_cube_map = ref_cube_map; | |
| 8999 TextureRef* ref_2d = | |
| 9000 (tt == 0) ? group().texture_manager()->GetTexture(client_texture_id_) | |
| 9001 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | |
| 9002 prev_state.texture_units[tt].bound_texture_2d = ref_2d; | |
| 9003 } | |
| 9004 prev_state.active_texture_unit = 0; | |
| 9005 | |
| 9006 InSequence sequence; | |
| 9007 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to | |
| 9008 // a default texture. | |
| 9009 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 9010 .Times(1) | |
| 9011 .RetiresOnSaturation(); | |
| 9012 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, | |
| 9013 TestHelper::kServiceDefaultTexture2dId)) | |
| 9014 .Times(1) | |
| 9015 .RetiresOnSaturation(); | |
| 9016 | |
| 9017 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to | |
| 9018 // non-default. | |
| 9019 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)) | |
| 9020 .Times(1) | |
| 9021 .RetiresOnSaturation(); | |
| 9022 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, | |
| 9023 kServiceTextureId)) | |
| 9024 .Times(1) | |
| 9025 .RetiresOnSaturation(); | |
| 9026 | |
| 9027 // Expect to restore active texture unit to GL_TEXTURE1. | |
| 9028 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)) | |
| 9029 .Times(1) | |
| 9030 .RetiresOnSaturation(); | |
| 9031 | |
| 9032 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); | |
| 9033 } | |
| 9034 | |
| 9035 TEST_F(GLES2DecoderManualInitTest, RestoreStateNonDefaultUnit1) { | |
| 9036 InitDecoder( | |
| 9037 "", // extensions | |
| 9038 false, // has alpha | |
| 9039 false, // has depth | |
| 9040 false, // has stencil | |
| 9041 false, // request alpha | |
| 9042 false, // request depth | |
| 9043 false, // request stencil | |
| 9044 false); // bind generates resource | |
| 9045 | |
| 9046 // Bind a non-default texture to GL_TEXTURE0 unit. | |
| 9047 SetupTexture(); | |
| 9048 | |
| 9049 // Construct a previous ContextState with GL_TEXTURE_2D target in | |
| 9050 // GL_TEXTURE1 unit bound to a non-default texture and the rest | |
| 9051 // set to default textures. | |
| 9052 ContextState prev_state(NULL, NULL); | |
| 9053 prev_state.texture_units.resize(group().max_texture_units()); | |
| 9054 for (uint32 tt = 0; tt < prev_state.texture_units.size(); ++tt) { | |
| 9055 TextureRef* ref_cube_map = | |
| 9056 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); | |
| 9057 prev_state.texture_units[tt].bound_texture_cube_map = ref_cube_map; | |
| 9058 TextureRef* ref_2d = | |
| 9059 (tt == 1) ? group().texture_manager()->GetTexture(client_texture_id_) | |
| 9060 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | |
| 9061 prev_state.texture_units[tt].bound_texture_2d = ref_2d; | |
| 9062 } | |
| 9063 prev_state.active_texture_unit = 0; | |
| 9064 | |
| 9065 InSequence sequence; | |
| 9066 // Expect to restore GL_TEXTURE_2D binding to the non-default texture | |
| 9067 // for GL_TEXTURE0 unit. | |
| 9068 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 9069 .Times(1) | |
| 9070 .RetiresOnSaturation(); | |
| 9071 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) | |
| 9072 .Times(1) | |
| 9073 .RetiresOnSaturation(); | |
| 9074 // Expect to restore GL_TEXTURE_2D binding to the default texture | |
| 9075 // for GL_TEXTURE1 unit. | |
| 9076 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)) | |
| 9077 .Times(1) | |
| 9078 .RetiresOnSaturation(); | |
| 9079 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, | |
| 9080 TestHelper::kServiceDefaultTexture2dId)) | |
| 9081 .Times(1) | |
| 9082 .RetiresOnSaturation(); | |
| 9083 | |
| 9084 // Expect to restore active texture unit to GL_TEXTURE0. | |
| 9085 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | |
| 9086 .Times(1) | |
| 9087 .RetiresOnSaturation(); | |
| 9088 | |
| 9089 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); | |
| 9090 } | |
| 9091 | |
| 8823 // TODO(gman): Complete this test. | 9092 // TODO(gman): Complete this test. |
| 8824 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { | 9093 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { |
| 8825 // } | 9094 // } |
| 8826 | 9095 |
| 8827 // TODO(gman): BufferData | 9096 // TODO(gman): BufferData |
| 8828 | 9097 |
| 8829 // TODO(gman): BufferDataImmediate | 9098 // TODO(gman): BufferDataImmediate |
| 8830 | 9099 |
| 8831 // TODO(gman): BufferSubData | 9100 // TODO(gman): BufferSubData |
| 8832 | 9101 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 8849 // TODO(gman): TexImage2DImmediate | 9118 // TODO(gman): TexImage2DImmediate |
| 8850 | 9119 |
| 8851 // TODO(gman): TexSubImage2DImmediate | 9120 // TODO(gman): TexSubImage2DImmediate |
| 8852 | 9121 |
| 8853 // TODO(gman): UseProgram | 9122 // TODO(gman): UseProgram |
| 8854 | 9123 |
| 8855 // TODO(gman): SwapBuffers | 9124 // TODO(gman): SwapBuffers |
| 8856 | 9125 |
| 8857 } // namespace gles2 | 9126 } // namespace gles2 |
| 8858 } // namespace gpu | 9127 } // namespace gpu |
| OLD | NEW |