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 "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gl/gl_mock.h"
16 using ::gfx::MockGLInterface
;
18 using ::testing::AnyNumber
;
19 using ::testing::DoAll
;
20 using ::testing::InSequence
;
21 using ::testing::MatcherCast
;
22 using ::testing::Pointee
;
23 using ::testing::Return
;
24 using ::testing::SetArrayArgument
;
25 using ::testing::SetArgumentPointee
;
26 using ::testing::StrEq
;
31 class GLES2DecoderTest2
: public GLES2DecoderTestBase
{
33 GLES2DecoderTest2() { }
35 void TestAcceptedUniform(GLenum uniform_type
, uint32 accepts_apis
) {
36 SetupShaderForUniform(uniform_type
);
37 bool valid_uniform
= false;
39 EXPECT_CALL(*gl_
, Uniform1i(1, _
)).Times(AnyNumber());
40 EXPECT_CALL(*gl_
, Uniform1iv(1, _
, _
)).Times(AnyNumber());
41 EXPECT_CALL(*gl_
, Uniform2iv(1, _
, _
)).Times(AnyNumber());
42 EXPECT_CALL(*gl_
, Uniform3iv(1, _
, _
)).Times(AnyNumber());
43 EXPECT_CALL(*gl_
, Uniform4iv(1, _
, _
)).Times(AnyNumber());
44 EXPECT_CALL(*gl_
, Uniform1f(1, _
)).Times(AnyNumber());
45 EXPECT_CALL(*gl_
, Uniform1fv(1, _
, _
)).Times(AnyNumber());
46 EXPECT_CALL(*gl_
, Uniform2fv(1, _
, _
)).Times(AnyNumber());
47 EXPECT_CALL(*gl_
, Uniform3fv(1, _
, _
)).Times(AnyNumber());
48 EXPECT_CALL(*gl_
, Uniform4fv(1, _
, _
)).Times(AnyNumber());
49 EXPECT_CALL(*gl_
, UniformMatrix2fv(1, _
, _
, _
)).Times(AnyNumber());
50 EXPECT_CALL(*gl_
, UniformMatrix3fv(1, _
, _
, _
)).Times(AnyNumber());
51 EXPECT_CALL(*gl_
, UniformMatrix4fv(1, _
, _
, _
)).Times(AnyNumber());
54 valid_uniform
= accepts_apis
& Program::kUniform1i
;
57 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
58 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
63 valid_uniform
= accepts_apis
& Program::kUniform1i
;
64 cmds::Uniform1ivImmediate
& cmd
=
65 *GetImmediateAs
<cmds::Uniform1ivImmediate
>();
66 GLint data
[2][1] = {{0}};
67 cmd
.Init(1, 2, &data
[0][0]);
68 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
69 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
74 valid_uniform
= accepts_apis
& Program::kUniform2i
;
77 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
78 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
83 valid_uniform
= accepts_apis
& Program::kUniform2i
;
84 cmds::Uniform2ivImmediate
& cmd
=
85 *GetImmediateAs
<cmds::Uniform2ivImmediate
>();
86 GLint data
[2][2] = {{0}};
87 cmd
.Init(1, 2, &data
[0][0]);
88 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
89 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
94 valid_uniform
= accepts_apis
& Program::kUniform3i
;
97 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
98 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
103 valid_uniform
= accepts_apis
& Program::kUniform3i
;
104 cmds::Uniform3ivImmediate
& cmd
=
105 *GetImmediateAs
<cmds::Uniform3ivImmediate
>();
106 GLint data
[2][3] = {{0}};
107 cmd
.Init(1, 2, &data
[0][0]);
108 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
109 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
114 valid_uniform
= accepts_apis
& Program::kUniform4i
;
116 cmd
.Init(1, 2, 3, 4, 5);
117 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
118 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
123 valid_uniform
= accepts_apis
& Program::kUniform4i
;
124 cmds::Uniform4ivImmediate
& cmd
=
125 *GetImmediateAs
<cmds::Uniform4ivImmediate
>();
126 GLint data
[2][4] = {{0}};
127 cmd
.Init(1, 2, &data
[0][0]);
128 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
129 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
136 valid_uniform
= accepts_apis
& Program::kUniform1f
;
139 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
140 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
145 valid_uniform
= accepts_apis
& Program::kUniform1f
;
146 cmds::Uniform1fvImmediate
& cmd
=
147 *GetImmediateAs
<cmds::Uniform1fvImmediate
>();
148 GLfloat data
[2][1] = {{0.0f
}};
149 cmd
.Init(1, 2, &data
[0][0]);
150 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
151 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
156 valid_uniform
= accepts_apis
& Program::kUniform2f
;
159 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
160 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
165 valid_uniform
= accepts_apis
& Program::kUniform2f
;
166 cmds::Uniform2fvImmediate
& cmd
=
167 *GetImmediateAs
<cmds::Uniform2fvImmediate
>();
168 GLfloat data
[2][2] = {{0.0f
}};
169 cmd
.Init(1, 2, &data
[0][0]);
170 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
171 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
176 valid_uniform
= accepts_apis
& Program::kUniform3f
;
178 cmd
.Init(1, 2, 3, 4);
179 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
180 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
185 valid_uniform
= accepts_apis
& Program::kUniform3f
;
186 cmds::Uniform3fvImmediate
& cmd
=
187 *GetImmediateAs
<cmds::Uniform3fvImmediate
>();
188 GLfloat data
[2][3] = {{0.0f
}};
189 cmd
.Init(1, 2, &data
[0][0]);
190 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
191 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
196 valid_uniform
= accepts_apis
& Program::kUniform4f
;
198 cmd
.Init(1, 2, 3, 4, 5);
199 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
200 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
205 valid_uniform
= accepts_apis
& Program::kUniform4f
;
206 cmds::Uniform4fvImmediate
& cmd
=
207 *GetImmediateAs
<cmds::Uniform4fvImmediate
>();
208 GLfloat data
[2][4] = {{0.0f
}};
209 cmd
.Init(1, 2, &data
[0][0]);
210 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
211 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
216 valid_uniform
= accepts_apis
& Program::kUniformMatrix2f
;
217 cmds::UniformMatrix2fvImmediate
& cmd
=
218 *GetImmediateAs
<cmds::UniformMatrix2fvImmediate
>();
219 GLfloat data
[2][2 * 2] = {{0.0f
}};
221 cmd
.Init(1, 2, &data
[0][0]);
222 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
223 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
228 valid_uniform
= accepts_apis
& Program::kUniformMatrix3f
;
229 cmds::UniformMatrix3fvImmediate
& cmd
=
230 *GetImmediateAs
<cmds::UniformMatrix3fvImmediate
>();
231 GLfloat data
[2][3 * 3] = {{0.0f
}};
232 cmd
.Init(1, 2, &data
[0][0]);
233 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
234 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
239 valid_uniform
= accepts_apis
& Program::kUniformMatrix4f
;
240 cmds::UniformMatrix4fvImmediate
& cmd
=
241 *GetImmediateAs
<cmds::UniformMatrix4fvImmediate
>();
242 GLfloat data
[2][4 * 4] = {{0.0f
}};
243 cmd
.Init(1, 2, &data
[0][0]);
244 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(data
)));
245 EXPECT_EQ(valid_uniform
? GL_NO_ERROR
: GL_INVALID_OPERATION
,
251 INSTANTIATE_TEST_CASE_P(Service
, GLES2DecoderTest2
, ::testing::Bool());
254 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GenQueriesEXTImmediate
, 0>(
257 // Make the client_query_id_ so that trying to make it again
259 cmds::GenQueriesEXTImmediate
& cmd
=
260 *GetImmediateAs
<cmds::GenQueriesEXTImmediate
>();
261 cmd
.Init(1, &client_query_id_
);
262 EXPECT_EQ(error::kNoError
,
263 ExecuteImmediateCmd(cmd
, sizeof(client_query_id_
)));
268 void GLES2DecoderTestBase::SpecializedSetup
<cmds::DeleteQueriesEXTImmediate
, 0>(
271 // Make the client_query_id_ so that trying to delete it will succeed.
272 cmds::GenQueriesEXTImmediate
& cmd
=
273 *GetImmediateAs
<cmds::GenQueriesEXTImmediate
>();
274 cmd
.Init(1, &client_query_id_
);
275 EXPECT_EQ(error::kNoError
,
276 ExecuteImmediateCmd(cmd
, sizeof(client_query_id_
)));
281 void GLES2DecoderTestBase::SpecializedSetup
<cmds::LinkProgram
, 0>(
283 const GLuint kClientVertexShaderId
= 5001;
284 const GLuint kServiceVertexShaderId
= 6001;
285 const GLuint kClientFragmentShaderId
= 5002;
286 const GLuint kServiceFragmentShaderId
= 6002;
288 GL_VERTEX_SHADER
, kClientVertexShaderId
, kServiceVertexShaderId
);
290 GL_FRAGMENT_SHADER
, kClientFragmentShaderId
, kServiceFragmentShaderId
);
292 GetShader(kClientVertexShaderId
)->SetStatus(true, "", NULL
);
293 GetShader(kClientFragmentShaderId
)->SetStatus(true, "", NULL
);
297 AttachShader(kServiceProgramId
, kServiceVertexShaderId
))
299 .RetiresOnSaturation();
301 AttachShader(kServiceProgramId
, kServiceFragmentShaderId
))
303 .RetiresOnSaturation();
304 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_LINK_STATUS
, _
))
305 .WillOnce(SetArgumentPointee
<2>(1));
307 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
308 .WillOnce(SetArgumentPointee
<2>(0))
309 .RetiresOnSaturation();
310 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTES
, _
))
311 .WillOnce(SetArgumentPointee
<2>(0));
314 GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, _
))
315 .WillOnce(SetArgumentPointee
<2>(0));
316 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORMS
, _
))
317 .WillOnce(SetArgumentPointee
<2>(0));
320 GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORM_MAX_LENGTH
, _
))
321 .WillOnce(SetArgumentPointee
<2>(0));
323 cmds::AttachShader attach_cmd
;
324 attach_cmd
.Init(client_program_id_
, kClientVertexShaderId
);
325 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
327 attach_cmd
.Init(client_program_id_
, kClientFragmentShaderId
);
328 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
332 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UseProgram
, 0>(
334 // Needs the same setup as LinkProgram.
335 SpecializedSetup
<cmds::LinkProgram
, 0>(false);
337 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
339 .RetiresOnSaturation();
341 cmds::LinkProgram link_cmd
;
342 link_cmd
.Init(client_program_id_
);
343 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
347 void GLES2DecoderTestBase::SpecializedSetup
<cmds::ValidateProgram
, 0>(
349 // Needs the same setup as LinkProgram.
350 SpecializedSetup
<cmds::LinkProgram
, 0>(false);
352 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
354 .RetiresOnSaturation();
356 cmds::LinkProgram link_cmd
;
357 link_cmd
.Init(client_program_id_
);
358 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
361 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
362 .WillOnce(SetArgumentPointee
<2>(0))
363 .RetiresOnSaturation();
367 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform1f
, 0>(
369 SetupShaderForUniform(GL_FLOAT
);
373 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform1fvImmediate
, 0>(
375 SetupShaderForUniform(GL_FLOAT
);
379 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform1ivImmediate
, 0>(
381 SetupShaderForUniform(GL_INT
);
385 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2f
, 0>(
387 SetupShaderForUniform(GL_FLOAT_VEC2
);
391 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2i
, 0>(
393 SetupShaderForUniform(GL_INT_VEC2
);
397 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2fvImmediate
, 0>(
399 SetupShaderForUniform(GL_FLOAT_VEC2
);
403 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform2ivImmediate
, 0>(
405 SetupShaderForUniform(GL_INT_VEC2
);
409 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3f
, 0>(
411 SetupShaderForUniform(GL_FLOAT_VEC3
);
415 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3i
, 0>(
417 SetupShaderForUniform(GL_INT_VEC3
);
421 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3fvImmediate
, 0>(
423 SetupShaderForUniform(GL_FLOAT_VEC3
);
427 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform3ivImmediate
, 0>(
429 SetupShaderForUniform(GL_INT_VEC3
);
433 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4f
, 0>(
435 SetupShaderForUniform(GL_FLOAT_VEC4
);
439 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4i
, 0>(
441 SetupShaderForUniform(GL_INT_VEC4
);
445 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4fvImmediate
, 0>(
447 SetupShaderForUniform(GL_FLOAT_VEC4
);
451 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Uniform4ivImmediate
, 0>(
453 SetupShaderForUniform(GL_INT_VEC4
);
457 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UniformMatrix2fvImmediate
, 0>(
459 SetupShaderForUniform(GL_FLOAT_MAT2
);
463 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UniformMatrix3fvImmediate
, 0>(
465 SetupShaderForUniform(GL_FLOAT_MAT3
);
469 void GLES2DecoderTestBase::SpecializedSetup
<cmds::UniformMatrix4fvImmediate
, 0>(
471 SetupShaderForUniform(GL_FLOAT_MAT4
);
475 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameterf
, 0>(
477 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
481 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameteri
, 0>(
483 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
487 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameterfvImmediate
, 0>(
489 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
493 void GLES2DecoderTestBase::SpecializedSetup
<cmds::TexParameterivImmediate
, 0>(
495 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
498 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h"
500 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT
) {
501 TestAcceptedUniform(GL_INT
, Program::kUniform1i
);
504 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT_VEC2
) {
505 TestAcceptedUniform(GL_INT_VEC2
, Program::kUniform2i
);
508 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT_VEC3
) {
509 TestAcceptedUniform(GL_INT_VEC3
, Program::kUniform3i
);
512 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_INT_VEC4
) {
513 TestAcceptedUniform(GL_INT_VEC4
, Program::kUniform4i
);
516 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL
) {
517 TestAcceptedUniform(GL_BOOL
, Program::kUniform1i
| Program::kUniform1f
);
520 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL_VEC2
) {
521 TestAcceptedUniform(GL_BOOL_VEC2
, Program::kUniform2i
| Program::kUniform2f
);
524 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL_VEC3
) {
525 TestAcceptedUniform(GL_BOOL_VEC3
, Program::kUniform3i
| Program::kUniform3f
);
528 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_BOOL_VEC4
) {
529 TestAcceptedUniform(GL_BOOL_VEC4
, Program::kUniform4i
| Program::kUniform4f
);
532 TEST_P(GLES2DecoderTest2
, AcceptsUniformTypeFLOAT
) {
533 TestAcceptedUniform(GL_FLOAT
, Program::kUniform1f
);
536 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_VEC2
) {
537 TestAcceptedUniform(GL_FLOAT_VEC2
, Program::kUniform2f
);
540 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_VEC3
) {
541 TestAcceptedUniform(GL_FLOAT_VEC3
, Program::kUniform3f
);
544 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_VEC4
) {
545 TestAcceptedUniform(GL_FLOAT_VEC4
, Program::kUniform4f
);
548 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_MAT2
) {
549 TestAcceptedUniform(GL_FLOAT_MAT2
, Program::kUniformMatrix2f
);
552 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_MAT3
) {
553 TestAcceptedUniform(GL_FLOAT_MAT3
, Program::kUniformMatrix3f
);
556 TEST_P(GLES2DecoderTest2
, AcceptsUniform_GL_FLOAT_MAT4
) {
557 TestAcceptedUniform(GL_FLOAT_MAT4
, Program::kUniformMatrix4f
);