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 os | 9 import os |
9 import collections | 10 import collections |
10 import re | 11 import re |
11 import sys | 12 import sys |
12 | 13 |
13 GL_FUNCTIONS = [ | 14 GL_FUNCTIONS = [ |
14 { 'return_type': 'void', | 15 { 'return_type': 'void', |
15 'names': ['glActiveTexture'], | 16 'names': ['glActiveTexture'], |
16 'arguments': 'GLenum texture', }, | 17 'arguments': 'GLenum texture', }, |
17 { 'return_type': 'void', | 18 { 'return_type': 'void', |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 'arguments': | 1134 'arguments': |
1134 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' | 1135 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' |
1135 'int64* sbc' }, | 1136 'int64* sbc' }, |
1136 { 'return_type': 'bool', | 1137 { 'return_type': 'bool', |
1137 'names': ['glXGetMscRateOML'], | 1138 'names': ['glXGetMscRateOML'], |
1138 'arguments': | 1139 'arguments': |
1139 'Display* dpy, GLXDrawable drawable, int32* numerator, ' | 1140 'Display* dpy, GLXDrawable drawable, int32* numerator, ' |
1140 'int32* denominator' }, | 1141 'int32* denominator' }, |
1141 ] | 1142 ] |
1142 | 1143 |
1144 BUNDLED_HEADER_PATHS = [ | |
1145 '../../third_party/mesa/MesaLib/include', | |
1146 '../../third_party/khronos', | |
1147 ] | |
1148 | |
1149 SYSTEM_HEADER_PATHS = [ | |
1150 '/usr/include', | |
1151 ] | |
1152 | |
1143 FUNCTION_SETS = [ | 1153 FUNCTION_SETS = [ |
1144 [GL_FUNCTIONS, 'gl', ['../../third_party/mesa/MesaLib/include/GL/glext.h', | 1154 [GL_FUNCTIONS, 'gl', [ |
1145 '../../third_party/khronos/GLES2/gl2ext.h'], []], | 1155 'GL/glext.h', |
1156 'GLES2/gl2ext.h', | |
1157 # Files below are Chromium-specific and shipped with Chromium sources. | |
1158 'GLES2/gl2chromium.h', | |
1159 'GLES2/gl2extchromium.h' | |
1160 ], []], | |
1146 [OSMESA_FUNCTIONS, 'osmesa', [], []], | 1161 [OSMESA_FUNCTIONS, 'osmesa', [], []], |
1147 [EGL_FUNCTIONS, 'egl', ['../../third_party/khronos/EGL/eglext.h'], | 1162 [EGL_FUNCTIONS, 'egl', ['EGL/eglext.h'], |
1148 [ | 1163 [ |
1149 'EGL_ANGLE_d3d_share_handle_client_buffer', | 1164 'EGL_ANGLE_d3d_share_handle_client_buffer', |
1150 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', | 1165 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', |
1151 ], | 1166 ], |
1152 ], | 1167 ], |
1153 [WGL_FUNCTIONS, 'wgl', [ | 1168 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []], |
1154 '../../third_party/mesa/MesaLib/include/GL/wglext.h'], []], | 1169 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []], |
1155 [GLX_FUNCTIONS, 'glx', [ | |
1156 '../../third_party/mesa/MesaLib/include/GL/glx.h', | |
1157 '../../third_party/mesa/MesaLib/include/GL/glxext.h'], []], | |
1158 ] | 1170 ] |
1159 | 1171 |
1160 def GenerateHeader(file, functions, set_name, used_extension_functions): | 1172 def GenerateHeader(file, functions, set_name, used_extension_functions): |
1161 """Generates gl_binding_autogen_x.h""" | 1173 """Generates gl_binding_autogen_x.h""" |
1162 | 1174 |
1163 # Write file header. | 1175 # Write file header. |
1164 file.write( | 1176 file.write( |
1165 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1177 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1166 // Use of this source code is governed by a BSD-style license that can be | 1178 // Use of this source code is governed by a BSD-style license that can be |
1167 // found in the LICENSE file. | 1179 // found in the LICENSE file. |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1578 def ParseExtensionFunctionsFromHeader(header_file): | 1590 def ParseExtensionFunctionsFromHeader(header_file): |
1579 """Parse a C extension header file and return a map from extension names to | 1591 """Parse a C extension header file and return a map from extension names to |
1580 a list of functions. | 1592 a list of functions. |
1581 | 1593 |
1582 Args: | 1594 Args: |
1583 header_file: Line-iterable C header file. | 1595 header_file: Line-iterable C header file. |
1584 Returns: | 1596 Returns: |
1585 Map of extension name => functions. | 1597 Map of extension name => functions. |
1586 """ | 1598 """ |
1587 extension_start = re.compile(r'#define ([A-Z]+_[A-Z]+_[a-zA-Z]\w+) 1') | 1599 extension_start = re.compile(r'#define ([A-Z]+_[A-Z]+_[a-zA-Z]\w+) 1') |
1588 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(.+\);') | 1600 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(') |
1589 typedef = re.compile(r'typedef .*') | 1601 typedef = re.compile(r'typedef .*') |
1590 macro_start = re.compile(r'^#(if|ifdef|ifndef).*') | 1602 macro_start = re.compile(r'^#(if|ifdef|ifndef).*') |
1591 macro_end = re.compile(r'^#endif.*') | 1603 macro_end = re.compile(r'^#endif.*') |
1592 macro_depth = 0 | 1604 macro_depth = 0 |
1593 current_extension = None | 1605 current_extension = None |
1594 current_extension_depth = 0 | 1606 current_extension_depth = 0 |
1595 extensions = collections.defaultdict(lambda: []) | 1607 extensions = collections.defaultdict(lambda: []) |
1596 for line in header_file: | 1608 for line in header_file: |
1597 if macro_start.match(line): | 1609 if macro_start.match(line): |
1598 macro_depth += 1 | 1610 macro_depth += 1 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1689 # Prefer ratified extensions and EXTs. | 1701 # Prefer ratified extensions and EXTs. |
1690 preferences = ['_ARB_', '_OES_', '_EXT_', ''] | 1702 preferences = ['_ARB_', '_OES_', '_EXT_', ''] |
1691 for i, category in enumerate(preferences): | 1703 for i, category in enumerate(preferences): |
1692 if category in name: | 1704 if category in name: |
1693 return -i | 1705 return -i |
1694 used_extension_functions = sorted(used_extension_functions.items(), | 1706 used_extension_functions = sorted(used_extension_functions.items(), |
1695 key = lambda item: ExtensionSortKey(item[0])) | 1707 key = lambda item: ExtensionSortKey(item[0])) |
1696 return used_extension_functions | 1708 return used_extension_functions |
1697 | 1709 |
1698 | 1710 |
1711 def ResolveHeader(header, use_system_mesa): | |
greggman
2013/01/07 20:23:33
All the changes in this file seem like adding a bu
Paweł Hajdan Jr.
2013/01/07 21:20:05
No. This file is executed during the build process
greggman
2013/01/07 21:32:22
It's not just a burden. The code you added is the
| |
1712 if use_system_mesa == 1: | |
1713 paths = SYSTEM_HEADER_PATHS | |
1714 else: | |
1715 paths = BUNDLED_HEADER_PATHS | |
1716 | |
1717 # Always use a path for Chromium-specific extensions. They are extracted | |
1718 # to separate files. | |
1719 paths.append('../../gpu') | |
1720 | |
1721 root = os.path.abspath(os.path.dirname(__file__)) | |
1722 | |
1723 for path in paths: | |
1724 result = os.path.join(path, header) | |
1725 if not os.path.isabs(path): | |
1726 result = os.path.relpath(os.path.join(root, result), os.getcwd()) | |
1727 if os.path.exists(result): | |
1728 return result | |
1729 | |
1730 raise Exception('Header %s not found.' % header) | |
1731 | |
1732 | |
1699 def main(argv): | 1733 def main(argv): |
1700 """This is the main function.""" | 1734 """This is the main function.""" |
1701 | 1735 |
1702 if len(argv) >= 1: | 1736 parser = optparse.OptionParser() |
1703 dir = argv[0] | 1737 parser.add_option('--inputs', action='store_true') |
1738 parser.add_option('--use-system-mesa', type=int, default=0) | |
1739 | |
1740 options, args = parser.parse_args(argv) | |
1741 | |
1742 if options.inputs: | |
1743 for [_, _, headers, _] in FUNCTION_SETS: | |
1744 for header in headers: | |
1745 print ResolveHeader(header, options.use_system_mesa) | |
1746 return 0 | |
1747 | |
1748 if len(args) >= 1: | |
1749 dir = args[0] | |
1704 else: | 1750 else: |
1705 dir = '.' | 1751 dir = '.' |
1706 | 1752 |
1707 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: | 1753 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: |
1754 extension_headers = [ResolveHeader(h, options.use_system_mesa) | |
1755 for h in extension_headers] | |
1708 used_extension_functions = GetUsedExtensionFunctions( | 1756 used_extension_functions = GetUsedExtensionFunctions( |
1709 functions, extension_headers, extensions) | 1757 functions, extension_headers, extensions) |
1710 | 1758 |
1711 header_file = open( | 1759 header_file = open( |
1712 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | 1760 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') |
1713 GenerateHeader(header_file, functions, set_name, used_extension_functions) | 1761 GenerateHeader(header_file, functions, set_name, used_extension_functions) |
1714 header_file.close() | 1762 header_file.close() |
1715 | 1763 |
1716 header_file = open( | 1764 header_file = open( |
1717 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') | 1765 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') |
(...skipping 19 matching lines...) Expand all Loading... | |
1737 header_file.close() | 1785 header_file.close() |
1738 | 1786 |
1739 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 1787 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
1740 GenerateMockSource(source_file, GL_FUNCTIONS) | 1788 GenerateMockSource(source_file, GL_FUNCTIONS) |
1741 source_file.close() | 1789 source_file.close() |
1742 return 0 | 1790 return 0 |
1743 | 1791 |
1744 | 1792 |
1745 if __name__ == '__main__': | 1793 if __name__ == '__main__': |
1746 sys.exit(main(sys.argv[1:])) | 1794 sys.exit(main(sys.argv[1:])) |
OLD | NEW |