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
<cmds::GetProgramiv
, 0>(
167 // GetProgramiv calls ClearGLError then GetError to make sure
168 // it actually got a value so it can report correctly to the client.
169 EXPECT_CALL(*gl_
, GetError())
170 .WillOnce(Return(GL_NO_ERROR
))
171 .RetiresOnSaturation();
172 EXPECT_CALL(*gl_
, GetError())
173 .WillOnce(Return(GL_NO_ERROR
))
174 .RetiresOnSaturation();
179 void GLES2DecoderTestBase::SpecializedSetup
<cmds::GetProgramInfoLog
, 0>(
181 const GLuint kClientVertexShaderId
= 5001;
182 const GLuint kServiceVertexShaderId
= 6001;
183 const GLuint kClientFragmentShaderId
= 5002;
184 const GLuint kServiceFragmentShaderId
= 6002;
185 const char* log
= "hello"; // Matches auto-generated unit test.
187 GL_VERTEX_SHADER
, kClientVertexShaderId
, kServiceVertexShaderId
);
189 GL_FRAGMENT_SHADER
, kClientFragmentShaderId
, kServiceFragmentShaderId
);
191 TestHelper::SetShaderStates(
192 gl_
.get(), GetShader(kClientVertexShaderId
), true);
193 TestHelper::SetShaderStates(
194 gl_
.get(), GetShader(kClientFragmentShaderId
), true);
198 AttachShader(kServiceProgramId
, kServiceVertexShaderId
))
200 .RetiresOnSaturation();
202 AttachShader(kServiceProgramId
, kServiceFragmentShaderId
))
204 .RetiresOnSaturation();
205 EXPECT_CALL(*gl_
, LinkProgram(kServiceProgramId
))
207 .RetiresOnSaturation();
208 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_LINK_STATUS
, _
))
209 .WillOnce(SetArgumentPointee
<2>(1));
211 GetProgramiv(kServiceProgramId
, GL_INFO_LOG_LENGTH
, _
))
212 .WillOnce(SetArgumentPointee
<2>(strlen(log
) + 1))
213 .RetiresOnSaturation();
215 GetProgramInfoLog(kServiceProgramId
, strlen(log
) + 1, _
, _
))
217 SetArgumentPointee
<2>(strlen(log
)),
218 SetArrayArgument
<3>(log
, log
+ strlen(log
) + 1)))
219 .RetiresOnSaturation();
220 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTES
, _
))
221 .WillOnce(SetArgumentPointee
<2>(0));
224 GetProgramiv(kServiceProgramId
, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, _
))
225 .WillOnce(SetArgumentPointee
<2>(0));
226 EXPECT_CALL(*gl_
, GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORMS
, _
))
227 .WillOnce(SetArgumentPointee
<2>(0));
230 GetProgramiv(kServiceProgramId
, GL_ACTIVE_UNIFORM_MAX_LENGTH
, _
))
231 .WillOnce(SetArgumentPointee
<2>(0));
233 Program
* program
= GetProgram(client_program_id_
);
234 ASSERT_TRUE(program
!= NULL
);
236 cmds::AttachShader attach_cmd
;
237 attach_cmd
.Init(client_program_id_
, kClientVertexShaderId
);
238 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
240 attach_cmd
.Init(client_program_id_
, kClientFragmentShaderId
);
241 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
243 program
->Link(NULL
, Program::kCountOnlyStaticallyUsed
,
244 base::Bind(&ShaderCacheCb
));
247 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"