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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 'arguments': 'GLuint array', | 754 'arguments': 'GLuint array', |
755 'other_extensions': ['OES_vertex_array_object', | 755 'other_extensions': ['OES_vertex_array_object', |
756 'APPLE_vertex_array_object', | 756 'APPLE_vertex_array_object', |
757 'ARB_vertex_array_object'] }, | 757 'ARB_vertex_array_object'] }, |
758 { 'return_type': 'void', | 758 { 'return_type': 'void', |
759 'names': ['glDiscardFramebufferEXT', 'glInvalidateFramebuffer'], | 759 'names': ['glDiscardFramebufferEXT', 'glInvalidateFramebuffer'], |
760 'arguments': 'GLenum target, GLsizei numAttachments, ' | 760 'arguments': 'GLenum target, GLsizei numAttachments, ' |
761 'const GLenum* attachments' }, | 761 'const GLenum* attachments' }, |
762 ] | 762 ] |
763 | 763 |
| 764 GL_NULLDRAW_FUNCTIONS = [ |
| 765 { 'return_type': 'void', |
| 766 'names': ['glClear'], |
| 767 'arguments': 'GLbitfield mask', }, |
| 768 { 'return_type': 'void', |
| 769 'names': ['glDrawArrays'], |
| 770 'arguments': 'GLenum mode, GLint first, GLsizei count', }, |
| 771 { 'return_type': 'void', |
| 772 'names': ['glDrawElements'], |
| 773 'arguments': |
| 774 'GLenum mode, GLsizei count, GLenum type, const void* indices', }, |
| 775 ] |
| 776 |
764 OSMESA_FUNCTIONS = [ | 777 OSMESA_FUNCTIONS = [ |
765 { 'return_type': 'OSMesaContext', | 778 { 'return_type': 'OSMesaContext', |
766 'names': ['OSMesaCreateContext'], | 779 'names': ['OSMesaCreateContext'], |
767 'arguments': 'GLenum format, OSMesaContext sharelist', }, | 780 'arguments': 'GLenum format, OSMesaContext sharelist', }, |
768 { 'return_type': 'OSMesaContext', | 781 { 'return_type': 'OSMesaContext', |
769 'names': ['OSMesaCreateContextExt'], | 782 'names': ['OSMesaCreateContextExt'], |
770 'arguments': | 783 'arguments': |
771 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' | 784 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' |
772 'OSMesaContext sharelist', }, | 785 'OSMesaContext sharelist', }, |
773 { 'return_type': 'void', | 786 { 'return_type': 'void', |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' | 1197 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' |
1185 'int64* sbc' }, | 1198 'int64* sbc' }, |
1186 { 'return_type': 'bool', | 1199 { 'return_type': 'bool', |
1187 'names': ['glXGetMscRateOML'], | 1200 'names': ['glXGetMscRateOML'], |
1188 'arguments': | 1201 'arguments': |
1189 'Display* dpy, GLXDrawable drawable, int32* numerator, ' | 1202 'Display* dpy, GLXDrawable drawable, int32* numerator, ' |
1190 'int32* denominator' }, | 1203 'int32* denominator' }, |
1191 ] | 1204 ] |
1192 | 1205 |
1193 FUNCTION_SETS = [ | 1206 FUNCTION_SETS = [ |
1194 [GL_FUNCTIONS, 'gl', [ | 1207 [GL_FUNCTIONS, GL_NULLDRAW_FUNCTIONS, 'gl', [ |
1195 'GL/glext.h', | 1208 'GL/glext.h', |
1196 'GLES2/gl2ext.h', | 1209 'GLES2/gl2ext.h', |
1197 # Files below are Chromium-specific and shipped with Chromium sources. | 1210 # Files below are Chromium-specific and shipped with Chromium sources. |
1198 'GL/glextchromium.h', | 1211 'GL/glextchromium.h', |
1199 'GLES2/gl2chromium.h', | 1212 'GLES2/gl2chromium.h', |
1200 'GLES2/gl2extchromium.h' | 1213 'GLES2/gl2extchromium.h' |
1201 ], []], | 1214 ], []], |
1202 [OSMESA_FUNCTIONS, 'osmesa', [], []], | 1215 [OSMESA_FUNCTIONS, [], 'osmesa', [], []], |
1203 [EGL_FUNCTIONS, 'egl', [ | 1216 [EGL_FUNCTIONS, [], 'egl', [ |
1204 'EGL/eglext.h', | 1217 'EGL/eglext.h', |
1205 # Files below are Chromium-specific and shipped with Chromium sources. | 1218 # Files below are Chromium-specific and shipped with Chromium sources. |
1206 'EGL/eglextchromium.h', | 1219 'EGL/eglextchromium.h', |
1207 ], | 1220 ], |
1208 [ | 1221 [ |
1209 'EGL_ANGLE_d3d_share_handle_client_buffer', | 1222 'EGL_ANGLE_d3d_share_handle_client_buffer', |
1210 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', | 1223 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', |
1211 ], | 1224 ], |
1212 ], | 1225 ], |
1213 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []], | 1226 [WGL_FUNCTIONS, [], 'wgl', ['GL/wglext.h'], []], |
1214 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []], | 1227 [GLX_FUNCTIONS, [], 'glx', ['GL/glx.h', 'GL/glxext.h'], []], |
1215 ] | 1228 ] |
1216 | 1229 |
1217 def GenerateHeader(file, functions, set_name, used_extension_functions): | 1230 def GenerateHeader(file, functions, set_name, used_extension_functions): |
1218 """Generates gl_bindings_autogen_x.h""" | 1231 """Generates gl_bindings_autogen_x.h""" |
1219 | 1232 |
1220 # Write file header. | 1233 # Write file header. |
1221 file.write( | 1234 file.write( |
1222 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1235 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1223 // Use of this source code is governed by a BSD-style license that can be | 1236 // Use of this source code is governed by a BSD-style license that can be |
1224 // found in the LICENSE file. | 1237 // found in the LICENSE file. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 for func in functions: | 1363 for func in functions: |
1351 args = func['arguments'] | 1364 args = func['arguments'] |
1352 if args == 'void': | 1365 if args == 'void': |
1353 args = '' | 1366 args = '' |
1354 file.write(' virtual %s %s(%s) = 0;\n' % | 1367 file.write(' virtual %s %s(%s) = 0;\n' % |
1355 (func['return_type'], func['names'][0][2:], args)) | 1368 (func['return_type'], func['names'][0][2:], args)) |
1356 | 1369 |
1357 file.write('\n') | 1370 file.write('\n') |
1358 | 1371 |
1359 | 1372 |
1360 def GenerateSource(file, functions, set_name, used_extension_functions): | 1373 def GenerateSource( |
| 1374 file, functions, nulldraw_functions, set_name, used_extension_functions): |
1361 """Generates gl_bindings_autogen_x.cc""" | 1375 """Generates gl_bindings_autogen_x.cc""" |
1362 | 1376 |
1363 # Write file header. | 1377 # Write file header. |
1364 file.write( | 1378 file.write( |
1365 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1379 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
1366 // Use of this source code is governed by a BSD-style license that can be | 1380 // Use of this source code is governed by a BSD-style license that can be |
1367 // found in the LICENSE file. | 1381 // found in the LICENSE file. |
1368 | 1382 |
1369 // This file is automatically generated. | 1383 // This file is automatically generated. |
1370 | 1384 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 file.write( | 1440 file.write( |
1427 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % | 1441 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % |
1428 (entry_point_name, entry_point_name, function_name)) | 1442 (entry_point_name, entry_point_name, function_name)) |
1429 queried_entry_points.add(entry_point_name) | 1443 queried_entry_points.add(entry_point_name) |
1430 file.write(' }\n') | 1444 file.write(' }\n') |
1431 file.write(' if (g_debugBindingsInitialized)\n') | 1445 file.write(' if (g_debugBindingsInitialized)\n') |
1432 file.write(' UpdateDebugExtensionBindings();\n') | 1446 file.write(' UpdateDebugExtensionBindings();\n') |
1433 file.write('}\n') | 1447 file.write('}\n') |
1434 file.write('\n') | 1448 file.write('\n') |
1435 | 1449 |
| 1450 # Write empty stubs for functions that want one. |
| 1451 file.write('extern "C" {\n') |
| 1452 for func in nulldraw_functions: |
| 1453 names = func['names'] |
| 1454 return_type = func['return_type'] |
| 1455 arguments = func['arguments'] |
| 1456 file.write('\n') |
| 1457 file.write('static %s GL_BINDING_CALL Stub_%s(%s) {}\n' % |
| 1458 (return_type, names[0], arguments)) |
| 1459 file.write('} // extern "C"\n') |
| 1460 |
1436 # Write logging wrappers for each function. | 1461 # Write logging wrappers for each function. |
1437 file.write('extern "C" {\n') | 1462 file.write('extern "C" {\n') |
1438 for func in functions: | 1463 for func in functions: |
1439 names = func['names'] | 1464 names = func['names'] |
1440 return_type = func['return_type'] | 1465 return_type = func['return_type'] |
1441 arguments = func['arguments'] | 1466 arguments = func['arguments'] |
1442 file.write('\n') | 1467 file.write('\n') |
1443 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % | 1468 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % |
1444 (return_type, names[0], arguments)) | 1469 (return_type, names[0], arguments)) |
1445 argument_names = re.sub( | 1470 argument_names = re.sub( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 set_name.upper()) | 1530 set_name.upper()) |
1506 for func in functions: | 1531 for func in functions: |
1507 first_name = func['names'][0] | 1532 first_name = func['names'][0] |
1508 file.write(' if (!debug_fn.%sFn) {\n' % first_name) | 1533 file.write(' if (!debug_fn.%sFn) {\n' % first_name) |
1509 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) | 1534 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) |
1510 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) | 1535 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) |
1511 file.write(' }\n') | 1536 file.write(' }\n') |
1512 file.write(' g_debugBindingsInitialized = true;\n') | 1537 file.write(' g_debugBindingsInitialized = true;\n') |
1513 file.write('}\n') | 1538 file.write('}\n') |
1514 | 1539 |
| 1540 # Write function to initialize the nulldraw function pointers. |
| 1541 if nulldraw_functions: |
| 1542 file.write('\n') |
| 1543 file.write('void Driver%s::InitializeNullDrawBindings() {\n' % |
| 1544 set_name.upper()) |
| 1545 |
| 1546 for func in nulldraw_functions: |
| 1547 first_name = func['names'][0] |
| 1548 file.write(' fn.%sFn = Stub_%s;\n' % (first_name, first_name)) |
| 1549 file.write('}\n') |
| 1550 |
1515 # Write function to update the debug function pointers to extension functions | 1551 # Write function to update the debug function pointers to extension functions |
1516 # after the extensions have been initialized. | 1552 # after the extensions have been initialized. |
1517 file.write('\n') | 1553 file.write('\n') |
1518 file.write('void Driver%s::UpdateDebugExtensionBindings() {\n' % | 1554 file.write('void Driver%s::UpdateDebugExtensionBindings() {\n' % |
1519 set_name.upper()) | 1555 set_name.upper()) |
1520 for extension, ext_functions in used_extension_functions: | 1556 for extension, ext_functions in used_extension_functions: |
1521 for name, _ in ext_functions: | 1557 for name, _ in ext_functions: |
1522 file.write(' if (debug_fn.%sFn != fn.%sFn &&\n' % (name, name)) | 1558 file.write(' if (debug_fn.%sFn != fn.%sFn &&\n' % (name, name)) |
1523 file.write(' fn.%sFn != Debug_%s) {\n' % (name, name)) | 1559 file.write(' fn.%sFn != Debug_%s) {\n' % (name, name)) |
1524 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (name, name)) | 1560 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (name, name)) |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 def main(argv): | 1825 def main(argv): |
1790 """This is the main function.""" | 1826 """This is the main function.""" |
1791 | 1827 |
1792 parser = optparse.OptionParser() | 1828 parser = optparse.OptionParser() |
1793 parser.add_option('--inputs', action='store_true') | 1829 parser.add_option('--inputs', action='store_true') |
1794 parser.add_option('--header-paths') | 1830 parser.add_option('--header-paths') |
1795 | 1831 |
1796 options, args = parser.parse_args(argv) | 1832 options, args = parser.parse_args(argv) |
1797 | 1833 |
1798 if options.inputs: | 1834 if options.inputs: |
1799 for [_, _, headers, _] in FUNCTION_SETS: | 1835 for [_, _, _, headers, _] in FUNCTION_SETS: |
1800 for header in headers: | 1836 for header in headers: |
1801 print ResolveHeader(header, options.header_paths) | 1837 print ResolveHeader(header, options.header_paths) |
1802 return 0 | 1838 return 0 |
1803 | 1839 |
1804 if len(args) >= 1: | 1840 if len(args) >= 1: |
1805 dir = args[0] | 1841 dir = args[0] |
1806 else: | 1842 else: |
1807 dir = '.' | 1843 dir = '.' |
1808 | 1844 |
1809 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: | 1845 for [functions, |
| 1846 nulldraw_functions, |
| 1847 set_name, |
| 1848 extension_headers, |
| 1849 extensions] in FUNCTION_SETS: |
1810 extension_headers = [ResolveHeader(h, options.header_paths) | 1850 extension_headers = [ResolveHeader(h, options.header_paths) |
1811 for h in extension_headers] | 1851 for h in extension_headers] |
1812 used_extension_functions = GetUsedExtensionFunctions( | 1852 used_extension_functions = GetUsedExtensionFunctions( |
1813 functions, extension_headers, extensions) | 1853 functions, extension_headers, extensions) |
1814 | 1854 |
1815 header_file = open( | 1855 header_file = open( |
1816 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | 1856 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') |
1817 GenerateHeader(header_file, functions, set_name, used_extension_functions) | 1857 GenerateHeader(header_file, functions, set_name, used_extension_functions) |
1818 header_file.close() | 1858 header_file.close() |
1819 | 1859 |
1820 header_file = open( | 1860 header_file = open( |
1821 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') | 1861 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') |
1822 GenerateAPIHeader( | 1862 GenerateAPIHeader( |
1823 header_file, functions, set_name, used_extension_functions) | 1863 header_file, functions, set_name, used_extension_functions) |
1824 header_file.close() | 1864 header_file.close() |
1825 | 1865 |
1826 source_file = open( | 1866 source_file = open( |
1827 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | 1867 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') |
1828 GenerateSource(source_file, functions, set_name, used_extension_functions) | 1868 GenerateSource(source_file, |
| 1869 functions, |
| 1870 nulldraw_functions, |
| 1871 set_name, |
| 1872 used_extension_functions) |
1829 source_file.close() | 1873 source_file.close() |
1830 | 1874 |
1831 header_file = open( | 1875 header_file = open( |
1832 os.path.join(dir, 'gl_interface_autogen_%s.h' % set_name), 'wb') | 1876 os.path.join(dir, 'gl_interface_autogen_%s.h' % set_name), 'wb') |
1833 GenerateInterfaceHeader( | 1877 GenerateInterfaceHeader( |
1834 header_file, functions, set_name, used_extension_functions) | 1878 header_file, functions, set_name, used_extension_functions) |
1835 header_file.close() | 1879 header_file.close() |
1836 | 1880 |
1837 header_file = open( | 1881 header_file = open( |
1838 os.path.join(dir, 'gl_mock_autogen_%s.h' % set_name), 'wb') | 1882 os.path.join(dir, 'gl_mock_autogen_%s.h' % set_name), 'wb') |
1839 GenerateMockHeader( | 1883 GenerateMockHeader( |
1840 header_file, functions, set_name, used_extension_functions) | 1884 header_file, functions, set_name, used_extension_functions) |
1841 header_file.close() | 1885 header_file.close() |
1842 | 1886 |
1843 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 1887 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
1844 GenerateMockSource(source_file, GL_FUNCTIONS) | 1888 GenerateMockSource(source_file, GL_FUNCTIONS) |
1845 source_file.close() | 1889 source_file.close() |
1846 return 0 | 1890 return 0 |
1847 | 1891 |
1848 | 1892 |
1849 if __name__ == '__main__': | 1893 if __name__ == '__main__': |
1850 sys.exit(main(sys.argv[1:])) | 1894 sys.exit(main(sys.argv[1:])) |
OLD | NEW |