Skip to content

Commit

Permalink
gpu: Generate GLES2Implementation::UseProgram().
Browse files Browse the repository at this point in the history
glUseProgram() is kind of Bind function, although prefix is Use, not Bind. So
reuse bind type harness.

The benefits:
1. Unit tests are generated.
2. Cache a program state in the same manner of other bind states.

BUG=160370

Review URL: https://codereview.chromium.org/195973010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259396 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dongseong.hwang@intel.com committed Mar 25, 2014
1 parent ab3dea2 commit cb79eaa
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 23 deletions.
17 changes: 8 additions & 9 deletions gpu/command_buffer/build_gles2_cmd_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2170,9 +2170,8 @@
'pepper_interface': 'ChromiumMapSub',
},
'UseProgram': {
'type': 'Bind',
'decoder_func': 'DoUseProgram',
'impl_func': False,
'unit_test': False,
},
'ValidateProgram': {'decoder_func': 'DoValidateProgram'},
'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'},
Expand Down Expand Up @@ -3701,7 +3700,9 @@ def WriteServiceUnitTest(self, func, file):
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
"""
if func.GetInfo("gen_func"):
valid_test += """
TEST_F(%(test_name)s, %(name)sValidArgsNewId) {
EXPECT_CALL(*gl_, %(gl_func_name)s(kNewServiceId));
EXPECT_CALL(*gl_, %(gl_gen_func_name)s(1, _))
Expand All @@ -3714,8 +3715,6 @@ def WriteServiceUnitTest(self, func, file):
EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL);
}
"""
gen_func_names = {
}
self.WriteValidUnitTest(func, file, valid_test, {
'resource_type': func.GetOriginalArgs()[0].resource_type,
'gl_gen_func_name': func.GetInfo("gen_func"),
Expand All @@ -3730,7 +3729,9 @@ def WriteServiceUnitTest(self, func, file):
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
"""
if func.GetInfo("gen_func"):
valid_test += """
TEST_F(%(test_name)s, %(name)sValidArgsNewId) {
EXPECT_CALL(*gl_, %(gl_func_name)s(%(first_gl_arg)s, kNewServiceId));
EXPECT_CALL(*gl_, %(gl_gen_func_name)s(1, _))
Expand All @@ -3743,8 +3744,6 @@ def WriteServiceUnitTest(self, func, file):
EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL);
}
"""
gen_func_names = {
}
self.WriteValidUnitTest(func, file, valid_test, {
'first_arg': func.GetOriginalArgs()[0].GetValidArg(func, 0, 0),
'first_gl_arg': func.GetOriginalArgs()[0].GetValidGLArg(func, 0, 0),
Expand Down Expand Up @@ -3786,7 +3785,7 @@ def WriteGLES2Implementation(self, func, file):
SetGLError(GL_INVALID_OPERATION, "%(name)s\", \"%(id)s reserved id");
return;
}
if (Bind%(type)sHelper(%(arg_string)s)) {
if (%(name)sHelper(%(arg_string)s)) {
helper_->%(name)s(%(arg_string)s);
}
CheckGLError();
Expand Down
21 changes: 10 additions & 11 deletions gpu/command_buffer/client/gles2_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1142,16 +1142,6 @@ GLint GLES2Implementation::GetUniformLocation(
return loc;
}

void GLES2Implementation::UseProgram(GLuint program) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUseProgram(" << program << ")");
if (current_program_ != program) {
current_program_ = program;
helper_->UseProgram(program);
}
CheckGLError();
}

bool GLES2Implementation::GetProgramivHelper(
GLuint program, GLenum pname, GLint* params) {
bool got_value = share_group_->program_info_manager()->GetProgramiv(
Expand Down Expand Up @@ -2526,7 +2516,7 @@ bool GLES2Implementation::BindTextureHelper(GLenum target, GLuint texture) {
return changed;
}

bool GLES2Implementation::BindVertexArrayHelper(GLuint array) {
bool GLES2Implementation::BindVertexArrayOESHelper(GLuint array) {
// TODO(gman): See note #1 above.
bool changed = false;
if (!vertex_array_object_manager_->BindVertexArray(array, &changed)) {
Expand All @@ -2541,6 +2531,15 @@ bool GLES2Implementation::BindVertexArrayHelper(GLuint array) {
return changed;
}

bool GLES2Implementation::UseProgramHelper(GLuint program) {
bool changed = false;
if (current_program_ != program) {
current_program_ = program;
changed = true;
}
return changed;
}

bool GLES2Implementation::IsBufferReservedId(GLuint id) {
return vertex_array_object_manager_->IsReservedId(id);
}
Expand Down
4 changes: 3 additions & 1 deletion gpu/command_buffer/client/gles2_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,14 @@ class GLES2_IMPL_EXPORT GLES2Implementation
bool IsRenderbufferReservedId(GLuint id) { return false; }
bool IsTextureReservedId(GLuint id) { return false; }
bool IsVertexArrayReservedId(GLuint id) { return false; }
bool IsProgramReservedId(GLuint id) { return false; }

bool BindBufferHelper(GLenum target, GLuint texture);
bool BindFramebufferHelper(GLenum target, GLuint texture);
bool BindRenderbufferHelper(GLenum target, GLuint texture);
bool BindTextureHelper(GLenum target, GLuint texture);
bool BindVertexArrayHelper(GLuint array);
bool BindVertexArrayOESHelper(GLuint array);
bool UseProgramHelper(GLuint program);

void GenBuffersHelper(GLsizei n, const GLuint* buffers);
void GenFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
Expand Down
15 changes: 14 additions & 1 deletion gpu/command_buffer/client/gles2_implementation_impl_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,19 @@ void GLES2Implementation::UniformMatrix4fv(GLint location,
CheckGLError();
}

void GLES2Implementation::UseProgram(GLuint program) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUseProgram(" << program << ")");
if (IsProgramReservedId(program)) {
SetGLError(GL_INVALID_OPERATION, "UseProgram", "program reserved id");
return;
}
if (UseProgramHelper(program)) {
helper_->UseProgram(program);
}
CheckGLError();
}

void GLES2Implementation::ValidateProgram(GLuint program) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glValidateProgram(" << program
Expand Down Expand Up @@ -1906,7 +1919,7 @@ void GLES2Implementation::BindVertexArrayOES(GLuint array) {
SetGLError(GL_INVALID_OPERATION, "BindVertexArrayOES", "array reserved id");
return;
}
if (BindVertexArrayHelper(array)) {
if (BindVertexArrayOESHelper(array)) {
helper_->BindVertexArrayOES(array);
}
CheckGLError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,9 @@ TEST_F(GLES2ImplementationTest, UseProgram) {

gl_->UseProgram(1);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
ClearCommands();
gl_->UseProgram(1);
EXPECT_TRUE(NoCommandsWritten());
}

TEST_F(GLES2ImplementationTest, ValidateProgram) {
Expand Down
15 changes: 15 additions & 0 deletions gpu/command_buffer/service/gles2_cmd_decoder_unittest_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ void GLES2DecoderTestBase::SpecializedSetup<cmds::LinkProgram, 0>(
EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
};

template <>
void GLES2DecoderTestBase::SpecializedSetup<cmds::UseProgram, 0>(
bool /* valid */) {
// Needs the same setup as LinkProgram.
SpecializedSetup<cmds::LinkProgram, 0>(false);

EXPECT_CALL(*gl_, LinkProgram(kServiceProgramId))
.Times(1)
.RetiresOnSaturation();

cmds::LinkProgram link_cmd;
link_cmd.Init(client_program_id_);
EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
};

template <>
void GLES2DecoderTestBase::SpecializedSetup<cmds::ValidateProgram, 0>(
bool /* valid */) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,24 @@ TEST_F(GLES2DecoderTest2, UniformMatrix4fvImmediateInvalidArgs2_0) {
EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
// TODO(gman): UseProgram

TEST_F(GLES2DecoderTest2, UseProgramValidArgs) {
EXPECT_CALL(*gl_, UseProgram(kServiceProgramId));
SpecializedSetup<cmds::UseProgram, 0>(true);
cmds::UseProgram cmd;
cmd.Init(client_program_id_);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}

TEST_F(GLES2DecoderTest2, UseProgramInvalidArgs0_0) {
EXPECT_CALL(*gl_, UseProgram(_)).Times(0);
SpecializedSetup<cmds::UseProgram, 0>(false);
cmds::UseProgram cmd;
cmd.Init(kInvalidClientId);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}

TEST_F(GLES2DecoderTest2, ValidateProgramValidArgs) {
EXPECT_CALL(*gl_, ValidateProgram(kServiceProgramId));
Expand Down

0 comments on commit cb79eaa

Please sign in to comment.