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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 'known_as': 'glDiscardFramebufferEXT', | 814 'known_as': 'glDiscardFramebufferEXT', |
815 'versions': [{ 'name': 'glInvalidateFramebuffer', | 815 'versions': [{ 'name': 'glInvalidateFramebuffer', |
816 'gl_versions': ['es3'], | 816 'gl_versions': ['es3'], |
817 'extensions': [] }, | 817 'extensions': [] }, |
818 { 'name': 'glDiscardFramebufferEXT', | 818 { 'name': 'glDiscardFramebufferEXT', |
819 'gl_versions': ['es1', 'es2'] }], | 819 'gl_versions': ['es1', 'es2'] }], |
820 'arguments': 'GLenum target, GLsizei numAttachments, ' | 820 'arguments': 'GLenum target, GLsizei numAttachments, ' |
821 'const GLenum* attachments' }, | 821 'const GLenum* attachments' }, |
822 ] | 822 ] |
823 | 823 |
824 GL_NULLDRAW_FUNCTIONS = [ | |
825 { 'return_type': 'void', | |
826 'names': ['glClear'], | |
827 'arguments': 'GLbitfield mask', }, | |
828 { 'return_type': 'void', | |
829 'names': ['glDrawArrays'], | |
830 'arguments': 'GLenum mode, GLint first, GLsizei count', }, | |
831 { 'return_type': 'void', | |
832 'names': ['glDrawElements'], | |
833 'arguments': | |
834 'GLenum mode, GLsizei count, GLenum type, const void* indices', }, | |
835 ] | |
836 | |
837 OSMESA_FUNCTIONS = [ | 824 OSMESA_FUNCTIONS = [ |
838 { 'return_type': 'OSMesaContext', | 825 { 'return_type': 'OSMesaContext', |
839 'names': ['OSMesaCreateContext'], | 826 'names': ['OSMesaCreateContext'], |
840 'arguments': 'GLenum format, OSMesaContext sharelist', }, | 827 'arguments': 'GLenum format, OSMesaContext sharelist', }, |
841 { 'return_type': 'OSMesaContext', | 828 { 'return_type': 'OSMesaContext', |
842 'names': ['OSMesaCreateContextExt'], | 829 'names': ['OSMesaCreateContextExt'], |
843 'arguments': | 830 'arguments': |
844 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' | 831 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' |
845 'OSMesaContext sharelist', }, | 832 'OSMesaContext sharelist', }, |
846 { 'return_type': 'void', | 833 { 'return_type': 'void', |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' | 1244 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' |
1258 'int64* sbc' }, | 1245 'int64* sbc' }, |
1259 { 'return_type': 'bool', | 1246 { 'return_type': 'bool', |
1260 'names': ['glXGetMscRateOML'], | 1247 'names': ['glXGetMscRateOML'], |
1261 'arguments': | 1248 'arguments': |
1262 'Display* dpy, GLXDrawable drawable, int32* numerator, ' | 1249 'Display* dpy, GLXDrawable drawable, int32* numerator, ' |
1263 'int32* denominator' }, | 1250 'int32* denominator' }, |
1264 ] | 1251 ] |
1265 | 1252 |
1266 FUNCTION_SETS = [ | 1253 FUNCTION_SETS = [ |
1267 [GL_FUNCTIONS, GL_NULLDRAW_FUNCTIONS, 'gl', [ | 1254 [GL_FUNCTIONS, 'gl', [ |
1268 'GL/glext.h', | 1255 'GL/glext.h', |
1269 'GLES2/gl2ext.h', | 1256 'GLES2/gl2ext.h', |
1270 # Files below are Chromium-specific and shipped with Chromium sources. | 1257 # Files below are Chromium-specific and shipped with Chromium sources. |
1271 'GL/glextchromium.h', | 1258 'GL/glextchromium.h', |
1272 'GLES2/gl2chromium.h', | 1259 'GLES2/gl2chromium.h', |
1273 'GLES2/gl2extchromium.h' | 1260 'GLES2/gl2extchromium.h' |
1274 ], []], | 1261 ], []], |
1275 [OSMESA_FUNCTIONS, [], 'osmesa', [], []], | 1262 [OSMESA_FUNCTIONS, 'osmesa', [], []], |
1276 [EGL_FUNCTIONS, [], 'egl', [ | 1263 [EGL_FUNCTIONS, 'egl', [ |
1277 'EGL/eglext.h', | 1264 'EGL/eglext.h', |
1278 # Files below are Chromium-specific and shipped with Chromium sources. | 1265 # Files below are Chromium-specific and shipped with Chromium sources. |
1279 'EGL/eglextchromium.h', | 1266 'EGL/eglextchromium.h', |
1280 ], | 1267 ], |
1281 [ | 1268 [ |
1282 'EGL_ANGLE_d3d_share_handle_client_buffer', | 1269 'EGL_ANGLE_d3d_share_handle_client_buffer', |
1283 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', | 1270 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', |
1284 ], | 1271 ], |
1285 ], | 1272 ], |
1286 [WGL_FUNCTIONS, [], 'wgl', ['GL/wglext.h'], []], | 1273 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []], |
1287 [GLX_FUNCTIONS, [], 'glx', ['GL/glx.h', 'GL/glxext.h'], []], | 1274 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []], |
1288 ] | 1275 ] |
1289 | 1276 |
1290 def GenerateHeader(file, functions, set_name, used_extensions): | 1277 def GenerateHeader(file, functions, set_name, used_extensions): |
1291 """Generates gl_bindings_autogen_x.h""" | 1278 """Generates gl_bindings_autogen_x.h""" |
1292 | 1279 |
1293 # Write file header. | 1280 # Write file header. |
1294 file.write( | 1281 file.write( |
1295 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1282 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1296 // Use of this source code is governed by a BSD-style license that can be | 1283 // Use of this source code is governed by a BSD-style license that can be |
1297 // found in the LICENSE file. | 1284 // found in the LICENSE file. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 args = '' | 1385 args = '' |
1399 arg_count = 0 | 1386 arg_count = 0 |
1400 if len(args): | 1387 if len(args): |
1401 arg_count = func['arguments'].count(',') + 1 | 1388 arg_count = func['arguments'].count(',') + 1 |
1402 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % | 1389 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % |
1403 (arg_count, func['known_as'][2:], func['return_type'], args)) | 1390 (arg_count, func['known_as'][2:], func['return_type'], args)) |
1404 | 1391 |
1405 file.write('\n') | 1392 file.write('\n') |
1406 | 1393 |
1407 | 1394 |
1408 def GenerateSource( | 1395 def GenerateSource(file, functions, set_name, used_extensions): |
1409 file, functions, nulldraw_functions, set_name, used_extensions): | |
1410 """Generates gl_bindings_autogen_x.cc""" | 1396 """Generates gl_bindings_autogen_x.cc""" |
1411 | 1397 |
1412 # Write file header. | 1398 # Write file header. |
1413 file.write( | 1399 file.write( |
1414 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1400 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
1415 // Use of this source code is governed by a BSD-style license that can be | 1401 // Use of this source code is governed by a BSD-style license that can be |
1416 // found in the LICENSE file. | 1402 // found in the LICENSE file. |
1417 | 1403 |
1418 // This file is automatically generated. | 1404 // This file is automatically generated. |
1419 | 1405 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 file.write(' debug_fn.%sFn = 0;\n' % func['known_as']) | 1546 file.write(' debug_fn.%sFn = 0;\n' % func['known_as']) |
1561 WriteConditionalFuncBinding(file, func) | 1547 WriteConditionalFuncBinding(file, func) |
1562 | 1548 |
1563 # Some new function pointers have been added, so update them in debug bindings | 1549 # Some new function pointers have been added, so update them in debug bindings |
1564 file.write('\n') | 1550 file.write('\n') |
1565 file.write(' if (g_debugBindingsInitialized)\n') | 1551 file.write(' if (g_debugBindingsInitialized)\n') |
1566 file.write(' InitializeDebugBindings();\n') | 1552 file.write(' InitializeDebugBindings();\n') |
1567 file.write('}\n') | 1553 file.write('}\n') |
1568 file.write('\n') | 1554 file.write('\n') |
1569 | 1555 |
1570 # Write empty stubs for functions that want one. | |
1571 file.write('extern "C" {\n') | |
1572 for func in nulldraw_functions: | |
1573 known_as = func['known_as'] | |
1574 return_type = func['return_type'] | |
1575 arguments = func['arguments'] | |
1576 file.write('\n') | |
1577 file.write('static %s GL_BINDING_CALL Stub_%s(%s) {}\n' % | |
1578 (return_type, known_as, arguments)) | |
1579 file.write('} // extern "C"\n') | |
1580 | |
1581 # Write logging wrappers for each function. | 1556 # Write logging wrappers for each function. |
1582 file.write('extern "C" {\n') | 1557 file.write('extern "C" {\n') |
1583 for func in functions: | 1558 for func in functions: |
1584 return_type = func['return_type'] | 1559 return_type = func['return_type'] |
1585 arguments = func['arguments'] | 1560 arguments = func['arguments'] |
1586 file.write('\n') | 1561 file.write('\n') |
1587 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % | 1562 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % |
1588 (return_type, func['known_as'], arguments)) | 1563 (return_type, func['known_as'], arguments)) |
1589 argument_names = re.sub( | 1564 argument_names = re.sub( |
1590 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | 1565 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 set_name.upper()) | 1624 set_name.upper()) |
1650 for func in functions: | 1625 for func in functions: |
1651 first_name = func['known_as'] | 1626 first_name = func['known_as'] |
1652 file.write(' if (!debug_fn.%sFn) {\n' % first_name) | 1627 file.write(' if (!debug_fn.%sFn) {\n' % first_name) |
1653 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) | 1628 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) |
1654 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) | 1629 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) |
1655 file.write(' }\n') | 1630 file.write(' }\n') |
1656 file.write(' g_debugBindingsInitialized = true;\n') | 1631 file.write(' g_debugBindingsInitialized = true;\n') |
1657 file.write('}\n') | 1632 file.write('}\n') |
1658 | 1633 |
1659 # Write function to initialize the nulldraw function pointers. | |
1660 if nulldraw_functions: | |
1661 file.write('\n') | |
1662 file.write('void Driver%s::InitializeNullDrawBindings() {\n' % | |
1663 set_name.upper()) | |
1664 | |
1665 for func in nulldraw_functions: | |
1666 first_name = func['known_as'] | |
1667 file.write(' fn.%sFn = Stub_%s;\n' % (first_name, first_name)) | |
1668 file.write('}\n') | |
1669 | |
1670 # Write function to clear all function pointers. | 1634 # Write function to clear all function pointers. |
1671 file.write('\n') | 1635 file.write('\n') |
1672 file.write("""void Driver%s::ClearBindings() { | 1636 file.write("""void Driver%s::ClearBindings() { |
1673 memset(this, 0, sizeof(*this)); | 1637 memset(this, 0, sizeof(*this)); |
1674 } | 1638 } |
1675 """ % set_name.upper()) | 1639 """ % set_name.upper()) |
1676 | 1640 |
1677 # Write GLApiBase functions | 1641 # Write GLApiBase functions |
1678 for func in functions: | 1642 for func in functions: |
1679 function_name = func['known_as'] | 1643 function_name = func['known_as'] |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1972 def main(argv): | 1936 def main(argv): |
1973 """This is the main function.""" | 1937 """This is the main function.""" |
1974 | 1938 |
1975 parser = optparse.OptionParser() | 1939 parser = optparse.OptionParser() |
1976 parser.add_option('--inputs', action='store_true') | 1940 parser.add_option('--inputs', action='store_true') |
1977 parser.add_option('--header-paths') | 1941 parser.add_option('--header-paths') |
1978 | 1942 |
1979 options, args = parser.parse_args(argv) | 1943 options, args = parser.parse_args(argv) |
1980 | 1944 |
1981 if options.inputs: | 1945 if options.inputs: |
1982 for [_, _, _, headers, _] in FUNCTION_SETS: | 1946 for [_, _, headers, _] in FUNCTION_SETS: |
1983 for header in headers: | 1947 for header in headers: |
1984 print ResolveHeader(header, options.header_paths) | 1948 print ResolveHeader(header, options.header_paths) |
1985 return 0 | 1949 return 0 |
1986 | 1950 |
1987 directory = '.' | 1951 directory = '.' |
1988 if len(args) >= 1: | 1952 if len(args) >= 1: |
1989 directory = args[0] | 1953 directory = args[0] |
1990 | 1954 |
1991 for [functions, | 1955 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: |
1992 nulldraw_functions, | |
1993 set_name, | |
1994 extension_headers, | |
1995 extensions] in FUNCTION_SETS: | |
1996 # Function names can be specified in two ways (list of unique names or list | 1956 # Function names can be specified in two ways (list of unique names or list |
1997 # of versions with different binding conditions). Fill in the data to the | 1957 # of versions with different binding conditions). Fill in the data to the |
1998 # versions list in case it is missing, so that can be used from here on: | 1958 # versions list in case it is missing, so that can be used from here on: |
1999 for func in functions + nulldraw_functions: | 1959 for func in functions: |
2000 assert 'versions' in func or 'names' in func, 'Function with no names' | 1960 assert 'versions' in func or 'names' in func, 'Function with no names' |
2001 if 'versions' not in func: | 1961 if 'versions' not in func: |
2002 func['versions'] = [{'name': n} for n in func['names']] | 1962 func['versions'] = [{'name': n} for n in func['names']] |
2003 # Use the first version's name unless otherwise specified | 1963 # Use the first version's name unless otherwise specified |
2004 if 'known_as' not in func: | 1964 if 'known_as' not in func: |
2005 func['known_as'] = func['versions'][0]['name'] | 1965 func['known_as'] = func['versions'][0]['name'] |
2006 # Make sure that 'names' is not accidentally used instead of 'versions' | 1966 # Make sure that 'names' is not accidentally used instead of 'versions' |
2007 if 'names' in func: | 1967 if 'names' in func: |
2008 del func['names'] | 1968 del func['names'] |
2009 | 1969 |
2010 extension_headers = [ResolveHeader(h, options.header_paths) | 1970 extension_headers = [ResolveHeader(h, options.header_paths) |
2011 for h in extension_headers] | 1971 for h in extension_headers] |
2012 used_extensions = FillExtensionsFromHeaders( | 1972 used_extensions = FillExtensionsFromHeaders( |
2013 functions, extension_headers, extensions) | 1973 functions, extension_headers, extensions) |
2014 | 1974 |
2015 header_file = open( | 1975 header_file = open( |
2016 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | 1976 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb') |
2017 GenerateHeader(header_file, functions, set_name, used_extensions) | 1977 GenerateHeader(header_file, functions, set_name, used_extensions) |
2018 header_file.close() | 1978 header_file.close() |
2019 | 1979 |
2020 header_file = open( | 1980 header_file = open( |
2021 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name), | 1981 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name), |
2022 'wb') | 1982 'wb') |
2023 GenerateAPIHeader(header_file, functions, set_name) | 1983 GenerateAPIHeader(header_file, functions, set_name) |
2024 header_file.close() | 1984 header_file.close() |
2025 | 1985 |
2026 source_file = open( | 1986 source_file = open( |
2027 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | 1987 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') |
2028 GenerateSource(source_file, | 1988 GenerateSource(source_file, functions, set_name, used_extensions) |
2029 functions, | |
2030 nulldraw_functions, | |
2031 set_name, | |
2032 used_extensions) | |
2033 source_file.close() | 1989 source_file.close() |
2034 | 1990 |
2035 header_file = open( | 1991 header_file = open( |
2036 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb') | 1992 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb') |
2037 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl') | 1993 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl') |
2038 header_file.close() | 1994 header_file.close() |
2039 | 1995 |
2040 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'), | 1996 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'), |
2041 'wb') | 1997 'wb') |
2042 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS) | 1998 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS) |
2043 header_file.close() | 1999 header_file.close() |
2044 | 2000 |
2045 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), | 2001 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), |
2046 'wb') | 2002 'wb') |
2047 GenerateMockBindingsSource(source_file, GL_FUNCTIONS) | 2003 GenerateMockBindingsSource(source_file, GL_FUNCTIONS) |
2048 source_file.close() | 2004 source_file.close() |
2049 return 0 | 2005 return 0 |
2050 | 2006 |
2051 | 2007 |
2052 if __name__ == '__main__': | 2008 if __name__ == '__main__': |
2053 sys.exit(main(sys.argv[1:])) | 2009 sys.exit(main(sys.argv[1:])) |
OLD | NEW |