OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 os | 8 import os |
9 import collections | 9 import collections |
10 import re | 10 import re |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 'arguments': 'Display* dpy, XVisualInfo* visualInfo', }, | 995 'arguments': 'Display* dpy, XVisualInfo* visualInfo', }, |
996 { 'return_type': 'GLXContext', | 996 { 'return_type': 'GLXContext', |
997 'names': ['glXCreateContextAttribsARB'], | 997 'names': ['glXCreateContextAttribsARB'], |
998 'arguments': | 998 'arguments': |
999 'Display* dpy, GLXFBConfig config, GLXContext share_context, int direct, ' | 999 'Display* dpy, GLXFBConfig config, GLXContext share_context, int direct, ' |
1000 'const int* attrib_list', }, | 1000 'const int* attrib_list', }, |
1001 ] | 1001 ] |
1002 | 1002 |
1003 FUNCTION_SETS = [ | 1003 FUNCTION_SETS = [ |
1004 [GL_FUNCTIONS, 'gl', ['../../../third_party/mesa/MesaLib/include/GL/glext.h', | 1004 [GL_FUNCTIONS, 'gl', ['../../../third_party/mesa/MesaLib/include/GL/glext.h', |
1005 '../../../third_party/khronos/GLES2/gl2ext.h']], | 1005 '../../../third_party/khronos/GLES2/gl2ext.h'], []], |
1006 [OSMESA_FUNCTIONS, 'osmesa', []], | 1006 [OSMESA_FUNCTIONS, 'osmesa', [], []], |
1007 [EGL_FUNCTIONS, 'egl', ['../../../third_party/khronos/EGL/eglext.h']], | 1007 [EGL_FUNCTIONS, 'egl', ['../../../third_party/khronos/EGL/eglext.h'], |
| 1008 [ |
| 1009 'EGL_ANGLE_d3d_share_handle_client_buffer', |
| 1010 ], |
| 1011 ], |
1008 [WGL_FUNCTIONS, 'wgl', [ | 1012 [WGL_FUNCTIONS, 'wgl', [ |
1009 '../../../third_party/mesa/MesaLib/include/GL/wglext.h']], | 1013 '../../../third_party/mesa/MesaLib/include/GL/wglext.h'], []], |
1010 [GLX_FUNCTIONS, 'glx', [ | 1014 [GLX_FUNCTIONS, 'glx', [ |
1011 '../../../third_party/mesa/MesaLib/include/GL/glxext.h']], | 1015 '../../../third_party/mesa/MesaLib/include/GL/glxext.h'], []], |
1012 ] | 1016 ] |
1013 | 1017 |
1014 | |
1015 def GenerateHeader(file, functions, set_name, used_extension_functions): | 1018 def GenerateHeader(file, functions, set_name, used_extension_functions): |
1016 """Generates gl_binding_autogen_x.h""" | 1019 """Generates gl_binding_autogen_x.h""" |
1017 | 1020 |
1018 # Write file header. | 1021 # Write file header. |
1019 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') | 1022 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') |
1020 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') | 1023 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') |
1021 file.write('// found in the LICENSE file.\n') | 1024 file.write('// found in the LICENSE file.\n') |
1022 file.write('\n') | 1025 file.write('\n') |
1023 file.write('// This file is automatically generated.\n') | 1026 file.write('// This file is automatically generated.\n') |
1024 file.write('\n') | 1027 file.write('\n') |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 return function_to_extension | 1374 return function_to_extension |
1372 | 1375 |
1373 | 1376 |
1374 def LooksLikeExtensionFunction(function): | 1377 def LooksLikeExtensionFunction(function): |
1375 """Heuristic to see if a function name is consistent with extension function | 1378 """Heuristic to see if a function name is consistent with extension function |
1376 naming.""" | 1379 naming.""" |
1377 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) | 1380 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) |
1378 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] | 1381 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] |
1379 | 1382 |
1380 | 1383 |
1381 def GetUsedExtensionFunctions(functions, extension_headers): | 1384 def GetUsedExtensionFunctions(functions, extension_headers, extra_extensions): |
1382 """Determine which functions belong to extensions. | 1385 """Determine which functions belong to extensions. |
1383 | 1386 |
1384 Args: | 1387 Args: |
1385 functions: List of (return type, function names, arguments). | 1388 functions: List of (return type, function names, arguments). |
1386 extension_headers: List of header file names. | 1389 extension_headers: List of header file names. |
1387 Returns: | 1390 Returns: |
1388 List of (extension name, [function name alternatives]) sorted with least | 1391 List of (extension name, [function name alternatives]) sorted with least |
1389 preferred extensions first. | 1392 preferred extensions first. |
1390 """ | 1393 """ |
1391 # Parse known extensions. | 1394 # Parse known extensions. |
1392 extensions = GetExtensionFunctions(extension_headers) | 1395 extensions = GetExtensionFunctions(extension_headers) |
1393 functions_to_extensions = GetFunctionToExtensionMap(extensions) | 1396 functions_to_extensions = GetFunctionToExtensionMap(extensions) |
1394 | 1397 |
1395 # Collect all used extension functions. | 1398 # Collect all used extension functions. |
1396 used_extension_functions = collections.defaultdict(lambda: []) | 1399 used_extension_functions = collections.defaultdict(lambda: []) |
1397 for func in functions: | 1400 for func in functions: |
1398 for name in func['names']: | 1401 for name in func['names']: |
1399 # Make sure we know about all extension functions. | 1402 # Make sure we know about all extension functions. |
1400 if (LooksLikeExtensionFunction(name) and | 1403 if (LooksLikeExtensionFunction(name) and |
1401 not name in functions_to_extensions): | 1404 not name in functions_to_extensions): |
1402 raise RuntimeError('%s looks like an extension function but does not ' | 1405 raise RuntimeError('%s looks like an extension function but does not ' |
1403 'belong to any of the known extensions.' % name) | 1406 'belong to any of the known extensions.' % name) |
1404 if name in functions_to_extensions: | 1407 if name in functions_to_extensions: |
1405 extension = functions_to_extensions[name] | 1408 extension = functions_to_extensions[name] |
1406 used_extension_functions[extension].append((func['names'][0], name)) | 1409 used_extension_functions[extension].append((func['names'][0], name)) |
1407 | 1410 |
| 1411 # Add extensions that do not have any functions. |
| 1412 used_extension_functions.update(dict( |
| 1413 [(e, []) for e in extra_extensions if e not in used_extension_functions])) |
| 1414 |
1408 def ExtensionSortKey(name): | 1415 def ExtensionSortKey(name): |
1409 # Prefer ratified extensions and EXTs. | 1416 # Prefer ratified extensions and EXTs. |
1410 preferences = ['_ARB_', '_OES_', '_EXT_', ''] | 1417 preferences = ['_ARB_', '_OES_', '_EXT_', ''] |
1411 for i, category in enumerate(preferences): | 1418 for i, category in enumerate(preferences): |
1412 if category in name: | 1419 if category in name: |
1413 return -i | 1420 return -i |
1414 used_extension_functions = sorted(used_extension_functions.items(), | 1421 used_extension_functions = sorted(used_extension_functions.items(), |
1415 key = lambda item: ExtensionSortKey(item[0])) | 1422 key = lambda item: ExtensionSortKey(item[0])) |
1416 return used_extension_functions | 1423 return used_extension_functions |
1417 | 1424 |
1418 | 1425 |
1419 def main(argv): | 1426 def main(argv): |
1420 """This is the main function.""" | 1427 """This is the main function.""" |
1421 | 1428 |
1422 if len(argv) >= 1: | 1429 if len(argv) >= 1: |
1423 dir = argv[0] | 1430 dir = argv[0] |
1424 else: | 1431 else: |
1425 dir = '.' | 1432 dir = '.' |
1426 | 1433 |
1427 for [functions, set_name, extension_headers] in FUNCTION_SETS: | 1434 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: |
1428 used_extension_functions = GetUsedExtensionFunctions( | 1435 used_extension_functions = GetUsedExtensionFunctions( |
1429 functions, extension_headers) | 1436 functions, extension_headers, extensions) |
1430 | 1437 |
1431 header_file = open( | 1438 header_file = open( |
1432 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | 1439 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') |
1433 GenerateHeader(header_file, functions, set_name, used_extension_functions) | 1440 GenerateHeader(header_file, functions, set_name, used_extension_functions) |
1434 header_file.close() | 1441 header_file.close() |
1435 | 1442 |
1436 source_file = open( | 1443 source_file = open( |
1437 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | 1444 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') |
1438 GenerateSource(source_file, functions, set_name, used_extension_functions) | 1445 GenerateSource(source_file, functions, set_name, used_extension_functions) |
1439 source_file.close() | 1446 source_file.close() |
1440 | 1447 |
1441 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 1448 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
1442 GenerateMockSource(source_file, GL_FUNCTIONS) | 1449 GenerateMockSource(source_file, GL_FUNCTIONS) |
1443 source_file.close() | 1450 source_file.close() |
1444 return 0 | 1451 return 0 |
1445 | 1452 |
1446 | 1453 |
1447 if __name__ == '__main__': | 1454 if __name__ == '__main__': |
1448 sys.exit(main(sys.argv[1:])) | 1455 sys.exit(main(sys.argv[1:])) |
OLD | NEW |