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

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: one less header 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
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 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
1143 FUNCTION_SETS = [ 1144 FUNCTION_SETS = [
1144 [GL_FUNCTIONS, 'gl', ['../../third_party/mesa/MesaLib/include/GL/glext.h', 1145 [GL_FUNCTIONS, 'gl', [
1145 '../../third_party/khronos/GLES2/gl2ext.h'], []], 1146 'GL/glext.h',
1147 'GLES2/gl2ext.h',
1148 # Files below are Chromium-specific and shipped with Chromium sources.
1149 'GLES2/gl2chromium.h',
1150 'GLES2/gl2extchromium.h'
1151 ], []],
1146 [OSMESA_FUNCTIONS, 'osmesa', [], []], 1152 [OSMESA_FUNCTIONS, 'osmesa', [], []],
1147 [EGL_FUNCTIONS, 'egl', ['../../third_party/khronos/EGL/eglext.h'], 1153 [EGL_FUNCTIONS, 'egl', ['EGL/eglext.h'],
1148 [ 1154 [
1149 'EGL_ANGLE_d3d_share_handle_client_buffer', 1155 'EGL_ANGLE_d3d_share_handle_client_buffer',
1150 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', 1156 'EGL_ANGLE_surface_d3d_texture_2d_share_handle',
1151 ], 1157 ],
1152 ], 1158 ],
1153 [WGL_FUNCTIONS, 'wgl', [ 1159 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []],
1154 '../../third_party/mesa/MesaLib/include/GL/wglext.h'], []], 1160 [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 ] 1161 ]
1159 1162
1160 def GenerateHeader(file, functions, set_name, used_extension_functions): 1163 def GenerateHeader(file, functions, set_name, used_extension_functions):
1161 """Generates gl_binding_autogen_x.h""" 1164 """Generates gl_binding_autogen_x.h"""
1162 1165
1163 # Write file header. 1166 # Write file header.
1164 file.write( 1167 file.write(
1165 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1168 """// 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 1169 // Use of this source code is governed by a BSD-style license that can be
1167 // found in the LICENSE file. 1170 // found in the LICENSE file.
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 def ParseExtensionFunctionsFromHeader(header_file): 1581 def ParseExtensionFunctionsFromHeader(header_file):
1579 """Parse a C extension header file and return a map from extension names to 1582 """Parse a C extension header file and return a map from extension names to
1580 a list of functions. 1583 a list of functions.
1581 1584
1582 Args: 1585 Args:
1583 header_file: Line-iterable C header file. 1586 header_file: Line-iterable C header file.
1584 Returns: 1587 Returns:
1585 Map of extension name => functions. 1588 Map of extension name => functions.
1586 """ 1589 """
1587 extension_start = re.compile(r'#define ([A-Z]+_[A-Z]+_[a-zA-Z]\w+) 1') 1590 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*\(.+\);') 1591 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(')
1589 typedef = re.compile(r'typedef .*') 1592 typedef = re.compile(r'typedef .*')
1590 macro_start = re.compile(r'^#(if|ifdef|ifndef).*') 1593 macro_start = re.compile(r'^#(if|ifdef|ifndef).*')
1591 macro_end = re.compile(r'^#endif.*') 1594 macro_end = re.compile(r'^#endif.*')
1592 macro_depth = 0 1595 macro_depth = 0
1593 current_extension = None 1596 current_extension = None
1594 current_extension_depth = 0 1597 current_extension_depth = 0
1595 extensions = collections.defaultdict(lambda: []) 1598 extensions = collections.defaultdict(lambda: [])
1596 for line in header_file: 1599 for line in header_file:
1597 if macro_start.match(line): 1600 if macro_start.match(line):
1598 macro_depth += 1 1601 macro_depth += 1
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 # Prefer ratified extensions and EXTs. 1692 # Prefer ratified extensions and EXTs.
1690 preferences = ['_ARB_', '_OES_', '_EXT_', ''] 1693 preferences = ['_ARB_', '_OES_', '_EXT_', '']
1691 for i, category in enumerate(preferences): 1694 for i, category in enumerate(preferences):
1692 if category in name: 1695 if category in name:
1693 return -i 1696 return -i
1694 used_extension_functions = sorted(used_extension_functions.items(), 1697 used_extension_functions = sorted(used_extension_functions.items(),
1695 key = lambda item: ExtensionSortKey(item[0])) 1698 key = lambda item: ExtensionSortKey(item[0]))
1696 return used_extension_functions 1699 return used_extension_functions
1697 1700
1698 1701
1702 def ResolveHeader(header, header_paths):
1703 paths = header_paths.split(':')
1704
1705 # Always use a path for Chromium-specific extensions. They are extracted
1706 # to separate files.
1707 paths.append('../../gpu')
1708
1709 root = os.path.abspath(os.path.dirname(__file__))
1710
1711 for path in paths:
1712 result = os.path.join(path, header)
1713 if not os.path.isabs(path):
1714 result = os.path.relpath(os.path.join(root, result), os.getcwd())
1715 if os.path.exists(result):
1716 return result
1717
1718 raise Exception('Header %s not found.' % header)
1719
1720
1699 def main(argv): 1721 def main(argv):
1700 """This is the main function.""" 1722 """This is the main function."""
1701 1723
1702 if len(argv) >= 1: 1724 parser = optparse.OptionParser()
1703 dir = argv[0] 1725 parser.add_option('--inputs', action='store_true')
1726 parser.add_option('--header-paths')
1727
1728 options, args = parser.parse_args(argv)
1729
1730 if options.inputs:
1731 for [_, _, headers, _] in FUNCTION_SETS:
1732 for header in headers:
1733 print ResolveHeader(header, options.header_paths)
1734 return 0
1735
1736 if len(args) >= 1:
1737 dir = args[0]
1704 else: 1738 else:
1705 dir = '.' 1739 dir = '.'
1706 1740
1707 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: 1741 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS:
1742 extension_headers = [ResolveHeader(h, options.header_paths)
1743 for h in extension_headers]
1708 used_extension_functions = GetUsedExtensionFunctions( 1744 used_extension_functions = GetUsedExtensionFunctions(
1709 functions, extension_headers, extensions) 1745 functions, extension_headers, extensions)
1710 1746
1711 header_file = open( 1747 header_file = open(
1712 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') 1748 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb')
1713 GenerateHeader(header_file, functions, set_name, used_extension_functions) 1749 GenerateHeader(header_file, functions, set_name, used_extension_functions)
1714 header_file.close() 1750 header_file.close()
1715 1751
1716 header_file = open( 1752 header_file = open(
1717 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') 1753 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb')
(...skipping 19 matching lines...) Expand all
1737 header_file.close() 1773 header_file.close()
1738 1774
1739 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') 1775 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb')
1740 GenerateMockSource(source_file, GL_FUNCTIONS) 1776 GenerateMockSource(source_file, GL_FUNCTIONS)
1741 source_file.close() 1777 source_file.close()
1742 return 0 1778 return 0
1743 1779
1744 1780
1745 if __name__ == '__main__': 1781 if __name__ == '__main__':
1746 sys.exit(main(sys.argv[1:])) 1782 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698