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::DoAll
;
19 using ::testing::InSequence
;
20 using ::testing::MatcherCast
;
21 using ::testing::Pointee
;
22 using ::testing::Return
;
23 using ::testing::SetArrayArgument
;
24 using ::testing::SetArgumentPointee
;
25 using ::testing::StrEq
;
31 void ShaderCacheCb(const std::string
& key
, const std::string
& shader
) {
35 class GLES2DecoderTest1
: public GLES2DecoderTestBase
{
37 GLES2DecoderTest1() { }
40 INSTANTIATE_TEST_CASE_P(Service
, GLES2DecoderTest1
, ::testing::Bool());
43 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GenerateMipmap
, 0>(
45 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
47 GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 16, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
48 kSharedMemoryId
, kSharedMemoryOffset
);
50 EXPECT_CALL(*gl_
, GetError())
51 .WillOnce(Return(GL_NO_ERROR
))
52 .WillOnce(Return(GL_NO_ERROR
))
53 .RetiresOnSaturation();
58 void GLES2DecoderTestBase::SpecializedSetup
<cmds::CheckFramebufferStatus
, 0>(
60 // Give it a valid framebuffer.
61 DoBindRenderbuffer(GL_RENDERBUFFER
, client_renderbuffer_id_
,
62 kServiceRenderbufferId
);
63 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
64 kServiceFramebufferId
);
65 DoRenderbufferStorage(
66 GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 1, 1, GL_NO_ERROR
);
67 DoFramebufferRenderbuffer(
68 GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
,
69 client_renderbuffer_id_
, kServiceRenderbufferId
, GL_NO_ERROR
);
73 void GLES2DecoderTestBase::SpecializedSetup
<cmds::Clear
, 0>(bool valid
) {
75 SetupExpectationsForApplyingDefaultDirtyState();
80 void GLES2DecoderTestBase::SpecializedSetup
<cmds::ColorMask
, 0>(
82 // We bind a framebuffer color the colormask test since the framebuffer
83 // will be considered RGB.
84 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
85 kServiceFramebufferId
);
89 void GLES2DecoderTestBase::SpecializedSetup
<cmds::CopyTexImage2D
, 0>(
92 EXPECT_CALL(*gl_
, GetError())
93 .WillOnce(Return(GL_NO_ERROR
))
94 .WillOnce(Return(GL_NO_ERROR
))
95 .RetiresOnSaturation();
100 void GLES2DecoderTestBase::SpecializedSetup
<cmds::CopyTexSubImage2D
, 0>(
103 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
105 GL_TEXTURE_2D
, 2, GL_RGBA
, 16, 16, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
106 kSharedMemoryId
, kSharedMemoryOffset
);
111 void GLES2DecoderTestBase::SpecializedSetup
<cmds::DetachShader
, 0>(bool valid
) {
114 AttachShader(kServiceProgramId
, kServiceShaderId
))
116 .RetiresOnSaturation();
117 cmds::AttachShader attach_cmd
;
118 attach_cmd
.Init(client_program_id_
, client_shader_id_
);
119 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
124 void GLES2DecoderTestBase::SpecializedSetup
<cmds::FramebufferRenderbuffer
, 0>(
126 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
127 kServiceFramebufferId
);
129 EXPECT_CALL(*gl_
, GetError())
130 .WillOnce(Return(GL_NO_ERROR
))
131 .WillOnce(Return(GL_NO_ERROR
))
132 .RetiresOnSaturation();
137 void GLES2DecoderTestBase::SpecializedSetup
<cmds::FramebufferTexture2D
, 0>(
139 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
140 kServiceFramebufferId
);
142 EXPECT_CALL(*gl_
, GetError())
143 .WillOnce(Return(GL_NO_ERROR
))
144 .WillOnce(Return(GL_NO_ERROR
))
145 .RetiresOnSaturation();
150 void GLES2DecoderTestBase::SpecializedSetup
<
151 cmds::GetBufferParameteriv
, 0>(bool /* valid */) {
152 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
156 void GLES2DecoderTestBase::SpecializedSetup
<
157 cmds::GetFramebufferAttachmentParameteriv
, 0>(bool /* valid */) {
158 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
159 kServiceFramebufferId
);
163 void GLES2DecoderTestBase::SpecializedSetup
<
164 cmds::GetRenderbufferParameteriv
, 0>(
166 DoBindRenderbuffer(GL_RENDERBUFFER
, client_renderbuffer_id_
,
167 kServiceRenderbufferId
);
171 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetProgramiv
, 0>(
174 // GetProgramiv calls ClearGLError then GetError to make sure
175 // it actually got a value so it can report correctly to the client.
176 EXPECT_CALL(*gl_
, GetError())
177 .WillOnce(Return(GL_NO_ERROR
))
178 .RetiresOnSaturation();
179 EXPECT_CALL(*gl_
, GetError())
180 .WillOnce(Return(GL_NO_ERROR
))
181 .RetiresOnSaturation();
186 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetProgramInfoLog
, 0>(
188 const GLuint kClientVertexShaderId
= 5001;
189 const GLuint kServiceVertexShaderId
= 6001;
190 const GLuint kClientFragmentShaderId
= 5002;
191 const GLuint kServiceFragmentShaderId
= 6002;
192 const char* log
= "hello"; // Matches auto-generated unit test.
194 GL_VERTEX_SHADER
, kClientVertexShaderId
, kServiceVertexShaderId
);
196 GL_FRAGMENT_SHADER
, kClientFragmentShaderId
, kServiceFragmentShaderId
);
198 GetShader(kClientVertexShaderId
)->SetStatus(true, "", NULL
);
199 GetShader(kClientFragmentShaderId
)->SetStatus(true, "", NULL
);
203 AttachShader(kServiceProgramId
, kServiceVertexShaderId
))
205 .RetiresOnSaturation();
207 AttachShader(kServiceProgramId
, kServiceFragmentShaderId
))
209 .RetiresOnSaturation();
210 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
212 .RetiresOnSaturation();
213 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_LINK_STATUS
, _
))
214 .WillOnce(SetArgumentPointee
<2>(1));
216 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
217 .WillOnce(SetArgumentPointee
<2>(strlen(log
) + 1))
218 .RetiresOnSaturation();
220 GetProgramInfoLog(kServiceProgramId
, strlen(log
) + 1, _
, _
))
222 SetArgumentPointee
<2>(strlen(log
)),
223 SetArrayArgument
<3>(log
, log
+ strlen(log
) + 1)))
224 .RetiresOnSaturation();
225 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTES
, _
))
226 .WillOnce(SetArgumentPointee
<2>(0));
229 GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, _
))
230 .WillOnce(SetArgumentPointee
<2>(0));
231 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORMS
, _
))
232 .WillOnce(SetArgumentPointee
<2>(0));
235 GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORM_MAX_LENGTH
, _
))
236 .WillOnce(SetArgumentPointee
<2>(0));
238 Program
* program
= GetProgram(client_program_id_
);
239 ASSERT_TRUE(program
!= NULL
);
241 cmds::AttachShader attach_cmd
;
242 attach_cmd
.Init(client_program_id_
, kClientVertexShaderId
);
243 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
245 attach_cmd
.Init(client_program_id_
, kClientFragmentShaderId
);
246 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
248 program
->Link(NULL
, NULL
, NULL
, Program::kCountOnlyStaticallyUsed
,
249 base::Bind(&ShaderCacheCb
));
253 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetVertexAttribfv
, 0>(
255 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
256 DoVertexAttribPointer(1, 1, GL_FLOAT
, 0, 0);
258 EXPECT_CALL(*gl_
, GetError())
259 .WillOnce(Return(GL_NO_ERROR
))
260 .WillOnce(Return(GL_NO_ERROR
))
261 .RetiresOnSaturation();
266 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetVertexAttribiv
, 0>(
268 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
269 DoVertexAttribPointer(1, 1, GL_FLOAT
, 0, 0);
271 EXPECT_CALL(*gl_
, GetError())
272 .WillOnce(Return(GL_NO_ERROR
))
273 .WillOnce(Return(GL_NO_ERROR
))
274 .RetiresOnSaturation();
279 void GLES2DecoderTestBase::SpecializedSetup
<cmds::RenderbufferStorage
, 0>(
281 DoBindRenderbuffer(GL_RENDERBUFFER
, client_renderbuffer_id_
,
282 kServiceRenderbufferId
);
284 EnsureRenderbufferBound(false);
285 EXPECT_CALL(*gl_
, GetError())
286 .WillOnce(Return(GL_NO_ERROR
))
287 .RetiresOnSaturation();
289 RenderbufferStorageEXT(GL_RENDERBUFFER
, _
, 3, 4))
291 .RetiresOnSaturation();
292 EXPECT_CALL(*gl_
, GetError())
293 .WillOnce(Return(GL_NO_ERROR
))
294 .RetiresOnSaturation();
299 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"