| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """code generator for GL/GLES extension wrangler.""" | 6 """code generator for GL/GLES extension wrangler.""" |
| 7 | 7 |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import collections | 10 import collections |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 'arguments': 'GLsync sync', }, | 748 'arguments': 'GLsync sync', }, |
| 749 { 'return_type': 'void', | 749 { 'return_type': 'void', |
| 750 'names': ['glGetSynciv'], | 750 'names': ['glGetSynciv'], |
| 751 'arguments': | 751 'arguments': |
| 752 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,' | 752 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,' |
| 753 'GLint* values', }, | 753 'GLint* values', }, |
| 754 { 'return_type': 'GLenum', | 754 { 'return_type': 'GLenum', |
| 755 'names': ['glClientWaitSync'], | 755 'names': ['glClientWaitSync'], |
| 756 'arguments': | 756 'arguments': |
| 757 'GLsync sync, GLbitfield flags, GLuint64 timeout', }, | 757 'GLsync sync, GLbitfield flags, GLuint64 timeout', }, |
| 758 { 'return_type': 'GLenum', |
| 759 'names': ['glWaitSync'], |
| 760 'arguments': |
| 761 'GLsync sync, GLbitfield flags, GLuint64 timeout', }, |
| 758 { 'return_type': 'void', | 762 { 'return_type': 'void', |
| 759 'known_as': 'glDrawArraysInstancedANGLE', | 763 'known_as': 'glDrawArraysInstancedANGLE', |
| 760 'names': ['glDrawArraysInstancedARB', 'glDrawArraysInstancedANGLE'], | 764 'names': ['glDrawArraysInstancedARB', 'glDrawArraysInstancedANGLE'], |
| 761 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', }, | 765 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', }, |
| 762 { 'return_type': 'void', | 766 { 'return_type': 'void', |
| 763 'known_as': 'glDrawElementsInstancedANGLE', | 767 'known_as': 'glDrawElementsInstancedANGLE', |
| 764 'names': ['glDrawElementsInstancedARB', 'glDrawElementsInstancedANGLE'], | 768 'names': ['glDrawElementsInstancedARB', 'glDrawElementsInstancedANGLE'], |
| 765 'arguments': | 769 'arguments': |
| 766 'GLenum mode, GLsizei count, GLenum type, const void* indices, ' | 770 'GLenum mode, GLsizei count, GLenum type, const void* indices, ' |
| 767 'GLsizei primcount', }, | 771 'GLsizei primcount', }, |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 """ % {'name': set_name.upper()}) | 1362 """ % {'name': set_name.upper()}) |
| 1359 | 1363 |
| 1360 # Write API declaration. | 1364 # Write API declaration. |
| 1361 for func in functions: | 1365 for func in functions: |
| 1362 file.write(' virtual %s %sFn(%s) OVERRIDE;\n' % | 1366 file.write(' virtual %s %sFn(%s) OVERRIDE;\n' % |
| 1363 (func['return_type'], func['known_as'], func['arguments'])) | 1367 (func['return_type'], func['known_as'], func['arguments'])) |
| 1364 | 1368 |
| 1365 file.write('\n') | 1369 file.write('\n') |
| 1366 | 1370 |
| 1367 | 1371 |
| 1372 def FixGLPrefix(func_name): |
| 1373 """Converts the gl/egl/wgl/glx function name into a suitable member function n
ame""" |
| 1374 if func_name.startswith('gl'): |
| 1375 return func_name[2:] |
| 1376 elif func_name.startswith('egl'): |
| 1377 return "EGL" + func_name[3:] |
| 1378 else: |
| 1379 assert False, "Unexpected: " + func_name |
| 1380 |
| 1368 def GenerateMockHeader(file, functions, set_name): | 1381 def GenerateMockHeader(file, functions, set_name): |
| 1369 """Generates gl_mock_autogen_x.h""" | 1382 """Generates gl_mock_autogen_x.h""" |
| 1370 | 1383 |
| 1371 # Write file header. | 1384 # Write file header. |
| 1372 file.write( | 1385 file.write( |
| 1373 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1386 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 1374 // Use of this source code is governed by a BSD-style license that can be | 1387 // Use of this source code is governed by a BSD-style license that can be |
| 1375 // found in the LICENSE file. | 1388 // found in the LICENSE file. |
| 1376 | 1389 |
| 1377 // This file is automatically generated. | 1390 // This file is automatically generated. |
| 1378 | 1391 |
| 1379 """ % {'name': set_name.upper()}) | 1392 """ % {'name': set_name.upper()}) |
| 1380 | 1393 |
| 1381 # Write API declaration. | 1394 # Write API declaration. |
| 1382 for func in functions: | 1395 for func in functions: |
| 1383 args = func['arguments'] | 1396 args = func['arguments'] |
| 1384 if args == 'void': | 1397 if args == 'void': |
| 1385 args = '' | 1398 args = '' |
| 1386 arg_count = 0 | 1399 arg_count = 0 |
| 1387 if len(args): | 1400 if len(args): |
| 1388 arg_count = func['arguments'].count(',') + 1 | 1401 arg_count = func['arguments'].count(',') + 1 |
| 1389 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % | 1402 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % |
| 1390 (arg_count, func['known_as'][2:], func['return_type'], args)) | 1403 (arg_count, FixGLPrefix(func['known_as']), func['return_type'], args)) |
| 1391 | 1404 |
| 1392 file.write('\n') | 1405 file.write('\n') |
| 1393 | 1406 |
| 1394 | 1407 |
| 1395 def GenerateSource(file, functions, set_name, used_extensions): | 1408 def GenerateSource(file, functions, set_name, used_extensions): |
| 1396 """Generates gl_bindings_autogen_x.cc""" | 1409 """Generates gl_bindings_autogen_x.cc""" |
| 1397 | 1410 |
| 1398 # Write file header. | 1411 # Write file header. |
| 1399 file.write( | 1412 file.write( |
| 1400 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1413 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 for key in sorted_function_names: | 1766 for key in sorted_function_names: |
| 1754 func = uniquely_named_functions[key] | 1767 func = uniquely_named_functions[key] |
| 1755 file.write('\n') | 1768 file.write('\n') |
| 1756 file.write('%s GL_BINDING_CALL MockGLInterface::Mock_%s(%s) {\n' % | 1769 file.write('%s GL_BINDING_CALL MockGLInterface::Mock_%s(%s) {\n' % |
| 1757 (func['return_type'], func['name'], func['arguments'])) | 1770 (func['return_type'], func['name'], func['arguments'])) |
| 1758 file.write(' MakeFunctionUnique("%s");\n' % func['name']) | 1771 file.write(' MakeFunctionUnique("%s");\n' % func['name']) |
| 1759 arg_re = r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0-9]+)' | 1772 arg_re = r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0-9]+)' |
| 1760 argument_names = re.sub(arg_re, r'\4', func['arguments']) | 1773 argument_names = re.sub(arg_re, r'\4', func['arguments']) |
| 1761 if argument_names == 'void': | 1774 if argument_names == 'void': |
| 1762 argument_names = '' | 1775 argument_names = '' |
| 1763 function_name = func['known_as'][2:] | 1776 function_name = FixGLPrefix(func['known_as']) |
| 1764 if func['return_type'] == 'void': | 1777 if func['return_type'] == 'void': |
| 1765 file.write(' interface_->%s(%s);\n' % | 1778 file.write(' interface_->%s(%s);\n' % |
| 1766 (function_name, argument_names)) | 1779 (function_name, argument_names)) |
| 1767 else: | 1780 else: |
| 1768 file.write(' return interface_->%s(%s);\n' % | 1781 file.write(' return interface_->%s(%s);\n' % |
| 1769 (function_name, argument_names)) | 1782 (function_name, argument_names)) |
| 1770 file.write('}\n') | 1783 file.write('}\n') |
| 1771 | 1784 |
| 1772 # Write an 'invalid' function to catch code calling through uninitialized | 1785 # Write an 'invalid' function to catch code calling through uninitialized |
| 1773 # function pointers or trying to interpret the return value of | 1786 # function pointers or trying to interpret the return value of |
| 1774 # GLProcAddress(). | 1787 # GLProcAddress(). |
| 1775 file.write('\n') | 1788 file.write('\n') |
| 1776 file.write('static void MockInvalidFunction() {\n') | 1789 file.write('static void MockInvalidFunction() {\n') |
| 1777 file.write(' NOTREACHED();\n') | 1790 file.write(' NOTREACHED();\n') |
| 1778 file.write('}\n') | 1791 file.write('}\n') |
| 1779 | 1792 |
| 1780 # Write a function to lookup a mock GL function based on its name. | 1793 # Write a function to lookup a mock GL function based on its name. |
| 1781 file.write('\n') | 1794 file.write('\n') |
| 1782 file.write('void* GL_BINDING_CALL ' + | 1795 file.write('void* GL_BINDING_CALL ' + |
| 1783 'MockGLInterface::GetGLProcAddress(const char* name) {\n') | 1796 'MockGLInterface::GetGLProcAddress(const char* name) {\n') |
| 1784 for key in sorted_function_names: | 1797 for key in sorted_function_names: |
| 1785 name = uniquely_named_functions[key]['name'] | 1798 name = uniquely_named_functions[key]['name'] |
| 1786 file.write(' if (strcmp(name, "%s") == 0)\n' % name) | 1799 file.write(' if (strcmp(name, "%s") == 0)\n' % name) |
| 1787 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % name) | 1800 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % name) |
| 1788 # Always return a non-NULL pointer like some EGL implementations do. | 1801 # Always return a non-NULL pointer like some EGL implementations do. |
| 1802 file.write(' NOTREACHED() << "GetGLProcAddr for: " << name;\n') |
| 1789 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n') | 1803 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n') |
| 1790 file.write('}\n') | 1804 file.write('}\n') |
| 1791 | 1805 |
| 1792 file.write('\n') | 1806 file.write('\n') |
| 1793 file.write('} // namespace gfx\n') | 1807 file.write('} // namespace gfx\n') |
| 1794 | 1808 |
| 1795 | 1809 |
| 1796 def ParseExtensionFunctionsFromHeader(header_file): | 1810 def ParseExtensionFunctionsFromHeader(header_file): |
| 1797 """Parse a C extension header file and return a map from extension names to | 1811 """Parse a C extension header file and return a map from extension names to |
| 1798 a list of functions. | 1812 a list of functions. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 source_file = open( | 2000 source_file = open( |
| 1987 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | 2001 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') |
| 1988 GenerateSource(source_file, functions, set_name, used_extensions) | 2002 GenerateSource(source_file, functions, set_name, used_extensions) |
| 1989 source_file.close() | 2003 source_file.close() |
| 1990 | 2004 |
| 1991 header_file = open( | 2005 header_file = open( |
| 1992 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb') | 2006 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb') |
| 1993 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl') | 2007 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl') |
| 1994 header_file.close() | 2008 header_file.close() |
| 1995 | 2009 |
| 2010 header_file = open( |
| 2011 os.path.join(directory, 'gl_mock_autogen_egl.h'), 'wb') |
| 2012 GenerateMockHeader(header_file, EGL_FUNCTIONS, 'egl') |
| 2013 header_file.close() |
| 2014 |
| 1996 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'), | 2015 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'), |
| 1997 'wb') | 2016 'wb') |
| 1998 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS) | 2017 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS + EGL_FUNCTIONS) |
| 1999 header_file.close() | 2018 header_file.close() |
| 2000 | 2019 |
| 2001 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), | 2020 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), |
| 2002 'wb') | 2021 'wb') |
| 2003 GenerateMockBindingsSource(source_file, GL_FUNCTIONS) | 2022 GenerateMockBindingsSource(source_file, GL_FUNCTIONS + EGL_FUNCTIONS) |
| 2004 source_file.close() | 2023 source_file.close() |
| 2005 return 0 | 2024 return 0 |
| 2006 | 2025 |
| 2007 | 2026 |
| 2008 if __name__ == '__main__': | 2027 if __name__ == '__main__': |
| 2009 sys.exit(main(sys.argv[1:])) | 2028 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |