Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc

Issue 118203002: During virtual context switches only restore texture units that have changed from the previous cont… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change mock GetContextState to return const ContextState* instead of non-const Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_mock.h ('k') | ui/gl/gl_gl_api_implementation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 class GLES2DecoderManualInitTest : public GLES2DecoderWithShaderTest { 135 class GLES2DecoderManualInitTest : public GLES2DecoderWithShaderTest {
135 public: 136 public:
136 GLES2DecoderManualInitTest() { } 137 GLES2DecoderManualInitTest() { }
137 138
138 // Override default setup so nothing gets setup. 139 // Override default setup so nothing gets setup.
139 virtual void SetUp() { 140 virtual void SetUp() {
140 } 141 }
141 }; 142 };
142 143
144 class GLES2DecoderRestoreStateTest : public GLES2DecoderManualInitTest {
145 public:
146 GLES2DecoderRestoreStateTest() { }
147
148 protected:
149 void AddExpectationsForActiveTexture(GLenum unit);
150 void AddExpectationsForBindTexture(GLenum target, GLuint id);
151 void InitializeContextState(
152 ContextState* state, uint32 non_default_unit, uint32 active_unit);
153 };
154
155 void GLES2DecoderRestoreStateTest::AddExpectationsForActiveTexture(
156 GLenum unit) {
157 EXPECT_CALL(*gl_, ActiveTexture(unit))
158 .Times(1)
159 .RetiresOnSaturation();
160 }
161
162 void GLES2DecoderRestoreStateTest::AddExpectationsForBindTexture(GLenum target,
163 GLuint id) {
164 EXPECT_CALL(*gl_, BindTexture(target, id))
165 .Times(1)
166 .RetiresOnSaturation();
167 }
168
169 void GLES2DecoderRestoreStateTest::InitializeContextState(
170 ContextState* state, uint32 non_default_unit, uint32 active_unit) {
171 state->texture_units.resize(group().max_texture_units());
172 for (uint32 tt = 0; tt < state->texture_units.size(); ++tt) {
173 TextureRef* ref_cube_map =
174 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
175 state->texture_units[tt].bound_texture_cube_map = ref_cube_map;
176 TextureRef* ref_2d =
177 (tt == non_default_unit)
178 ? group().texture_manager()->GetTexture(client_texture_id_)
179 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
180 state->texture_units[tt].bound_texture_2d = ref_2d;
181 }
182 state->active_texture_unit = active_unit;
183 }
184
143 TEST_F(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) { 185 TEST_F(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) {
144 SetupTexture(); 186 SetupTexture();
145 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); 187 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
146 SetupExpectationsForApplyingDefaultDirtyState(); 188 SetupExpectationsForApplyingDefaultDirtyState();
147 189
148 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) 190 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
149 .Times(1) 191 .Times(1)
150 .RetiresOnSaturation(); 192 .RetiresOnSaturation();
151 DrawArrays cmd; 193 DrawArrays cmd;
152 cmd.Init(GL_TRIANGLES, 0, kNumVertices); 194 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
(...skipping 8660 matching lines...) Expand 10 before | Expand all | Expand 10 after
8813 DiscardFramebufferEXTImmediate& cmd = 8855 DiscardFramebufferEXTImmediate& cmd =
8814 *GetImmediateAs<DiscardFramebufferEXTImmediate>(); 8856 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
8815 cmd.Init(target, count, attachments); 8857 cmd.Init(target, count, attachments);
8816 8858
8817 // Should not result into a call into GL. 8859 // Should not result into a call into GL.
8818 EXPECT_EQ(error::kNoError, 8860 EXPECT_EQ(error::kNoError,
8819 ExecuteImmediateCmd(cmd, sizeof(attachments))); 8861 ExecuteImmediateCmd(cmd, sizeof(attachments)));
8820 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 8862 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8821 } 8863 }
8822 8864
8865 TEST_F(GLES2DecoderRestoreStateTest, NullPreviousState) {
8866 InitDecoder(
8867 "", // extensions
8868 false, // has alpha
8869 false, // has depth
8870 false, // has stencil
8871 false, // request alpha
8872 false, // request depth
8873 false, // request stencil
8874 false); // bind generates resource
8875 SetupTexture();
8876
8877 InSequence sequence;
8878 // Expect to restore texture bindings for unit GL_TEXTURE0.
8879 AddExpectationsForActiveTexture(GL_TEXTURE0);
8880 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
8881 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
8882 TestHelper::kServiceDefaultTextureCubemapId);
8883
8884 // Expect to restore texture bindings for remaining units.
8885 for (uint32 i = 1; i < group().max_texture_units() ; ++i) {
8886 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
8887 AddExpectationsForBindTexture(GL_TEXTURE_2D,
8888 TestHelper::kServiceDefaultTexture2dId);
8889 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
8890 TestHelper::kServiceDefaultTextureCubemapId);
8891 }
8892
8893 // Expect to restore the active texture unit to GL_TEXTURE0.
8894 AddExpectationsForActiveTexture(GL_TEXTURE0);
8895
8896 GetDecoder()->RestoreAllTextureUnitBindings(NULL);
8897 }
8898
8899 TEST_F(GLES2DecoderRestoreStateTest, WithPreviousState) {
8900 InitDecoder(
8901 "", // extensions
8902 false, // has alpha
8903 false, // has depth
8904 false, // has stencil
8905 false, // request alpha
8906 false, // request depth
8907 false, // request stencil
8908 false); // bind generates resource
8909 SetupTexture();
8910
8911 // Construct a previous ContextState with all texture bindings
8912 // set to default textures.
8913 ContextState prev_state(NULL, NULL);
8914 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
8915
8916 InSequence sequence;
8917 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
8918 // since the rest of the bindings haven't changed between the current
8919 // state and the |prev_state|.
8920 AddExpectationsForActiveTexture(GL_TEXTURE0);
8921 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
8922
8923 // Expect to restore active texture unit to GL_TEXTURE0.
8924 AddExpectationsForActiveTexture(GL_TEXTURE0);
8925
8926 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
8927 }
8928
8929 TEST_F(GLES2DecoderRestoreStateTest, ActiveUnit1) {
8930 InitDecoder(
8931 "", // extensions
8932 false, // has alpha
8933 false, // has depth
8934 false, // has stencil
8935 false, // request alpha
8936 false, // request depth
8937 false, // request stencil
8938 false); // bind generates resource
8939
8940 // Bind a non-default texture to GL_TEXTURE1 unit.
8941 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
8942 ActiveTexture cmd;
8943 cmd.Init(GL_TEXTURE1);
8944 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8945 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8946 SetupTexture();
8947
8948 // Construct a previous ContextState with all texture bindings
8949 // set to default textures.
8950 ContextState prev_state(NULL, NULL);
8951 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
8952
8953 InSequence sequence;
8954 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit,
8955 // since the rest of the bindings haven't changed between the current
8956 // state and the |prev_state|.
8957 AddExpectationsForActiveTexture(GL_TEXTURE1);
8958 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
8959
8960 // Expect to restore active texture unit to GL_TEXTURE1.
8961 AddExpectationsForActiveTexture(GL_TEXTURE1);
8962
8963 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
8964 }
8965
8966 TEST_F(GLES2DecoderRestoreStateTest, NonDefaultUnit0) {
8967 InitDecoder(
8968 "", // extensions
8969 false, // has alpha
8970 false, // has depth
8971 false, // has stencil
8972 false, // request alpha
8973 false, // request depth
8974 false, // request stencil
8975 false); // bind generates resource
8976
8977 // Bind a non-default texture to GL_TEXTURE1 unit.
8978 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
8979 SpecializedSetup<ActiveTexture, 0>(true);
8980 ActiveTexture cmd;
8981 cmd.Init(GL_TEXTURE1);
8982 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8983 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8984 SetupTexture();
8985
8986 // Construct a previous ContextState with GL_TEXTURE_2D target in
8987 // GL_TEXTURE0 unit bound to a non-default texture and the rest
8988 // set to default textures.
8989 ContextState prev_state(NULL, NULL);
8990 InitializeContextState(&prev_state, 0, kServiceTextureId);
8991
8992 InSequence sequence;
8993 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
8994 // a default texture.
8995 AddExpectationsForActiveTexture(GL_TEXTURE0);
8996 AddExpectationsForBindTexture(GL_TEXTURE_2D,
8997 TestHelper::kServiceDefaultTexture2dId);
8998
8999 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
9000 // non-default.
9001 AddExpectationsForActiveTexture(GL_TEXTURE1);
9002 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
9003
9004 // Expect to restore active texture unit to GL_TEXTURE1.
9005 AddExpectationsForActiveTexture(GL_TEXTURE1);
9006
9007 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
9008 }
9009
9010 TEST_F(GLES2DecoderRestoreStateTest, NonDefaultUnit1) {
9011 InitDecoder(
9012 "", // extensions
9013 false, // has alpha
9014 false, // has depth
9015 false, // has stencil
9016 false, // request alpha
9017 false, // request depth
9018 false, // request stencil
9019 false); // bind generates resource
9020
9021 // Bind a non-default texture to GL_TEXTURE0 unit.
9022 SetupTexture();
9023
9024 // Construct a previous ContextState with GL_TEXTURE_2D target in
9025 // GL_TEXTURE1 unit bound to a non-default texture and the rest
9026 // set to default textures.
9027 ContextState prev_state(NULL, NULL);
9028 InitializeContextState(&prev_state, 1, kServiceTextureId);
9029
9030 InSequence sequence;
9031 // Expect to restore GL_TEXTURE_2D binding to the non-default texture
9032 // for GL_TEXTURE0 unit.
9033 AddExpectationsForActiveTexture(GL_TEXTURE0);
9034 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
9035
9036 // Expect to restore GL_TEXTURE_2D binding to the default texture
9037 // for GL_TEXTURE1 unit.
9038 AddExpectationsForActiveTexture(GL_TEXTURE1);
9039 AddExpectationsForBindTexture(GL_TEXTURE_2D,
9040 TestHelper::kServiceDefaultTexture2dId);
9041
9042 // Expect to restore active texture unit to GL_TEXTURE0.
9043 AddExpectationsForActiveTexture(GL_TEXTURE0);
9044
9045 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
9046 }
9047
8823 // TODO(gman): Complete this test. 9048 // TODO(gman): Complete this test.
8824 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { 9049 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) {
8825 // } 9050 // }
8826 9051
8827 // TODO(gman): BufferData 9052 // TODO(gman): BufferData
8828 9053
8829 // TODO(gman): BufferDataImmediate 9054 // TODO(gman): BufferDataImmediate
8830 9055
8831 // TODO(gman): BufferSubData 9056 // TODO(gman): BufferSubData
8832 9057
(...skipping 16 matching lines...) Expand all
8849 // TODO(gman): TexImage2DImmediate 9074 // TODO(gman): TexImage2DImmediate
8850 9075
8851 // TODO(gman): TexSubImage2DImmediate 9076 // TODO(gman): TexSubImage2DImmediate
8852 9077
8853 // TODO(gman): UseProgram 9078 // TODO(gman): UseProgram
8854 9079
8855 // TODO(gman): SwapBuffers 9080 // TODO(gman): SwapBuffers
8856 9081
8857 } // namespace gles2 9082 } // namespace gles2
8858 } // namespace gpu 9083 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_mock.h ('k') | ui/gl/gl_gl_api_implementation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698