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::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
;
32 void ShaderCacheCb(const std::string
& key
, const std::string
& shader
) {
36 class GLES2DecoderTest1
: public GLES2DecoderTestBase
{
38 GLES2DecoderTest1() { }
41 INSTANTIATE_TEST_CASE_P(Service
, GLES2DecoderTest1
, ::testing::Bool());
44 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GenerateMipmap
, 0>(
46 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
48 GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 16, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
49 kSharedMemoryId
, kSharedMemoryOffset
);
51 EXPECT_CALL(*gl_
, GetError())
52 .WillOnce(Return(GL_NO_ERROR
))
53 .WillOnce(Return(GL_NO_ERROR
))
54 .RetiresOnSaturation();
59 void GLES2DecoderTestBase::SpecializedSetup
<cmds::CheckFramebufferStatus
, 0>(
61 // Give it a valid framebuffer.
62 DoBindRenderbuffer(GL_RENDERBUFFER
, client_renderbuffer_id_
,
63 kServiceRenderbufferId
);
64 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
65 kServiceFramebufferId
);
66 DoRenderbufferStorage(
67 GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 1, 1, GL_NO_ERROR
);
68 DoFramebufferRenderbuffer(
69 GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
,
70 client_renderbuffer_id_
, kServiceRenderbufferId
, GL_NO_ERROR
);
74 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Clear
, 0>(bool valid
) {
76 SetupExpectationsForApplyingDefaultDirtyState();
81 void GLES2DecoderTestBase::SpecializedSetup
<cmds::ColorMask
, 0>(
83 // We bind a framebuffer color the colormask test since the framebuffer
84 // will be considered RGB.
85 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
86 kServiceFramebufferId
);
90 void GLES2DecoderTestBase::SpecializedSetup
<cmds::CopyTexImage2D
, 0>(
93 EXPECT_CALL(*gl_
, GetError())
94 .WillOnce(Return(GL_NO_ERROR
))
95 .WillOnce(Return(GL_NO_ERROR
))
96 .RetiresOnSaturation();
101 void GLES2DecoderTestBase::SpecializedSetup
<cmds::CopyTexSubImage2D
, 0>(
104 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
106 GL_TEXTURE_2D
, 2, GL_RGBA
, 16, 16, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
107 kSharedMemoryId
, kSharedMemoryOffset
);
112 void GLES2DecoderTestBase::SpecializedSetup
<cmds::DetachShader
, 0>(bool valid
) {
115 AttachShader(kServiceProgramId
, kServiceShaderId
))
117 .RetiresOnSaturation();
118 cmds::AttachShader attach_cmd
;
119 attach_cmd
.Init(client_program_id_
, client_shader_id_
);
120 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
125 void GLES2DecoderTestBase::SpecializedSetup
<cmds::FramebufferRenderbuffer
, 0>(
127 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
128 kServiceFramebufferId
);
130 EXPECT_CALL(*gl_
, GetError())
131 .WillOnce(Return(GL_NO_ERROR
))
132 .WillOnce(Return(GL_NO_ERROR
))
133 .RetiresOnSaturation();
138 void GLES2DecoderTestBase::SpecializedSetup
<cmds::FramebufferTexture2D
, 0>(
140 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
141 kServiceFramebufferId
);
143 EXPECT_CALL(*gl_
, GetError())
144 .WillOnce(Return(GL_NO_ERROR
))
145 .WillOnce(Return(GL_NO_ERROR
))
146 .RetiresOnSaturation();
151 void GLES2DecoderTestBase::SpecializedSetup
<
152 cmds::GetBufferParameteriv
, 0>(bool /* valid */) {
153 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
157 void GLES2DecoderTestBase::SpecializedSetup
<
158 cmds::GetFramebufferAttachmentParameteriv
, 0>(bool /* valid */) {
159 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
160 kServiceFramebufferId
);
164 void GLES2DecoderTestBase::SpecializedSetup
<
165 cmds::GetRenderbufferParameteriv
, 0>(
167 DoBindRenderbuffer(GL_RENDERBUFFER
, client_renderbuffer_id_
,
168 kServiceRenderbufferId
);
172 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetProgramiv
, 0>(
175 // GetProgramiv calls ClearGLError then GetError to make sure
176 // it actually got a value so it can report correctly to the client.
177 EXPECT_CALL(*gl_
, GetError())
178 .WillOnce(Return(GL_NO_ERROR
))
179 .RetiresOnSaturation();
180 EXPECT_CALL(*gl_
, GetError())
181 .WillOnce(Return(GL_NO_ERROR
))
182 .RetiresOnSaturation();
187 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetProgramInfoLog
, 0>(
189 const GLuint kClientVertexShaderId
= 5001;
190 const GLuint kServiceVertexShaderId
= 6001;
191 const GLuint kClientFragmentShaderId
= 5002;
192 const GLuint kServiceFragmentShaderId
= 6002;
193 const char* log
= "hello"; // Matches auto-generated unit test.
195 GL_VERTEX_SHADER
, kClientVertexShaderId
, kServiceVertexShaderId
);
197 GL_FRAGMENT_SHADER
, kClientFragmentShaderId
, kServiceFragmentShaderId
);
199 TestHelper::SetShaderStates(
200 gl_
.get(), GetShader(kClientVertexShaderId
), true);
201 TestHelper::SetShaderStates(
202 gl_
.get(), GetShader(kClientFragmentShaderId
), true);
206 AttachShader(kServiceProgramId
, kServiceVertexShaderId
))
208 .RetiresOnSaturation();
210 AttachShader(kServiceProgramId
, kServiceFragmentShaderId
))
212 .RetiresOnSaturation();
213 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
215 .RetiresOnSaturation();
216 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_LINK_STATUS
, _
))
217 .WillOnce(SetArgumentPointee
<2>(1));
219 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
220 .WillOnce(SetArgumentPointee
<2>(strlen(log
) + 1))
221 .RetiresOnSaturation();
223 GetProgramInfoLog(kServiceProgramId
, strlen(log
) + 1, _
, _
))
225 SetArgumentPointee
<2>(strlen(log
)),
226 SetArrayArgument
<3>(log
, log
+ strlen(log
) + 1)))
227 .RetiresOnSaturation();
228 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTES
, _
))
229 .WillOnce(SetArgumentPointee
<2>(0));
232 GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, _
))
233 .WillOnce(SetArgumentPointee
<2>(0));
234 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORMS
, _
))
235 .WillOnce(SetArgumentPointee
<2>(0));
238 GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORM_MAX_LENGTH
, _
))
239 .WillOnce(SetArgumentPointee
<2>(0));
241 Program
* program
= GetProgram(client_program_id_
);
242 ASSERT_TRUE(program
!= NULL
);
244 cmds::AttachShader attach_cmd
;
245 attach_cmd
.Init(client_program_id_
, kClientVertexShaderId
);
246 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
248 attach_cmd
.Init(client_program_id_
, kClientFragmentShaderId
);
249 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
251 program
->Link(NULL
, Program::kCountOnlyStaticallyUsed
,
252 base::Bind(&ShaderCacheCb
));
255 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"