Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: ui/gl/generate_bindings.py

Issue 11693007: Linux: use generated shim headers for system mesa. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes for windows Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/generate_shim_headers/generate_shim_headers.py ('k') | ui/gl/gl.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' 1141 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, '
1141 'int64* sbc' }, 1142 'int64* sbc' },
1142 { 'return_type': 'bool', 1143 { 'return_type': 'bool',
1143 'names': ['glXGetMscRateOML'], 1144 'names': ['glXGetMscRateOML'],
1144 'arguments': 1145 'arguments':
1145 'Display* dpy, GLXDrawable drawable, int32* numerator, ' 1146 'Display* dpy, GLXDrawable drawable, int32* numerator, '
1146 'int32* denominator' }, 1147 'int32* denominator' },
1147 ] 1148 ]
1148 1149
1149 FUNCTION_SETS = [ 1150 FUNCTION_SETS = [
1150 [GL_FUNCTIONS, 'gl', ['../../third_party/mesa/MesaLib/include/GL/glext.h', 1151 [GL_FUNCTIONS, 'gl', [
1151 '../../third_party/khronos/GLES2/gl2ext.h'], []], 1152 'GL/glext.h',
1153 'GLES2/gl2ext.h',
1154 # Files below are Chromium-specific and shipped with Chromium sources.
1155 'GLES2/gl2chromium.h',
1156 'GLES2/gl2extchromium.h'
1157 ], []],
1152 [OSMESA_FUNCTIONS, 'osmesa', [], []], 1158 [OSMESA_FUNCTIONS, 'osmesa', [], []],
1153 [EGL_FUNCTIONS, 'egl', ['../../third_party/khronos/EGL/eglext.h'], 1159 [EGL_FUNCTIONS, 'egl', ['EGL/eglext.h'],
1154 [ 1160 [
1155 'EGL_ANGLE_d3d_share_handle_client_buffer', 1161 'EGL_ANGLE_d3d_share_handle_client_buffer',
1156 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', 1162 'EGL_ANGLE_surface_d3d_texture_2d_share_handle',
1157 ], 1163 ],
1158 ], 1164 ],
1159 [WGL_FUNCTIONS, 'wgl', [ 1165 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []],
1160 '../../third_party/mesa/MesaLib/include/GL/wglext.h'], []], 1166 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []],
1161 [GLX_FUNCTIONS, 'glx', [
1162 '../../third_party/mesa/MesaLib/include/GL/glx.h',
1163 '../../third_party/mesa/MesaLib/include/GL/glxext.h'], []],
1164 ] 1167 ]
1165 1168
1166 def GenerateHeader(file, functions, set_name, used_extension_functions): 1169 def GenerateHeader(file, functions, set_name, used_extension_functions):
1167 """Generates gl_binding_autogen_x.h""" 1170 """Generates gl_binding_autogen_x.h"""
1168 1171
1169 # Write file header. 1172 # Write file header.
1170 file.write( 1173 file.write(
1171 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1174 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1172 // Use of this source code is governed by a BSD-style license that can be 1175 // Use of this source code is governed by a BSD-style license that can be
1173 // found in the LICENSE file. 1176 // found in the LICENSE file.
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 def ParseExtensionFunctionsFromHeader(header_file): 1587 def ParseExtensionFunctionsFromHeader(header_file):
1585 """Parse a C extension header file and return a map from extension names to 1588 """Parse a C extension header file and return a map from extension names to
1586 a list of functions. 1589 a list of functions.
1587 1590
1588 Args: 1591 Args:
1589 header_file: Line-iterable C header file. 1592 header_file: Line-iterable C header file.
1590 Returns: 1593 Returns:
1591 Map of extension name => functions. 1594 Map of extension name => functions.
1592 """ 1595 """
1593 extension_start = re.compile(r'#define ([A-Z]+_[A-Z]+_[a-zA-Z]\w+) 1') 1596 extension_start = re.compile(r'#define ([A-Z]+_[A-Z]+_[a-zA-Z]\w+) 1')
1594 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(.+\);') 1597 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(')
1595 typedef = re.compile(r'typedef .*') 1598 typedef = re.compile(r'typedef .*')
1596 macro_start = re.compile(r'^#(if|ifdef|ifndef).*') 1599 macro_start = re.compile(r'^#(if|ifdef|ifndef).*')
1597 macro_end = re.compile(r'^#endif.*') 1600 macro_end = re.compile(r'^#endif.*')
1598 macro_depth = 0 1601 macro_depth = 0
1599 current_extension = None 1602 current_extension = None
1600 current_extension_depth = 0 1603 current_extension_depth = 0
1601 extensions = collections.defaultdict(lambda: []) 1604 extensions = collections.defaultdict(lambda: [])
1602 for line in header_file: 1605 for line in header_file:
1603 if macro_start.match(line): 1606 if macro_start.match(line):
1604 macro_depth += 1 1607 macro_depth += 1
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 # Prefer ratified extensions and EXTs. 1698 # Prefer ratified extensions and EXTs.
1696 preferences = ['_ARB_', '_OES_', '_EXT_', ''] 1699 preferences = ['_ARB_', '_OES_', '_EXT_', '']
1697 for i, category in enumerate(preferences): 1700 for i, category in enumerate(preferences):
1698 if category in name: 1701 if category in name:
1699 return -i 1702 return -i
1700 used_extension_functions = sorted(used_extension_functions.items(), 1703 used_extension_functions = sorted(used_extension_functions.items(),
1701 key = lambda item: ExtensionSortKey(item[0])) 1704 key = lambda item: ExtensionSortKey(item[0]))
1702 return used_extension_functions 1705 return used_extension_functions
1703 1706
1704 1707
1708 def ResolveHeader(header, header_paths):
1709 paths = header_paths.split(':')
1710
1711 # Always use a path for Chromium-specific extensions. They are extracted
1712 # to separate files.
1713 paths.append('../../gpu')
1714
1715 root = os.path.abspath(os.path.dirname(__file__))
1716
1717 for path in paths:
1718 result = os.path.join(path, header)
1719 if not os.path.isabs(path):
1720 result = os.path.relpath(os.path.join(root, result), os.getcwd())
1721 if os.path.exists(result):
1722 # Always use forward slashes as path separators. Otherwise backslashes
1723 # may be incorrectly interpreted as escape characters.
1724 return result.replace(os.path.sep, '/')
1725
1726 raise Exception('Header %s not found.' % header)
1727
1728
1705 def main(argv): 1729 def main(argv):
1706 """This is the main function.""" 1730 """This is the main function."""
1707 1731
1708 if len(argv) >= 1: 1732 parser = optparse.OptionParser()
1709 dir = argv[0] 1733 parser.add_option('--inputs', action='store_true')
1734 parser.add_option('--header-paths')
1735
1736 options, args = parser.parse_args(argv)
1737
1738 if options.inputs:
1739 for [_, _, headers, _] in FUNCTION_SETS:
1740 for header in headers:
1741 print ResolveHeader(header, options.header_paths)
1742 return 0
1743
1744 if len(args) >= 1:
1745 dir = args[0]
1710 else: 1746 else:
1711 dir = '.' 1747 dir = '.'
1712 1748
1713 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: 1749 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS:
1750 extension_headers = [ResolveHeader(h, options.header_paths)
1751 for h in extension_headers]
1714 used_extension_functions = GetUsedExtensionFunctions( 1752 used_extension_functions = GetUsedExtensionFunctions(
1715 functions, extension_headers, extensions) 1753 functions, extension_headers, extensions)
1716 1754
1717 header_file = open( 1755 header_file = open(
1718 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') 1756 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb')
1719 GenerateHeader(header_file, functions, set_name, used_extension_functions) 1757 GenerateHeader(header_file, functions, set_name, used_extension_functions)
1720 header_file.close() 1758 header_file.close()
1721 1759
1722 header_file = open( 1760 header_file = open(
1723 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') 1761 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb')
(...skipping 19 matching lines...) Expand all
1743 header_file.close() 1781 header_file.close()
1744 1782
1745 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') 1783 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb')
1746 GenerateMockSource(source_file, GL_FUNCTIONS) 1784 GenerateMockSource(source_file, GL_FUNCTIONS)
1747 source_file.close() 1785 source_file.close()
1748 return 0 1786 return 0
1749 1787
1750 1788
1751 if __name__ == '__main__': 1789 if __name__ == '__main__':
1752 sys.exit(main(sys.argv[1:])) 1790 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « tools/generate_shim_headers/generate_shim_headers.py ('k') | ui/gl/gl.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698