diff options
Diffstat (limited to 'gpu/command_buffer')
-rwxr-xr-x | gpu/command_buffer/build_gles2_cmd_buffer.py | 379 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.cc | 15 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.h | 2 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation_unittest.cc | 109 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation_unittest_autogen.h | 1578 | ||||
-rw-r--r-- | gpu/command_buffer/common/gles2_cmd_format.h | 2 |
6 files changed, 2052 insertions, 33 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py index ece3ddc..fbeb98f 100755 --- a/gpu/command_buffer/build_gles2_cmd_buffer.py +++ b/gpu/command_buffer/build_gles2_cmd_buffer.py @@ -1139,7 +1139,8 @@ _ENUM_LISTS = { # needs_size: If true a data_size field is added to the command. # data_type: The type of data the command uses. For PUTn or PUT types. # count: The number of units per element. For PUTn or PUT types. -# unit_test: If False no unit test will be generated. +# unit_test: If False no service side unit test will be generated. +# client_test: If False no client side unit test will be generated. # expectation: If False the unit test will have no expected calls. # gen_func: Name of function that generates GL resource for corresponding # bind function. @@ -1151,6 +1152,7 @@ _FUNCTION_INFO = { 'decoder_func': 'DoActiveTexture', 'unit_test': False, 'impl_func': False, + 'client_test': False, }, 'AttachShader': {'decoder_func': 'DoAttachShader'}, 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, @@ -1181,8 +1183,16 @@ _FUNCTION_INFO = { 'unit_test': False, 'extension': True, }, - 'BufferData': {'type': 'Manual', 'immediate': True}, - 'BufferSubData': {'type': 'Data', 'decoder_func': 'DoBufferSubData'}, + 'BufferData': { + 'type': 'Manual', + 'immediate': True, + 'client_test': False, + }, + 'BufferSubData': { + 'type': 'Data', + 'client_test': False, + 'decoder_func': 'DoBufferSubData', + }, 'CheckFramebufferStatus': { 'type': 'Is', 'decoder_func': 'DoCheckFramebufferStatus', @@ -1225,8 +1235,14 @@ _FUNCTION_INFO = { 'CopyTexSubImage2D': { 'decoder_func': 'DoCopyTexSubImage2D', }, - 'CreateProgram': {'type': 'Create'}, - 'CreateShader': {'type': 'Create'}, + 'CreateProgram': { + 'type': 'Create', + 'client_test': False, + }, + 'CreateShader': { + 'type': 'Create', + 'client_test': False, + }, 'DeleteBuffers': { 'type': 'DELn', 'gl_test_func': 'glDeleteBuffersARB', @@ -1263,11 +1279,13 @@ _FUNCTION_INFO = { }, 'DrawArrays': { 'type': 'Manual', - 'cmd_args': 'GLenum mode, GLint first, GLsizei count', + 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count', }, 'DrawElements': { 'type': 'Manual', - 'cmd_args': 'GLenum mode, GLsizei count, GLenum type, GLuint index_offset', + 'cmd_args': 'GLenumDrawMode mode, GLsizei count, ' + 'GLenumIndexType type, GLuint index_offset', + 'client_test': False }, 'Enable': { 'decoder_func': 'DoEnable', @@ -1276,7 +1294,10 @@ _FUNCTION_INFO = { 'decoder_func': 'DoEnableVertexAttribArray', 'impl_decl': False, }, - 'Finish': {'impl_func': False}, + 'Finish': { + 'impl_func': False, + 'client_test': False, + }, 'Flush': {'impl_func': False}, 'FramebufferRenderbuffer': { 'decoder_func': 'DoFramebufferRenderbuffer', @@ -1354,6 +1375,7 @@ _FUNCTION_INFO = { 'decoder_func': 'GetGLError', 'impl_func': False, 'result': ['GLenum'], + 'client_test': False, }, 'GetFloatv': { 'type': 'GETn', @@ -1371,12 +1393,14 @@ _FUNCTION_INFO = { 'type': 'GETn', 'result': ['SizedResult<GLint>'], 'decoder_func': 'DoGetIntegerv', + 'client_test': False, }, 'GetMaxValueInBufferCHROMIUM': { 'type': 'Is', 'decoder_func': 'DoGetMaxValueInBufferCHROMIUM', 'result': ['GLuint'], 'unit_test': False, + 'client_test': False, 'extension': True, 'chromium': True, }, @@ -1386,6 +1410,7 @@ _FUNCTION_INFO = { 'expectation': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'GetProgramiv': { 'type': 'GETn', @@ -1399,6 +1424,7 @@ _FUNCTION_INFO = { 'impl_func': False, 'extension': True, 'chromium': True, + 'client_test': False, 'cmd_args': 'GLidProgram program, uint32 bucket_id', 'result': [ 'uint32 link_status', @@ -1445,9 +1471,11 @@ _FUNCTION_INFO = { 'get_len_func': 'DoGetShaderiv', 'get_len_enum': 'GL_SHADER_SOURCE_LENGTH', 'unit_test': False, + 'client_test': False, }, 'GetString': { 'type': 'Custom', + 'client_test': False, 'cmd_args': 'GLenumStringType name, uint32 bucket_id', }, 'GetTexParameterfv': {'type': 'GETn', 'result': ['SizedResult<GLfloat>']}, @@ -1484,6 +1512,7 @@ _FUNCTION_INFO = { 'impl_decl': False, 'decoder_func': 'DoGetVertexAttribfv', 'expectation': False, + 'client_test': False, }, 'GetVertexAttribiv': { 'type': 'GETn', @@ -1491,11 +1520,13 @@ _FUNCTION_INFO = { 'impl_decl': False, 'decoder_func': 'DoGetVertexAttribiv', 'expectation': False, + 'client_test': False, }, 'GetVertexAttribPointerv': { 'type': 'Custom', 'immediate': False, 'result': ['SizedResult<GLuint>'], + 'client_test': False, }, 'IsBuffer': { 'type': 'Is', @@ -1536,17 +1567,20 @@ _FUNCTION_INFO = { 'gen_cmd': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'MapTexSubImage2DCHROMIUM': { 'gen_cmd': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'PixelStorei': {'type': 'Manual'}, 'PostSubBufferCHROMIUM': { 'type': 'Custom', 'impl_func': False, 'unit_test': False, + 'client_test': False, 'extension': True, 'chromium': True, }, @@ -1570,9 +1604,11 @@ _FUNCTION_INFO = { 'type': 'Custom', 'immediate': False, 'impl_func': False, + 'client_test': False, 'cmd_args': - 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, ' - 'GLenum type, uint32 pixels_shm_id, uint32 pixels_shm_offset, ' + 'GLint x, GLint y, GLsizei width, GLsizei height, ' + 'GLenumReadPixelFormat format, GLenumPixelType type, ' + 'uint32 pixels_shm_id, uint32 pixels_shm_offset, ' 'uint32 result_shm_id, uint32 result_shm_offset', 'result': ['uint32'], }, @@ -1589,12 +1625,16 @@ _FUNCTION_INFO = { 'decoder_func': 'DoReleaseShaderCompiler', 'unit_test': False, }, - 'ShaderBinary': {'type': 'Custom'}, + 'ShaderBinary': { + 'type': 'Custom', + 'client_test': False, + }, 'ShaderSource': { 'type': 'Manual', 'immediate': True, 'bucket': True, 'needs_size': True, + 'client_test': False, 'cmd_args': 'GLuint shader, const char* data', }, @@ -1607,9 +1647,14 @@ _FUNCTION_INFO = { 'type': 'Custom', 'impl_func': False, 'unit_test': False, + 'client_test': False, 'extension': True, }, - 'TexImage2D': {'type': 'Manual', 'immediate': True}, + 'TexImage2D': { + 'type': 'Manual', + 'immediate': True, + 'client_test': False, + }, 'TexParameterf': { 'decoder_func': 'DoTexParameterf', 'valid_args': { @@ -1639,8 +1684,11 @@ _FUNCTION_INFO = { 'TexSubImage2D': { 'type': 'Manual', 'immediate': True, - 'cmd_args': 'GLenum target, GLint level, GLint xoffset, GLint yoffset, ' - 'GLsizei width, GLsizei height, GLenum format, GLenum type, ' + 'client_test': False, + 'cmd_args': 'GLenumTextureTarget target, GLint level, ' + 'GLint xoffset, GLint yoffset, ' + 'GLsizei width, GLsizei height, ' + 'GLenumTextureFormat format, GLenumPixelType type, ' 'const void* pixels, GLboolean internal' }, 'Uniform1f': {'type': 'PUTXn', 'data_type': 'GLfloat', 'count': 1}, @@ -1721,11 +1769,13 @@ _FUNCTION_INFO = { 'gen_cmd': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'UnmapTexSubImage2DCHROMIUM': { 'gen_cmd': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'UseProgram': {'decoder_func': 'DoUseProgram', 'unit_test': False}, 'ValidateProgram': {'decoder_func': 'DoValidateProgram'}, @@ -1759,8 +1809,10 @@ _FUNCTION_INFO = { }, 'VertexAttribPointer': { 'type': 'Manual', - 'cmd_args': 'GLuint indx, GLint size, GLenum type, GLboolean normalized, ' + 'cmd_args': 'GLuint indx, GLintVertexAttribSize size, ' + 'GLenumVertexAttribType type, GLboolean normalized, ' 'GLsizei stride, GLuint offset', + 'client_test': False, }, 'ResizeCHROMIUM': { 'type': 'Custom', @@ -1781,6 +1833,7 @@ _FUNCTION_INFO = { 'type': 'Custom', 'impl_func': False, 'immediate': False, + 'client_test': False, 'cmd_args': 'uint32 bucket_id', 'extension': True, 'chromium': True, @@ -1789,6 +1842,7 @@ _FUNCTION_INFO = { 'gen_cmd': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'Placeholder447CHROMIUM': { 'type': 'UnknownCommand', @@ -1804,6 +1858,7 @@ _FUNCTION_INFO = { 'expectation': False, 'extension': True, 'chromium': True, + 'client_test': False, }, 'DestroyStreamTextureCHROMIUM': { 'type': 'Custom', @@ -1878,8 +1933,8 @@ class CWriter(object): def __init__(self, filename): self.filename = filename - self.file = open(filename, "wb") self.file_num = 0 + self.content = [] def SetFileNum(self, num): """Used to help write number files and tests.""" @@ -1932,7 +1987,7 @@ class CWriter(object): nolint = '' if len(line1) > 80: nolint = ' // NOLINT' - self.file.write(line1 + nolint + '\n') + self.__AddLine(line1 + nolint + '\n') match = re.match("( +)", line1) indent = "" if match: @@ -1945,13 +2000,27 @@ class CWriter(object): nolint = '' if len(line) > 80: nolint = ' // NOLINT' - self.file.write(line + nolint) + self.__AddLine(line + nolint) if ends_with_eol: - self.file.write('\n') + self.__AddLine('\n') + + def __AddLine(self, line): + self.content.append(line) def Close(self): """Close the file.""" - self.file.close() + content = "".join(self.content) + write_file = True + if os.path.exists(self.filename): + old_file = open(self.filename, "rb"); + old_content = old_file.read() + old_file.close(); + if content == old_content: + write_file = False + if write_file: + file = open(self.filename, "wb") + file.write(content) + file.close() class CHeaderWriter(CWriter): @@ -2382,6 +2451,42 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { else: self.WriteGLES2ImplementationDeclaration(func, file) + def WriteGLES2ImplementationUnitTest(self, func, file): + """Writes the GLES2 Implemention unit test.""" + client_test = func.GetInfo('client_test') + if (func.can_auto_generate and + (client_test == None or client_test == True)): + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + struct Cmds { + %(name)s cmd; + }; + Cmds expected; + expected.cmd.Init(%(cmd_args)s); + + gl_->%(name)s(%(args)s); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +""" + cmd_arg_strings = [] + count = 0 + for arg in func.GetCmdArgs(): + cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0)) + count += 1 + gl_arg_strings = [] + count = 0 + for arg in func.GetOriginalArgs(): + gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0)) + count += 1 + file.Write(code % { + 'name': func.name, + 'args': ", ".join(gl_arg_strings), + 'cmd_args': ", ".join(cmd_arg_strings), + }) + else: + if client_test != False: + file.Write("// TODO: Implement unit test for %s\n" % func.name) + def WriteDestinationInitalizationValidation(self, func, file): """Writes the client side destintion initialization validation.""" for arg in func.GetOriginalArgs(): @@ -2883,6 +2988,30 @@ class GENnHandler(TypeHandler): """ file.Write(code % args) + def WriteGLES2ImplementationUnitTest(self, func, file): + """Overrriden from TypeHandler.""" + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + GLuint ids[2] = { 0, }; + struct Cmds { + %(name)sImmediate gen; + GLuint data[2]; + }; + Cmds expected; + expected.gen.Init(arraysize(ids), &ids[0]); + expected.data[0] = k%(type)ssStartId; + expected.data[1] = k%(type)ssStartId + 1; + gl_->%(name)s(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(k%(type)ssStartId, ids[0]); + EXPECT_EQ(k%(type)ssStartId + 1, ids[1]); +} +""" + file.Write(code % { + 'name': func.name, + 'type': func.name[3:-1], + }) + def WriteServiceUnitTest(self, func, file): """Overrriden from TypeHandler.""" valid_test = """ @@ -3148,6 +3277,28 @@ class DELnHandler(TypeHandler): """ file.Write(code) + def WriteGLES2ImplementationUnitTest(self, func, file): + """Overrriden from TypeHandler.""" + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + GLuint ids[2] = { k%(type)ssStartId, k%(type)ssStartId + 1 }; + struct Cmds { + %(name)sImmediate del; + GLuint data[2]; + }; + Cmds expected; + expected.del.Init(arraysize(ids), &ids[0]); + expected.data[0] = k%(type)ssStartId; + expected.data[1] = k%(type)ssStartId + 1; + gl_->%(name)s(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +""" + file.Write(code % { + 'name': func.name, + 'type': func.GetOriginalArgs()[1].name[0:-1].capitalize(), + }) + def WriteServiceUnitTest(self, func, file): """Overrriden from TypeHandler.""" valid_test = """ @@ -3441,6 +3592,43 @@ class GETnHandler(TypeHandler): 'all_arg_string': all_arg_string, }) + def WriteGLES2ImplementationUnitTest(self, func, file): + """Writes the GLES2 Implemention unit test.""" + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + struct Cmds { + %(name)s cmd; + }; + typedef %(name)s::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(%(cmd_args)s, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->%(name)s(%(args)s, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} +""" + cmd_arg_strings = [] + count = 0 + for arg in func.GetCmdArgs()[0:-2]: + cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0)) + count += 1 + cmd_arg_strings[0] = '123' + gl_arg_strings = [] + count = 0 + for arg in func.GetOriginalArgs()[0:-1]: + gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0)) + count += 1 + gl_arg_strings[0] = '123' + file.Write(code % { + 'name': func.name, + 'args': ", ".join(gl_arg_strings), + 'cmd_args': ", ".join(cmd_arg_strings), + }) + def WriteServiceUnitTest(self, func, file): """Overrriden from TypeHandler.""" valid_test = """ @@ -3613,6 +3801,42 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { file.Write("}\n") file.Write("\n") + def WriteGLES2ImplementationUnitTest(self, func, file): + """Writes the GLES2 Implemention unit test.""" + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + struct Cmds { + %(name)sImmediate cmd; + %(type)s data[%(count)d]; + }; + + Cmds expected; + for (int jj = 0; jj < %(count)d; ++jj) { + expected.data[jj] = static_cast<%(type)s>(jj); + } + expected.cmd.Init(%(cmd_args)s, &expected.data[0]); + gl_->%(name)s(%(args)s, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +""" + cmd_arg_strings = [] + count = 0 + for arg in func.GetCmdArgs()[0:-2]: + cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0)) + count += 1 + gl_arg_strings = [] + count = 0 + for arg in func.GetOriginalArgs()[0:-1]: + gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0)) + count += 1 + file.Write(code % { + 'name': func.name, + 'type': func.GetInfo('data_type'), + 'count': func.GetInfo('count'), + 'args': ", ".join(gl_arg_strings), + 'cmd_args': ", ".join(cmd_arg_strings), + }) + def WriteImmediateCmdComputeSize(self, func, file): """Overrriden from TypeHandler.""" file.Write(" static uint32 ComputeDataSize() {\n") @@ -3843,6 +4067,44 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { file.Write("}\n") file.Write("\n") + def WriteGLES2ImplementationUnitTest(self, func, file): + """Writes the GLES2 Implemention unit test.""" + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + struct Cmds { + %(name)sImmediate cmd; + %(type)s data[2][%(count)d]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < %(count)d; ++jj) { + expected.data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj); + } + } + expected.cmd.Init(%(cmd_args)s, &expected.data[0][0]); + gl_->%(name)s(%(args)s, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +""" + cmd_arg_strings = [] + count = 0 + for arg in func.GetCmdArgs()[0:-2]: + cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0)) + count += 1 + gl_arg_strings = [] + count = 0 + for arg in func.GetOriginalArgs()[0:-1]: + gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0)) + count += 1 + file.Write(code % { + 'name': func.name, + 'type': func.GetInfo('data_type'), + 'count': func.GetInfo('count'), + 'args': ", ".join(gl_arg_strings), + 'cmd_args': ", ".join(cmd_arg_strings), + }) + def WriteImmediateCmdComputeSize(self, func, file): """Overrriden from TypeHandler.""" file.Write(" static uint32 ComputeDataSize(GLsizei count) {\n") @@ -4234,6 +4496,33 @@ TEST_F(%(test_name)s, %(name)sInvalidArgsBadSharedMemoryId) { else: self.WriteGLES2ImplementationDeclaration(func, file) + def WriteGLES2ImplementationUnitTest(self, func, file): + """Overrriden from TypeHandler.""" + client_test = func.GetInfo('client_test') + if client_test == None or client_test == True: + code = """ +TEST_F(GLES2ImplementationTest, %(name)s) { + struct Cmds { + %(name)s cmd; + }; + + typedef %(name)s::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->%(name)s(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} +""" + file.Write(code % { + 'name': func.name, + }) + class STRnHandler(TypeHandler): """Handler for GetProgramInfoLog, GetShaderInfoLog, GetShaderSource, and @@ -4385,11 +4674,16 @@ class UnknownCommandHandler(TypeHandler): def WriteGLES2CLibImplementation(self, func, file): """Overrriden from TypeHandler.""" - pass; + pass def WriteServiceUnitTest(self, func, file): """Overrriden from TypeHandler.""" - pass; + pass + + def WriteGLES2ImplementationUnitTest(self, func, file): + """Overrriden from TypeHandler.""" + pass + class FunctionInfo(object): """Holds info about a function.""" @@ -4444,6 +4738,14 @@ class Argument(object): return valid_arg return str(offset + 1) + def GetValidClientSideArg(self, func, offset, index): + """Gets a valid value for this argument.""" + return str(offset + 1) + + def GetValidClientSideCmdArg(self, func, offset, index): + """Gets a valid value for this argument.""" + return str(offset + 1) + def GetValidGLArg(self, func, offset, index): """Gets a valid GL value for this argument.""" valid_arg = func.GetValidArg(offset) @@ -4517,6 +4819,14 @@ class BoolArgument(Argument): """Gets a valid value for this argument.""" return 'true' + def GetValidClientSideArg(self, func, offset, index): + """Gets a valid value for this argument.""" + return 'true' + + def GetValidClientSideCmdArg(self, func, offset, index): + """Gets a valid value for this argument.""" + return 'true' + def GetValidGLArg(self, func, offset, index): """Gets a valid GL value for this argument.""" return 'true' @@ -4617,7 +4927,16 @@ class EnumBaseArgument(Argument): return valid[index] return str(offset + 1) + def GetValidClientSideArg(self, func, offset, index): + """Gets a valid value for this argument.""" + return self.GetValidArg(func, offset, index) + + def GetValidClientSideCmdArg(self, func, offset, index): + """Gets a valid value for this argument.""" + return self.GetValidArg(func, offset, index) + def GetValidGLArg(self, func, offset, index): + """Gets a valid value for this argument.""" return self.GetValidArg(func, offset, index) def GetNumInvalidValues(self, func): @@ -5165,6 +5484,10 @@ class Function(object): """Writes the GLES2 Implemention declaration.""" self.type_handler.WriteGLES2ImplementationHeader(self, file) + def WriteGLES2ImplementationUnitTest(self, file): + """Writes the GLES2 Implemention unit test.""" + self.type_handler.WriteGLES2ImplementationUnitTest(self, file) + def WriteDestinationInitalizationValidation(self, file): """Writes the client side destintion initialization validation.""" self.type_handler.WriteDestinationInitalizationValidation(self, file) @@ -5671,6 +5994,16 @@ class GLGenerator(object): func.WriteGLES2ImplementationHeader(file) file.Close() + def WriteGLES2ImplementationUnitTests(self, filename): + """Writes the GLES2 helper header.""" + file = CHeaderWriter( + filename, + "// This file is included by gles2_implementation.h to declare the\n" + "// GL api functions.\n") + for func in self.original_functions: + func.WriteGLES2ImplementationUnitTest(file) + file.Close() + def WriteServiceUtilsHeader(self, filename): """Writes the gles2 auto generated utility header.""" file = CHeaderWriter(filename) @@ -6014,6 +6347,8 @@ def main(argv): gen.WriteFormat("common/gles2_cmd_format_autogen.h") gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") + gen.WriteGLES2ImplementationUnitTests( + "client/gles2_implementation_unittest_autogen.h") gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index ecf4d6c..cad8722 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -2001,10 +2001,7 @@ void GLES2Implementation::GetShaderPrecisionFormat( } } -const GLubyte* GLES2Implementation::GetString(GLenum name) { - GPU_CLIENT_SINGLE_THREAD_CHECK(); - GPU_CLIENT_LOG("[" << this << "] glGetString(" - << GLES2Util::GetStringStringType(name) << ")"); +const GLubyte* GLES2Implementation::GetStringHelper(GLenum name) { const char* result = NULL; // Clears the bucket so if the command fails nothing will be in it. helper_->SetBucketSize(kResultBucketId, 0); @@ -2044,10 +2041,18 @@ const GLubyte* GLES2Implementation::GetString(GLenum name) { result = insert_result.first->c_str(); } } - GPU_CLIENT_LOG(" returned " << static_cast<const char*>(result)); return reinterpret_cast<const GLubyte*>(result); } +const GLubyte* GLES2Implementation::GetString(GLenum name) { + GPU_CLIENT_SINGLE_THREAD_CHECK(); + GPU_CLIENT_LOG("[" << this << "] glGetString(" + << GLES2Util::GetStringStringType(name) << ")"); + const GLubyte* result = GetStringHelper(name); + GPU_CLIENT_LOG(" returned " << reinterpret_cast<const char*>(result)); + return result; +} + void GLES2Implementation::GetUniformfv( GLuint program, GLint location, GLfloat* params) { GPU_CLIENT_SINGLE_THREAD_CHECK(); diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h index 5a23671..690f4ba 100644 --- a/gpu/command_buffer/client/gles2_implementation.h +++ b/gpu/command_buffer/client/gles2_implementation.h @@ -494,6 +494,8 @@ class GLES2Implementation { bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params); bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params); bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params); + const GLubyte* GetStringHelper(GLenum name); + GLES2Util util_; GLES2CmdHelper* helper_; diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc index 4c6013d..719419c 100644 --- a/gpu/command_buffer/client/gles2_implementation_unittest.cc +++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc @@ -433,6 +433,12 @@ class GLES2ImplementationTest : public GLES2CommandBufferTestBase { static const GLint kNumCompressedTextureFormats = 0; static const GLint kNumShaderBinaryFormats = 0; static const GLuint kStartId = 1024; + static const GLuint kBuffersStartId = + GLES2Implementation::kClientSideArrayId + 2; + static const GLuint kFramebuffersStartId = 1; + static const GLuint kProgramsAndShadersStartId = 1; + static const GLuint kRenderbuffersStartId = 1; + static const GLuint kTexturesStartId = 1; GLES2ImplementationTest() { } @@ -532,6 +538,28 @@ class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest { } }; +// GCC requires these declarations, but MSVC requires they not be present +#ifndef _MSC_VER +const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits; +const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize; +const GLint GLES2ImplementationTest::kMaxFragmentUniformVectors; +const GLint GLES2ImplementationTest::kMaxRenderbufferSize; +const GLint GLES2ImplementationTest::kMaxTextureImageUnits; +const GLint GLES2ImplementationTest::kMaxTextureSize; +const GLint GLES2ImplementationTest::kMaxVaryingVectors; +const GLint GLES2ImplementationTest::kMaxVertexAttribs; +const GLint GLES2ImplementationTest::kMaxVertexTextureImageUnits; +const GLint GLES2ImplementationTest::kMaxVertexUniformVectors; +const GLint GLES2ImplementationTest::kNumCompressedTextureFormats; +const GLint GLES2ImplementationTest::kNumShaderBinaryFormats; +const GLuint GLES2ImplementationTest::kStartId; +const GLuint GLES2ImplementationTest::kBuffersStartId; +const GLuint GLES2ImplementationTest::kFramebuffersStartId; +const GLuint GLES2ImplementationTest::kProgramsAndShadersStartId; +const GLuint GLES2ImplementationTest::kRenderbuffersStartId; +const GLuint GLES2ImplementationTest::kTexturesStartId; +#endif + TEST_F(GLES2ImplementationTest, ShaderSource) { const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation const GLuint kShaderId = 456; @@ -2066,20 +2094,89 @@ TEST_F(GLES2ImplementationTest, CreateStreamTextureCHROMIUM) { EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); } -TEST_F(GLES2ImplementationTest, DestroyStreamTextureCHROMIUM) { - const GLuint kTextureHandle = 456; - +TEST_F(GLES2ImplementationTest, GetString) { + const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation + const Str7 kString = {"foobar"}; + // GL_CHROMIUM_map_sub GL_CHROMIUM_flipy are hard coded into + // GLES2Implementation. + const char* expected_str = "foobar GL_CHROMIUM_map_sub GL_CHROMIUM_flipy"; + const char kBad = 0x12; struct Cmds { - DestroyStreamTextureCHROMIUM destroy_stream; + cmd::SetBucketSize set_bucket_size1; + GetString get_string; + cmd::GetBucketSize get_bucket_size; + cmd::GetBucketData get_bucket_data; + cmd::SetToken set_token1; + cmd::SetBucketSize set_bucket_size2; }; + uint32 offset = AllocateTransferBuffer(sizeof(kString)); + Cmds expected; + expected.set_bucket_size1.Init(kBucketId, 0); + expected.get_string.Init(GL_EXTENSIONS, kBucketId); + expected.get_bucket_size.Init(kBucketId, transfer_buffer_id_, 0); + expected.get_bucket_data.Init( + kBucketId, 0, sizeof(kString), transfer_buffer_id_, offset); + expected.set_token1.Init(GetNextToken()); + expected.set_bucket_size2.Init(kBucketId, 0); + char buf[sizeof(kString) + 1]; + memset(buf, kBad, sizeof(buf)); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(sizeof(kString)))) + .WillOnce(SetMemoryAtOffset(offset, kString)) + .RetiresOnSaturation(); + + const GLubyte* result = gl_->GetString(GL_EXTENSIONS); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_STREQ(expected_str, reinterpret_cast<const char*>(result)); +} +TEST_F(GLES2ImplementationTest, PixelStoreiGLPackReverseRowOrderANGLE) { + const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation + const Str7 kString = {"foobar"}; + struct Cmds { + cmd::SetBucketSize set_bucket_size1; + GetString get_string; + cmd::GetBucketSize get_bucket_size; + cmd::GetBucketData get_bucket_data; + cmd::SetToken set_token1; + cmd::SetBucketSize set_bucket_size2; + PixelStorei pixel_store; + }; + uint32 offset = AllocateTransferBuffer(sizeof(kString)); Cmds expected; - expected.destroy_stream.Init(kTextureHandle); + expected.set_bucket_size1.Init(kBucketId, 0); + expected.get_string.Init(GL_EXTENSIONS, kBucketId); + expected.get_bucket_size.Init(kBucketId, transfer_buffer_id_, 0); + expected.get_bucket_data.Init( + kBucketId, 0, sizeof(kString), transfer_buffer_id_, offset); + expected.set_token1.Init(GetNextToken()); + expected.set_bucket_size2.Init(kBucketId, 0); + expected.pixel_store.Init(GL_PACK_REVERSE_ROW_ORDER_ANGLE, 1); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(sizeof(kString)))) + .WillOnce(SetMemoryAtOffset(offset, kString)) + .RetiresOnSaturation(); - gl_->DestroyStreamTextureCHROMIUM(kTextureHandle); + gl_->PixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, 1); EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); } +TEST_F(GLES2ImplementationTest, CreateProgram) { + struct Cmds { + CreateProgram cmd; + }; + + Cmds expected; + expected.cmd.Init(kProgramsAndShadersStartId); + GLuint id = gl_->CreateProgram(); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(kProgramsAndShadersStartId, id); +} + +#include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" + } // namespace gles2 } // namespace gpu diff --git a/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h b/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h new file mode 100644 index 0000000..07a2ae7 --- /dev/null +++ b/gpu/command_buffer/client/gles2_implementation_unittest_autogen.h @@ -0,0 +1,1578 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto-generated from +// gpu/command_buffer/build_gles2_cmd_buffer.py +// DO NOT EDIT! + +// This file is included by gles2_implementation.h to declare the +// GL api functions. +#ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_UNITTEST_AUTOGEN_H_ +#define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_UNITTEST_AUTOGEN_H_ + + +TEST_F(GLES2ImplementationTest, AttachShader) { + struct Cmds { + AttachShader cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->AttachShader(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +// TODO: Implement unit test for BindAttribLocation + +TEST_F(GLES2ImplementationTest, BindBuffer) { + struct Cmds { + BindBuffer cmd; + }; + Cmds expected; + expected.cmd.Init(GL_ARRAY_BUFFER, 2); + + gl_->BindBuffer(GL_ARRAY_BUFFER, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BindFramebuffer) { + struct Cmds { + BindFramebuffer cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRAMEBUFFER, 2); + + gl_->BindFramebuffer(GL_FRAMEBUFFER, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BindRenderbuffer) { + struct Cmds { + BindRenderbuffer cmd; + }; + Cmds expected; + expected.cmd.Init(GL_RENDERBUFFER, 2); + + gl_->BindRenderbuffer(GL_RENDERBUFFER, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BindTexture) { + struct Cmds { + BindTexture cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, 2); + + gl_->BindTexture(GL_TEXTURE_2D, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BlendColor) { + struct Cmds { + BlendColor cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->BlendColor(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BlendEquation) { + struct Cmds { + BlendEquation cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FUNC_ADD); + + gl_->BlendEquation(GL_FUNC_ADD); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BlendEquationSeparate) { + struct Cmds { + BlendEquationSeparate cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FUNC_ADD, GL_FUNC_ADD); + + gl_->BlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BlendFunc) { + struct Cmds { + BlendFunc cmd; + }; + Cmds expected; + expected.cmd.Init(GL_ZERO, GL_ZERO); + + gl_->BlendFunc(GL_ZERO, GL_ZERO); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BlendFuncSeparate) { + struct Cmds { + BlendFuncSeparate cmd; + }; + Cmds expected; + expected.cmd.Init(GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO); + + gl_->BlendFuncSeparate(GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, CheckFramebufferStatus) { + struct Cmds { + CheckFramebufferStatus cmd; + }; + + typedef CheckFramebufferStatus::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->CheckFramebufferStatus(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, Clear) { + struct Cmds { + Clear cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->Clear(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, ClearColor) { + struct Cmds { + ClearColor cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->ClearColor(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, ClearDepthf) { + struct Cmds { + ClearDepthf cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->ClearDepthf(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, ClearStencil) { + struct Cmds { + ClearStencil cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->ClearStencil(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, ColorMask) { + struct Cmds { + ColorMask cmd; + }; + Cmds expected; + expected.cmd.Init(true, true, true, true); + + gl_->ColorMask(true, true, true, true); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, CompileShader) { + struct Cmds { + CompileShader cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->CompileShader(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +// TODO: Implement unit test for CompressedTexImage2D +// TODO: Implement unit test for CompressedTexSubImage2D + +TEST_F(GLES2ImplementationTest, CopyTexImage2D) { + struct Cmds { + CopyTexImage2D cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, 2, GL_ALPHA, 4, 5, 6, 7, 0); + + gl_->CopyTexImage2D(GL_TEXTURE_2D, 2, GL_ALPHA, 4, 5, 6, 7, 0); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, CopyTexSubImage2D) { + struct Cmds { + CopyTexSubImage2D cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, 2, 3, 4, 5, 6, 7, 8); + + gl_->CopyTexSubImage2D(GL_TEXTURE_2D, 2, 3, 4, 5, 6, 7, 8); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, CullFace) { + struct Cmds { + CullFace cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRONT); + + gl_->CullFace(GL_FRONT); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DeleteBuffers) { + GLuint ids[2] = { kBuffersStartId, kBuffersStartId + 1 }; + struct Cmds { + DeleteBuffersImmediate del; + GLuint data[2]; + }; + Cmds expected; + expected.del.Init(arraysize(ids), &ids[0]); + expected.data[0] = kBuffersStartId; + expected.data[1] = kBuffersStartId + 1; + gl_->DeleteBuffers(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DeleteFramebuffers) { + GLuint ids[2] = { kFramebuffersStartId, kFramebuffersStartId + 1 }; + struct Cmds { + DeleteFramebuffersImmediate del; + GLuint data[2]; + }; + Cmds expected; + expected.del.Init(arraysize(ids), &ids[0]); + expected.data[0] = kFramebuffersStartId; + expected.data[1] = kFramebuffersStartId + 1; + gl_->DeleteFramebuffers(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DeleteProgram) { + struct Cmds { + DeleteProgram cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->DeleteProgram(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DeleteRenderbuffers) { + GLuint ids[2] = { kRenderbuffersStartId, kRenderbuffersStartId + 1 }; + struct Cmds { + DeleteRenderbuffersImmediate del; + GLuint data[2]; + }; + Cmds expected; + expected.del.Init(arraysize(ids), &ids[0]); + expected.data[0] = kRenderbuffersStartId; + expected.data[1] = kRenderbuffersStartId + 1; + gl_->DeleteRenderbuffers(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DeleteShader) { + struct Cmds { + DeleteShader cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->DeleteShader(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DeleteTextures) { + GLuint ids[2] = { kTexturesStartId, kTexturesStartId + 1 }; + struct Cmds { + DeleteTexturesImmediate del; + GLuint data[2]; + }; + Cmds expected; + expected.del.Init(arraysize(ids), &ids[0]); + expected.data[0] = kTexturesStartId; + expected.data[1] = kTexturesStartId + 1; + gl_->DeleteTextures(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DepthFunc) { + struct Cmds { + DepthFunc cmd; + }; + Cmds expected; + expected.cmd.Init(GL_NEVER); + + gl_->DepthFunc(GL_NEVER); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DepthMask) { + struct Cmds { + DepthMask cmd; + }; + Cmds expected; + expected.cmd.Init(true); + + gl_->DepthMask(true); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DepthRangef) { + struct Cmds { + DepthRangef cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->DepthRangef(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DetachShader) { + struct Cmds { + DetachShader cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->DetachShader(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Disable) { + struct Cmds { + Disable cmd; + }; + Cmds expected; + expected.cmd.Init(GL_BLEND); + + gl_->Disable(GL_BLEND); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DisableVertexAttribArray) { + struct Cmds { + DisableVertexAttribArray cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->DisableVertexAttribArray(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, DrawArrays) { + struct Cmds { + DrawArrays cmd; + }; + Cmds expected; + expected.cmd.Init(GL_POINTS, 2, 3); + + gl_->DrawArrays(GL_POINTS, 2, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Enable) { + struct Cmds { + Enable cmd; + }; + Cmds expected; + expected.cmd.Init(GL_BLEND); + + gl_->Enable(GL_BLEND); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, EnableVertexAttribArray) { + struct Cmds { + EnableVertexAttribArray cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->EnableVertexAttribArray(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Flush) { + struct Cmds { + Flush cmd; + }; + Cmds expected; + expected.cmd.Init(); + + gl_->Flush(); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, FramebufferRenderbuffer) { + struct Cmds { + FramebufferRenderbuffer cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 4); + + gl_->FramebufferRenderbuffer( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, FramebufferTexture2D) { + struct Cmds { + FramebufferTexture2D cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 4, 0); + + gl_->FramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 4, 0); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, FrontFace) { + struct Cmds { + FrontFace cmd; + }; + Cmds expected; + expected.cmd.Init(GL_CW); + + gl_->FrontFace(GL_CW); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, GenBuffers) { + GLuint ids[2] = { 0, }; + struct Cmds { + GenBuffersImmediate gen; + GLuint data[2]; + }; + Cmds expected; + expected.gen.Init(arraysize(ids), &ids[0]); + expected.data[0] = kBuffersStartId; + expected.data[1] = kBuffersStartId + 1; + gl_->GenBuffers(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(kBuffersStartId, ids[0]); + EXPECT_EQ(kBuffersStartId + 1, ids[1]); +} + +TEST_F(GLES2ImplementationTest, GenerateMipmap) { + struct Cmds { + GenerateMipmap cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D); + + gl_->GenerateMipmap(GL_TEXTURE_2D); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, GenFramebuffers) { + GLuint ids[2] = { 0, }; + struct Cmds { + GenFramebuffersImmediate gen; + GLuint data[2]; + }; + Cmds expected; + expected.gen.Init(arraysize(ids), &ids[0]); + expected.data[0] = kFramebuffersStartId; + expected.data[1] = kFramebuffersStartId + 1; + gl_->GenFramebuffers(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(kFramebuffersStartId, ids[0]); + EXPECT_EQ(kFramebuffersStartId + 1, ids[1]); +} + +TEST_F(GLES2ImplementationTest, GenRenderbuffers) { + GLuint ids[2] = { 0, }; + struct Cmds { + GenRenderbuffersImmediate gen; + GLuint data[2]; + }; + Cmds expected; + expected.gen.Init(arraysize(ids), &ids[0]); + expected.data[0] = kRenderbuffersStartId; + expected.data[1] = kRenderbuffersStartId + 1; + gl_->GenRenderbuffers(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(kRenderbuffersStartId, ids[0]); + EXPECT_EQ(kRenderbuffersStartId + 1, ids[1]); +} + +TEST_F(GLES2ImplementationTest, GenTextures) { + GLuint ids[2] = { 0, }; + struct Cmds { + GenTexturesImmediate gen; + GLuint data[2]; + }; + Cmds expected; + expected.gen.Init(arraysize(ids), &ids[0]); + expected.data[0] = kTexturesStartId; + expected.data[1] = kTexturesStartId + 1; + gl_->GenTextures(arraysize(ids), &ids[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(kTexturesStartId, ids[0]); + EXPECT_EQ(kTexturesStartId + 1, ids[1]); +} +// TODO: Implement unit test for GetActiveAttrib +// TODO: Implement unit test for GetActiveUniform +// TODO: Implement unit test for GetAttachedShaders +// TODO: Implement unit test for GetAttribLocation + +TEST_F(GLES2ImplementationTest, GetBooleanv) { + struct Cmds { + GetBooleanv cmd; + }; + typedef GetBooleanv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetBooleanv(123, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetBufferParameteriv) { + struct Cmds { + GetBufferParameteriv cmd; + }; + typedef GetBufferParameteriv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, GL_BUFFER_SIZE, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetBufferParameteriv(123, GL_BUFFER_SIZE, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetFloatv) { + struct Cmds { + GetFloatv cmd; + }; + typedef GetFloatv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetFloatv(123, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetFramebufferAttachmentParameteriv) { + struct Cmds { + GetFramebufferAttachmentParameteriv cmd; + }; + typedef GetFramebufferAttachmentParameteriv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init( + 123, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, + transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetFramebufferAttachmentParameteriv( + 123, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, + &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetIntegerv) { + struct Cmds { + GetIntegerv cmd; + }; + typedef GetIntegerv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetIntegerv(123, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetProgramiv) { + struct Cmds { + GetProgramiv cmd; + }; + typedef GetProgramiv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, GL_DELETE_STATUS, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetProgramiv(123, GL_DELETE_STATUS, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} +// TODO: Implement unit test for GetProgramInfoLog + +TEST_F(GLES2ImplementationTest, GetRenderbufferParameteriv) { + struct Cmds { + GetRenderbufferParameteriv cmd; + }; + typedef GetRenderbufferParameteriv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, GL_RENDERBUFFER_RED_SIZE, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetRenderbufferParameteriv(123, GL_RENDERBUFFER_RED_SIZE, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetShaderiv) { + struct Cmds { + GetShaderiv cmd; + }; + typedef GetShaderiv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, GL_SHADER_TYPE, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetShaderiv(123, GL_SHADER_TYPE, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} +// TODO: Implement unit test for GetShaderInfoLog +// TODO: Implement unit test for GetShaderPrecisionFormat + +TEST_F(GLES2ImplementationTest, GetTexParameterfv) { + struct Cmds { + GetTexParameterfv cmd; + }; + typedef GetTexParameterfv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, GL_TEXTURE_MAG_FILTER, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetTexParameterfv(123, GL_TEXTURE_MAG_FILTER, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetTexParameteriv) { + struct Cmds { + GetTexParameteriv cmd; + }; + typedef GetTexParameteriv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init(123, GL_TEXTURE_MAG_FILTER, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetTexParameteriv(123, GL_TEXTURE_MAG_FILTER, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} +// TODO: Implement unit test for GetUniformfv +// TODO: Implement unit test for GetUniformiv +// TODO: Implement unit test for GetUniformLocation + +TEST_F(GLES2ImplementationTest, GetVertexAttribfv) { + struct Cmds { + GetVertexAttribfv cmd; + }; + typedef GetVertexAttribfv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init( + 123, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetVertexAttribfv(123, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, GetVertexAttribiv) { + struct Cmds { + GetVertexAttribiv cmd; + }; + typedef GetVertexAttribiv::Result Result; + Result::Type result = 0; + Cmds expected; + expected.cmd.Init( + 123, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, transfer_buffer_id_, 0); + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(SizedResultHelper<Result::Type>(1))) + .RetiresOnSaturation(); + gl_->GetVertexAttribiv(123, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &result); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_EQ(static_cast<Result::Type>(1), result); +} + +TEST_F(GLES2ImplementationTest, Hint) { + struct Cmds { + Hint cmd; + }; + Cmds expected; + expected.cmd.Init(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); + + gl_->Hint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, IsBuffer) { + struct Cmds { + IsBuffer cmd; + }; + + typedef IsBuffer::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsBuffer(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, IsEnabled) { + struct Cmds { + IsEnabled cmd; + }; + + typedef IsEnabled::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsEnabled(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, IsFramebuffer) { + struct Cmds { + IsFramebuffer cmd; + }; + + typedef IsFramebuffer::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsFramebuffer(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, IsProgram) { + struct Cmds { + IsProgram cmd; + }; + + typedef IsProgram::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsProgram(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, IsRenderbuffer) { + struct Cmds { + IsRenderbuffer cmd; + }; + + typedef IsRenderbuffer::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsRenderbuffer(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, IsShader) { + struct Cmds { + IsShader cmd; + }; + + typedef IsShader::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsShader(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, IsTexture) { + struct Cmds { + IsTexture cmd; + }; + + typedef IsTexture::Result Result; + Cmds expected; + expected.cmd.Init(1, transfer_buffer_id_, 0); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(1))) + .RetiresOnSaturation(); + + GLboolean result = gl_->IsTexture(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); + EXPECT_TRUE(result); +} + +TEST_F(GLES2ImplementationTest, LineWidth) { + struct Cmds { + LineWidth cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->LineWidth(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, LinkProgram) { + struct Cmds { + LinkProgram cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->LinkProgram(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, PixelStorei) { + struct Cmds { + PixelStorei cmd; + }; + Cmds expected; + expected.cmd.Init(GL_PACK_ALIGNMENT, 1); + + gl_->PixelStorei(GL_PACK_ALIGNMENT, 1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, PolygonOffset) { + struct Cmds { + PolygonOffset cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->PolygonOffset(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, ReleaseShaderCompiler) { + struct Cmds { + ReleaseShaderCompiler cmd; + }; + Cmds expected; + expected.cmd.Init(); + + gl_->ReleaseShaderCompiler(); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, RenderbufferStorage) { + struct Cmds { + RenderbufferStorage cmd; + }; + Cmds expected; + expected.cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 3, 4); + + gl_->RenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, SampleCoverage) { + struct Cmds { + SampleCoverage cmd; + }; + Cmds expected; + expected.cmd.Init(1, true); + + gl_->SampleCoverage(1, true); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Scissor) { + struct Cmds { + Scissor cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->Scissor(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, StencilFunc) { + struct Cmds { + StencilFunc cmd; + }; + Cmds expected; + expected.cmd.Init(GL_NEVER, 2, 3); + + gl_->StencilFunc(GL_NEVER, 2, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, StencilFuncSeparate) { + struct Cmds { + StencilFuncSeparate cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRONT, GL_NEVER, 3, 4); + + gl_->StencilFuncSeparate(GL_FRONT, GL_NEVER, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, StencilMask) { + struct Cmds { + StencilMask cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->StencilMask(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, StencilMaskSeparate) { + struct Cmds { + StencilMaskSeparate cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRONT, 2); + + gl_->StencilMaskSeparate(GL_FRONT, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, StencilOp) { + struct Cmds { + StencilOp cmd; + }; + Cmds expected; + expected.cmd.Init(GL_KEEP, GL_KEEP, GL_KEEP); + + gl_->StencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, StencilOpSeparate) { + struct Cmds { + StencilOpSeparate cmd; + }; + Cmds expected; + expected.cmd.Init(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP); + + gl_->StencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, TexParameterf) { + struct Cmds { + TexParameterf cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 3); + + gl_->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, TexParameterfv) { + struct Cmds { + TexParameterfvImmediate cmd; + GLfloat data[1]; + }; + + Cmds expected; + for (int jj = 0; jj < 1; ++jj) { + expected.data[jj] = static_cast<GLfloat>(jj); + } + expected.cmd.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &expected.data[0]); + gl_->TexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, TexParameteri) { + struct Cmds { + TexParameteri cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 3); + + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, TexParameteriv) { + struct Cmds { + TexParameterivImmediate cmd; + GLint data[1]; + }; + + Cmds expected; + for (int jj = 0; jj < 1; ++jj) { + expected.data[jj] = static_cast<GLint>(jj); + } + expected.cmd.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &expected.data[0]); + gl_->TexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform1f) { + struct Cmds { + Uniform1f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->Uniform1f(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform1fv) { + struct Cmds { + Uniform1fvImmediate cmd; + GLfloat data[2][1]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 1; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 1 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform1fv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform1i) { + struct Cmds { + Uniform1i cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->Uniform1i(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform1iv) { + struct Cmds { + Uniform1ivImmediate cmd; + GLint data[2][1]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 1; ++jj) { + expected.data[ii][jj] = static_cast<GLint>(ii * 1 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform1iv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform2f) { + struct Cmds { + Uniform2f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3); + + gl_->Uniform2f(1, 2, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform2fv) { + struct Cmds { + Uniform2fvImmediate cmd; + GLfloat data[2][2]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 2; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 2 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform2fv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform2i) { + struct Cmds { + Uniform2i cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3); + + gl_->Uniform2i(1, 2, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform2iv) { + struct Cmds { + Uniform2ivImmediate cmd; + GLint data[2][2]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 2; ++jj) { + expected.data[ii][jj] = static_cast<GLint>(ii * 2 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform2iv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform3f) { + struct Cmds { + Uniform3f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->Uniform3f(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform3fv) { + struct Cmds { + Uniform3fvImmediate cmd; + GLfloat data[2][3]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 3; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 3 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform3fv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform3i) { + struct Cmds { + Uniform3i cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->Uniform3i(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform3iv) { + struct Cmds { + Uniform3ivImmediate cmd; + GLint data[2][3]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 3; ++jj) { + expected.data[ii][jj] = static_cast<GLint>(ii * 3 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform3iv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform4f) { + struct Cmds { + Uniform4f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4, 5); + + gl_->Uniform4f(1, 2, 3, 4, 5); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform4fv) { + struct Cmds { + Uniform4fvImmediate cmd; + GLfloat data[2][4]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 4; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 4 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform4fv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform4i) { + struct Cmds { + Uniform4i cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4, 5); + + gl_->Uniform4i(1, 2, 3, 4, 5); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Uniform4iv) { + struct Cmds { + Uniform4ivImmediate cmd; + GLint data[2][4]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 4; ++jj) { + expected.data[ii][jj] = static_cast<GLint>(ii * 4 + jj); + } + } + expected.cmd.Init(1, 2, &expected.data[0][0]); + gl_->Uniform4iv(1, 2, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, UniformMatrix2fv) { + struct Cmds { + UniformMatrix2fvImmediate cmd; + GLfloat data[2][4]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 4; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 4 + jj); + } + } + expected.cmd.Init(1, 2, false, &expected.data[0][0]); + gl_->UniformMatrix2fv(1, 2, false, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, UniformMatrix3fv) { + struct Cmds { + UniformMatrix3fvImmediate cmd; + GLfloat data[2][9]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 9; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 9 + jj); + } + } + expected.cmd.Init(1, 2, false, &expected.data[0][0]); + gl_->UniformMatrix3fv(1, 2, false, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, UniformMatrix4fv) { + struct Cmds { + UniformMatrix4fvImmediate cmd; + GLfloat data[2][16]; + }; + + Cmds expected; + for (int ii = 0; ii < 2; ++ii) { + for (int jj = 0; jj < 16; ++jj) { + expected.data[ii][jj] = static_cast<GLfloat>(ii * 16 + jj); + } + } + expected.cmd.Init(1, 2, false, &expected.data[0][0]); + gl_->UniformMatrix4fv(1, 2, false, &expected.data[0][0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, UseProgram) { + struct Cmds { + UseProgram cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->UseProgram(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, ValidateProgram) { + struct Cmds { + ValidateProgram cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->ValidateProgram(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib1f) { + struct Cmds { + VertexAttrib1f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->VertexAttrib1f(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib1fv) { + struct Cmds { + VertexAttrib1fvImmediate cmd; + GLfloat data[1]; + }; + + Cmds expected; + for (int jj = 0; jj < 1; ++jj) { + expected.data[jj] = static_cast<GLfloat>(jj); + } + expected.cmd.Init(1, &expected.data[0]); + gl_->VertexAttrib1fv(1, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib2f) { + struct Cmds { + VertexAttrib2f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3); + + gl_->VertexAttrib2f(1, 2, 3); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib2fv) { + struct Cmds { + VertexAttrib2fvImmediate cmd; + GLfloat data[2]; + }; + + Cmds expected; + for (int jj = 0; jj < 2; ++jj) { + expected.data[jj] = static_cast<GLfloat>(jj); + } + expected.cmd.Init(1, &expected.data[0]); + gl_->VertexAttrib2fv(1, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib3f) { + struct Cmds { + VertexAttrib3f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->VertexAttrib3f(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib3fv) { + struct Cmds { + VertexAttrib3fvImmediate cmd; + GLfloat data[3]; + }; + + Cmds expected; + for (int jj = 0; jj < 3; ++jj) { + expected.data[jj] = static_cast<GLfloat>(jj); + } + expected.cmd.Init(1, &expected.data[0]); + gl_->VertexAttrib3fv(1, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib4f) { + struct Cmds { + VertexAttrib4f cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4, 5); + + gl_->VertexAttrib4f(1, 2, 3, 4, 5); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, VertexAttrib4fv) { + struct Cmds { + VertexAttrib4fvImmediate cmd; + GLfloat data[4]; + }; + + Cmds expected; + for (int jj = 0; jj < 4; ++jj) { + expected.data[jj] = static_cast<GLfloat>(jj); + } + expected.cmd.Init(1, &expected.data[0]); + gl_->VertexAttrib4fv(1, &expected.data[0]); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, Viewport) { + struct Cmds { + Viewport cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4); + + gl_->Viewport(1, 2, 3, 4); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, BlitFramebufferEXT) { + struct Cmds { + BlitFramebufferEXT cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2, 3, 4, 5, 6, 7, 8, 9, GL_NEAREST); + + gl_->BlitFramebufferEXT(1, 2, 3, 4, 5, 6, 7, 8, 9, GL_NEAREST); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, RenderbufferStorageMultisampleEXT) { + struct Cmds { + RenderbufferStorageMultisampleEXT cmd; + }; + Cmds expected; + expected.cmd.Init(GL_RENDERBUFFER, 2, GL_RGBA4, 4, 5); + + gl_->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 2, GL_RGBA4, 4, 5); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} + +TEST_F(GLES2ImplementationTest, TexStorage2DEXT) { + struct Cmds { + TexStorage2DEXT cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, 2, GL_RGB565, 4, 5); + + gl_->TexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGB565, 4, 5); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +// TODO: Implement unit test for GenSharedIdsCHROMIUM +// TODO: Implement unit test for DeleteSharedIdsCHROMIUM +// TODO: Implement unit test for RegisterSharedIdsCHROMIUM +// TODO: Implement unit test for EnableFeatureCHROMIUM + +TEST_F(GLES2ImplementationTest, ResizeCHROMIUM) { + struct Cmds { + ResizeCHROMIUM cmd; + }; + Cmds expected; + expected.cmd.Init(1, 2); + + gl_->ResizeCHROMIUM(1, 2); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +// TODO: Implement unit test for GetRequestableExtensionsCHROMIUM + +TEST_F(GLES2ImplementationTest, DestroyStreamTextureCHROMIUM) { + struct Cmds { + DestroyStreamTextureCHROMIUM cmd; + }; + Cmds expected; + expected.cmd.Init(1); + + gl_->DestroyStreamTextureCHROMIUM(1); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +// TODO: Implement unit test for GetTranslatedShaderSourceANGLE + +TEST_F(GLES2ImplementationTest, TexImageIOSurface2DCHROMIUM) { + struct Cmds { + TexImageIOSurface2DCHROMIUM cmd; + }; + Cmds expected; + expected.cmd.Init(GL_TEXTURE_2D, 2, 3, 4, 5); + + gl_->TexImageIOSurface2DCHROMIUM(GL_TEXTURE_2D, 2, 3, 4, 5); + EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); +} +#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_UNITTEST_AUTOGEN_H_ + diff --git a/gpu/command_buffer/common/gles2_cmd_format.h b/gpu/command_buffer/common/gles2_cmd_format.h index f1a0167..439ea71 100644 --- a/gpu/command_buffer/common/gles2_cmd_format.h +++ b/gpu/command_buffer/common/gles2_cmd_format.h @@ -70,6 +70,8 @@ COMPILE_ASSERT(kTextures == 4, kTextures_is_not_4); // the command failed its result size will 0. template <typename T> struct SizedResult { + typedef T Type; + T* GetData() { return static_cast<T*>(static_cast<void*>(&data)); } |