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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "gpu/command_buffer/common/gles2_cmd_format.h"
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
10 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/program_manager.h"
13 #include "gpu/command_buffer/service/test_helper.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gl/gl_mock.h"
17 using ::gfx::MockGLInterface
;
19 using ::testing::AnyNumber
;
20 using ::testing::DoAll
;
21 using ::testing::InSequence
;
22 using ::testing::MatcherCast
;
23 using ::testing::Pointee
;
24 using ::testing::Return
;
25 using ::testing::SetArrayArgument
;
26 using ::testing::SetArgumentPointee
;
27 using ::testing::StrEq
;
32 class GLES2DecoderTest2
: public GLES2DecoderTestBase
{
34 GLES2DecoderTest2() { }
36 void TestAcceptedUniform(GLenum uniform_type
, uint32 accepts_apis
) {
37 SetupShaderForUniform(uniform_type
);
38 bool valid_uniform
= false;
40 EXPECT_CALL(*gl_
, Uniform1i(1, _
)).Times(AnyNumber());
41 EXPECT_CALL(*gl_
, Uniform1iv(1, _
, _
)).Times(AnyNumber());
42 EXPECT_CALL(*gl_
, Uniform2iv(1, _
, _
)).Times(AnyNumber());
43 EXPECT_CALL(*gl_
, Uniform3iv(1, _
, _
)).Times(AnyNumber());
44 EXPECT_CALL(*gl_
, Uniform4iv(1, _
, _
)).Times(AnyNumber());
45 EXPECT_CALL(*gl_
, Uniform1f(1, _
)).Times(AnyNumber());
46 EXPECT_CALL(*gl_
, Uniform1fv(1, _
, _
)).Times(AnyNumber());
47 EXPECT_CALL(*gl_
, Uniform2fv(1, _
, _
)).Times(AnyNumber());
48 EXPECT_CALL(*gl_
, Uniform3fv(1, _
, _
)).Times(AnyNumber());
49 EXPECT_CALL(*gl_
, Uniform4fv(1, _
, _
)).Times(AnyNumber());
50 EXPECT_CALL(*gl_
, UniformMatrix2fv(1, _
, _
, _
)).Times(AnyNumber());
51 EXPECT_CALL(*gl_
, UniformMatrix3fv(1, _
, _
, _
)).Times(AnyNumber());
52 EXPECT_CALL(*gl_
, UniformMatrix4fv(1, _
, _
, _
)).Times(AnyNumber());
55 valid_uniform
= accepts_apis
& Program::kUniform1i
;
58 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
59 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
64 valid_uniform
= accepts_apis
& Program::kUniform1i
;
65 cmds::Uniform1ivImmediate
& cmd
=
66 *GetImmediateAs
<cmds::Uniform1ivImmediate
>();
67 GLint data
[2][1] = {{0}};
68 cmd
.Init(1, 2, &data
[0][0]);
69 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
70 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
75 valid_uniform
= accepts_apis
& Program::kUniform2i
;
78 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
79 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
84 valid_uniform
= accepts_apis
& Program::kUniform2i
;
85 cmds::Uniform2ivImmediate
& cmd
=
86 *GetImmediateAs
<cmds::Uniform2ivImmediate
>();
87 GLint data
[2][2] = {{0}};
88 cmd
.Init(1, 2, &data
[0][0]);
89 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
90 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
95 valid_uniform
= accepts_apis
& Program::kUniform3i
;
98 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
99 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
104 valid_uniform
= accepts_apis
& Program::kUniform3i
;
105 cmds::Uniform3ivImmediate
& cmd
=
106 *GetImmediateAs
<cmds::Uniform3ivImmediate
>();
107 GLint data
[2][3] = {{0}};
108 cmd
.Init(1, 2, &data
[0][0]);
109 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
110 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
115 valid_uniform
= accepts_apis
& Program::kUniform4i
;
117 cmd
.Init(1, 2, 3, 4, 5);
118 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
119 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
124 valid_uniform
= accepts_apis
& Program::kUniform4i
;
125 cmds::Uniform4ivImmediate
& cmd
=
126 *GetImmediateAs
<cmds::Uniform4ivImmediate
>();
127 GLint data
[2][4] = {{0}};
128 cmd
.Init(1, 2, &data
[0][0]);
129 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
130 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
137 valid_uniform
= accepts_apis
& Program::kUniform1f
;
140 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
141 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
146 valid_uniform
= accepts_apis
& Program::kUniform1f
;
147 cmds::Uniform1fvImmediate
& cmd
=
148 *GetImmediateAs
<cmds::Uniform1fvImmediate
>();
149 GLfloat data
[2][1] = {{0.0f
}};
150 cmd
.Init(1, 2, &data
[0][0]);
151 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
152 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
157 valid_uniform
= accepts_apis
& Program::kUniform2f
;
160 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
161 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
166 valid_uniform
= accepts_apis
& Program::kUniform2f
;
167 cmds::Uniform2fvImmediate
& cmd
=
168 *GetImmediateAs
<cmds::Uniform2fvImmediate
>();
169 GLfloat data
[2][2] = {{0.0f
}};
170 cmd
.Init(1, 2, &data
[0][0]);
171 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
172 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
177 valid_uniform
= accepts_apis
& Program::kUniform3f
;
179 cmd
.Init(1, 2, 3, 4);
180 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
181 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
186 valid_uniform
= accepts_apis
& Program::kUniform3f
;
187 cmds::Uniform3fvImmediate
& cmd
=
188 *GetImmediateAs
<cmds::Uniform3fvImmediate
>();
189 GLfloat data
[2][3] = {{0.0f
}};
190 cmd
.Init(1, 2, &data
[0][0]);
191 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
192 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
197 valid_uniform
= accepts_apis
& Program::kUniform4f
;
199 cmd
.Init(1, 2, 3, 4, 5);
200 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
201 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
206 valid_uniform
= accepts_apis
& Program::kUniform4f
;
207 cmds::Uniform4fvImmediate
& cmd
=
208 *GetImmediateAs
<cmds::Uniform4fvImmediate
>();
209 GLfloat data
[2][4] = {{0.0f
}};
210 cmd
.Init(1, 2, &data
[0][0]);
211 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
212 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
217 valid_uniform
= accepts_apis
& Program::kUniformMatrix2f
;
218 cmds::UniformMatrix2fvImmediate
& cmd
=
219 *GetImmediateAs
<cmds::UniformMatrix2fvImmediate
>();
220 GLfloat data
[2][2 * 2] = {{0.0f
}};
222 cmd
.Init(1, 2, &data
[0][0]);
223 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
224 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
229 valid_uniform
= accepts_apis
& Program::kUniformMatrix3f
;
230 cmds::UniformMatrix3fvImmediate
& cmd
=
231 *GetImmediateAs
<cmds::UniformMatrix3fvImmediate
>();
232 GLfloat data
[2][3 * 3] = {{0.0f
}};
233 cmd
.Init(1, 2, &data
[0][0]);
234 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
235 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
240 valid_uniform
= accepts_apis
& Program::kUniformMatrix4f
;
241 cmds::UniformMatrix4fvImmediate
& cmd
=
242 *GetImmediateAs
<cmds::UniformMatrix4fvImmediate
>();
243 GLfloat data
[2][4 * 4] = {{0.0f
}};
244 cmd
.Init(1, 2, &data
[0][0]);
245 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
246 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
252 INSTANTIATE_TEST_CASE_P(Service
, GLES2DecoderTest2
, ::testing::Bool());
255 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GenQueriesEXTImmediate
, 0>(
258 // Make the client_query_id_ so that trying to make it again
260 cmds::GenQueriesEXTImmediate
& cmd
=
261 *GetImmediateAs
<cmds::GenQueriesEXTImmediate
>();
262 cmd
.Init(1, &client_query_id_
);
263 EXPECT_EQ(error::kNoError
,
264 ExecuteImmediateCmd(cmd
, sizeof(client_query_id_
)));
269 void GLES2DecoderTestBase::SpecializedSetup
<cmds::DeleteQueriesEXTImmediate
, 0>(
272 // Make the client_query_id_ so that trying to delete it will succeed.
273 cmds::GenQueriesEXTImmediate
& cmd
=
274 *GetImmediateAs
<cmds::GenQueriesEXTImmediate
>();
275 cmd
.Init(1, &client_query_id_
);
276 EXPECT_EQ(error::kNoError
,
277 ExecuteImmediateCmd(cmd
, sizeof(client_query_id_
)));
282 void GLES2DecoderTestBase::SpecializedSetup
<cmds::LinkProgram
, 0>(
284 const GLuint kClientVertexShaderId
= 5001;
285 const GLuint kServiceVertexShaderId
= 6001;
286 const GLuint kClientFragmentShaderId
= 5002;
287 const GLuint kServiceFragmentShaderId
= 6002;
289 GL_VERTEX_SHADER
, kClientVertexShaderId
, kServiceVertexShaderId
);
291 GL_FRAGMENT_SHADER
, kClientFragmentShaderId
, kServiceFragmentShaderId
);
293 TestHelper::SetShaderStates(
294 gl_
.get(), GetShader(kClientVertexShaderId
), true);
295 TestHelper::SetShaderStates(
296 gl_
.get(), GetShader(kClientFragmentShaderId
), true);
300 AttachShader(kServiceProgramId
, kServiceVertexShaderId
))
302 .RetiresOnSaturation();
304 AttachShader(kServiceProgramId
, kServiceFragmentShaderId
))
306 .RetiresOnSaturation();
307 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_LINK_STATUS
, _
))
308 .WillOnce(SetArgumentPointee
<2>(1));
310 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
311 .WillOnce(SetArgumentPointee
<2>(0))
312 .RetiresOnSaturation();
313 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTES
, _
))
314 .WillOnce(SetArgumentPointee
<2>(0));
317 GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, _
))
318 .WillOnce(SetArgumentPointee
<2>(0));
319 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORMS
, _
))
320 .WillOnce(SetArgumentPointee
<2>(0));
323 GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORM_MAX_LENGTH
, _
))
324 .WillOnce(SetArgumentPointee
<2>(0));
326 cmds::AttachShader attach_cmd
;
327 attach_cmd
.Init(client_program_id_
, kClientVertexShaderId
);
328 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
330 attach_cmd
.Init(client_program_id_
, kClientFragmentShaderId
);
331 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
335 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UseProgram
, 0>(
337 // Needs the same setup as LinkProgram.
338 SpecializedSetup
<cmds::LinkProgram
, 0>(false);
340 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
342 .RetiresOnSaturation();
344 cmds::LinkProgram link_cmd
;
345 link_cmd
.Init(client_program_id_
);
346 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
350 void GLES2DecoderTestBase::SpecializedSetup
<cmds::ValidateProgram
, 0>(
352 // Needs the same setup as LinkProgram.
353 SpecializedSetup
<cmds::LinkProgram
, 0>(false);
355 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
357 .RetiresOnSaturation();
359 cmds::LinkProgram link_cmd
;
360 link_cmd
.Init(client_program_id_
);
361 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
364 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
365 .WillOnce(SetArgumentPointee
<2>(0))
366 .RetiresOnSaturation();
370 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform1f
, 0>(
372 SetupShaderForUniform(GL_FLOAT
);
376 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform1fvImmediate
, 0>(
378 SetupShaderForUniform(GL_FLOAT
);
382 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform1ivImmediate
, 0>(
384 SetupShaderForUniform(GL_INT
);
388 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2f
, 0>(
390 SetupShaderForUniform(GL_FLOAT_VEC2
);
394 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2i
, 0>(
396 SetupShaderForUniform(GL_INT_VEC2
);
400 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2fvImmediate
, 0>(
402 SetupShaderForUniform(GL_FLOAT_VEC2
);
406 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2ivImmediate
, 0>(
408 SetupShaderForUniform(GL_INT_VEC2
);
412 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3f
, 0>(
414 SetupShaderForUniform(GL_FLOAT_VEC3
);
418 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3i
, 0>(
420 SetupShaderForUniform(GL_INT_VEC3
);
424 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3fvImmediate
, 0>(
426 SetupShaderForUniform(GL_FLOAT_VEC3
);
430 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3ivImmediate
, 0>(
432 SetupShaderForUniform(GL_INT_VEC3
);
436 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4f
, 0>(
438 SetupShaderForUniform(GL_FLOAT_VEC4
);
442 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4i
, 0>(
444 SetupShaderForUniform(GL_INT_VEC4
);
448 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4fvImmediate
, 0>(
450 SetupShaderForUniform(GL_FLOAT_VEC4
);
454 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4ivImmediate
, 0>(
456 SetupShaderForUniform(GL_INT_VEC4
);
460 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UniformMatrix2fvImmediate
, 0>(
462 SetupShaderForUniform(GL_FLOAT_MAT2
);
466 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UniformMatrix3fvImmediate
, 0>(
468 SetupShaderForUniform(GL_FLOAT_MAT3
);
472 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UniformMatrix4fvImmediate
, 0>(
474 SetupShaderForUniform(GL_FLOAT_MAT4
);
478 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameterf
, 0>(
480 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
484 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameteri
, 0>(
486 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
490 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameterfvImmediate
, 0>(
492 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
496 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameterivImmediate
, 0>(
498 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
501 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h"
503 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT
) {
504 TestAcceptedUniform(GL_INT
, Program::kUniform1i
);
507 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT_VEC2
) {
508 TestAcceptedUniform(GL_INT_VEC2
, Program::kUniform2i
);
511 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT_VEC3
) {
512 TestAcceptedUniform(GL_INT_VEC3
, Program::kUniform3i
);
515 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT_VEC4
) {
516 TestAcceptedUniform(GL_INT_VEC4
, Program::kUniform4i
);
519 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL
) {
520 TestAcceptedUniform(GL_BOOL
, Program::kUniform1i
| Program::kUniform1f
);
523 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL_VEC2
) {
524 TestAcceptedUniform(GL_BOOL_VEC2
, Program::kUniform2i
| Program::kUniform2f
);
527 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL_VEC3
) {
528 TestAcceptedUniform(GL_BOOL_VEC3
, Program::kUniform3i
| Program::kUniform3f
);
531 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL_VEC4
) {
532 TestAcceptedUniform(GL_BOOL_VEC4
, Program::kUniform4i
| Program::kUniform4f
);
535 TEST_P(GLES2DecoderTest2
, AcceptsUniformTypeFLOAT
) {
536 TestAcceptedUniform(GL_FLOAT
, Program::kUniform1f
);
539 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_VEC2
) {
540 TestAcceptedUniform(GL_FLOAT_VEC2
, Program::kUniform2f
);
543 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_VEC3
) {
544 TestAcceptedUniform(GL_FLOAT_VEC3
, Program::kUniform3f
);
547 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_VEC4
) {
548 TestAcceptedUniform(GL_FLOAT_VEC4
, Program::kUniform4f
);
551 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_MAT2
) {
552 TestAcceptedUniform(GL_FLOAT_MAT2
, Program::kUniformMatrix2f
);
555 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_MAT3
) {
556 TestAcceptedUniform(GL_FLOAT_MAT3
, Program::kUniformMatrix3f
);
559 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_MAT4
) {
560 TestAcceptedUniform(GL_FLOAT_MAT4
, Program::kUniformMatrix4f
);