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() { }
41 void GLES2DecoderTestBase::SpecializedSetup<cmds::GenerateMipmap, 0>(
43 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
45 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
46 kSharedMemoryId, kSharedMemoryOffset);
48 EXPECT_CALL(*gl_, TexParameteri(
49 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
51 .RetiresOnSaturation();
52 EXPECT_CALL(*gl_, TexParameteri(
53 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
55 .RetiresOnSaturation();
56 EXPECT_CALL(*gl_, GetError())
57 .WillOnce(Return(GL_NO_ERROR))
58 .WillOnce(Return(GL_NO_ERROR))
59 .RetiresOnSaturation();
64 void GLES2DecoderTestBase::SpecializedSetup<cmds::CheckFramebufferStatus, 0>(
66 // Give it a valid framebuffer.
67 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
68 kServiceRenderbufferId);
69 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
70 kServiceFramebufferId);
71 DoRenderbufferStorage(
72 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
73 DoFramebufferRenderbuffer(
74 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
75 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
79 void GLES2DecoderTestBase::SpecializedSetup<cmds::Clear, 0>(bool valid) {
81 SetupExpectationsForApplyingDefaultDirtyState();
86 void GLES2DecoderTestBase::SpecializedSetup<cmds::ColorMask, 0>(
88 // We bind a framebuffer color the colormask test since the framebuffer
89 // will be considered RGB.
90 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
91 kServiceFramebufferId);
95 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexImage2D, 0>(
98 EXPECT_CALL(*gl_, GetError())
99 .WillOnce(Return(GL_NO_ERROR))
100 .WillOnce(Return(GL_NO_ERROR))
101 .RetiresOnSaturation();
106 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexSubImage2D, 0>(
109 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
111 GL_TEXTURE_2D, 2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
112 kSharedMemoryId, kSharedMemoryOffset);
117 void GLES2DecoderTestBase::SpecializedSetup<cmds::DetachShader, 0>(bool valid) {
120 AttachShader(kServiceProgramId, kServiceShaderId))
122 .RetiresOnSaturation();
123 cmds::AttachShader attach_cmd;
124 attach_cmd.Init(client_program_id_, client_shader_id_);
125 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
130 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferRenderbuffer, 0>(
132 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
133 kServiceFramebufferId);
135 EXPECT_CALL(*gl_, GetError())
136 .WillOnce(Return(GL_NO_ERROR))
137 .WillOnce(Return(GL_NO_ERROR))
138 .RetiresOnSaturation();
143 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferTexture2D, 0>(
145 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
146 kServiceFramebufferId);
148 EXPECT_CALL(*gl_, GetError())
149 .WillOnce(Return(GL_NO_ERROR))
150 .WillOnce(Return(GL_NO_ERROR))
151 .RetiresOnSaturation();
156 void GLES2DecoderTestBase::SpecializedSetup<
157 cmds::GetBufferParameteriv, 0>(bool /* valid */) {
158 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
162 void GLES2DecoderTestBase::SpecializedSetup<
163 cmds::GetFramebufferAttachmentParameteriv, 0>(bool /* valid */) {
164 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
165 kServiceFramebufferId);
169 void GLES2DecoderTestBase::SpecializedSetup<
170 cmds::GetRenderbufferParameteriv, 0>(
172 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
173 kServiceRenderbufferId);
177 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramiv, 0>(
180 // GetProgramiv calls ClearGLError then GetError to make sure
181 // it actually got a value so it can report correctly to the client.
182 EXPECT_CALL(*gl_, GetError())
183 .WillOnce(Return(GL_NO_ERROR))
184 .RetiresOnSaturation();
185 EXPECT_CALL(*gl_, GetError())
186 .WillOnce(Return(GL_NO_ERROR))
187 .RetiresOnSaturation();
192 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramInfoLog, 0>(
194 const GLuint kClientVertexShaderId = 5001;
195 const GLuint kServiceVertexShaderId = 6001;
196 const GLuint kClientFragmentShaderId = 5002;
197 const GLuint kServiceFragmentShaderId = 6002;
198 const char* log = "hello"; // Matches auto-generated unit test.
200 GL_VERTEX_SHADER, kClientVertexShaderId, kServiceVertexShaderId);
202 GL_FRAGMENT_SHADER, kClientFragmentShaderId, kServiceFragmentShaderId);
204 GetShader(kClientVertexShaderId)->SetStatus(true, "", NULL);
205 GetShader(kClientFragmentShaderId)->SetStatus(true, "", NULL);
209 AttachShader(kServiceProgramId, kServiceVertexShaderId))
211 .RetiresOnSaturation();
213 AttachShader(kServiceProgramId, kServiceFragmentShaderId))
215 .RetiresOnSaturation();
216 EXPECT_CALL(*gl_, LinkProgram(kServiceProgramId))
218 .RetiresOnSaturation();
219 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
220 .WillOnce(SetArgumentPointee<2>(1));
222 GetProgramiv(kServiceProgramId, GL_INFO_LOG_LENGTH, _))
223 .WillOnce(SetArgumentPointee<2>(strlen(log) + 1))
224 .RetiresOnSaturation();
226 GetProgramInfoLog(kServiceProgramId, strlen(log) + 1, _, _))
228 SetArgumentPointee<2>(strlen(log)),
229 SetArrayArgument<3>(log, log + strlen(log) + 1)))
230 .RetiresOnSaturation();
231 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _))
232 .WillOnce(SetArgumentPointee<2>(0));
235 GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
236 .WillOnce(SetArgumentPointee<2>(0));
237 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _))
238 .WillOnce(SetArgumentPointee<2>(0));
241 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
242 .WillOnce(SetArgumentPointee<2>(0));
244 Program* program = GetProgram(client_program_id_);
245 ASSERT_TRUE(program != NULL);
247 cmds::AttachShader attach_cmd;
248 attach_cmd.Init(client_program_id_, kClientVertexShaderId);
249 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
251 attach_cmd.Init(client_program_id_, kClientFragmentShaderId);
252 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
254 program->Link(NULL, NULL, NULL, Program::kCountOnlyStaticallyUsed,
255 base::Bind(&ShaderCacheCb));
259 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribfv, 0>(
261 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
262 DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
264 EXPECT_CALL(*gl_, GetError())
265 .WillOnce(Return(GL_NO_ERROR))
266 .WillOnce(Return(GL_NO_ERROR))
267 .RetiresOnSaturation();
272 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribiv, 0>(
274 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
275 DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
277 EXPECT_CALL(*gl_, GetError())
278 .WillOnce(Return(GL_NO_ERROR))
279 .WillOnce(Return(GL_NO_ERROR))
280 .RetiresOnSaturation();
284 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"