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 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 file.write(' g_debugBindingsInitialized = true;\n') | 1645 file.write(' g_debugBindingsInitialized = true;\n') |
1646 file.write('}\n') | 1646 file.write('}\n') |
1647 | 1647 |
1648 # Write function to clear all function pointers. | 1648 # Write function to clear all function pointers. |
1649 file.write('\n') | 1649 file.write('\n') |
1650 file.write("""void Driver%s::ClearBindings() { | 1650 file.write("""void Driver%s::ClearBindings() { |
1651 memset(this, 0, sizeof(*this)); | 1651 memset(this, 0, sizeof(*this)); |
1652 } | 1652 } |
1653 """ % set_name.upper()) | 1653 """ % set_name.upper()) |
1654 | 1654 |
| 1655 def MakeArgNames(arguments): |
| 1656 argument_names = re.sub( |
| 1657 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) |
| 1658 argument_names = re.sub( |
| 1659 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) |
| 1660 if argument_names == 'void' or argument_names == '': |
| 1661 argument_names = '' |
| 1662 return argument_names |
| 1663 |
1655 # Write GLApiBase functions | 1664 # Write GLApiBase functions |
1656 for func in functions: | 1665 for func in functions: |
1657 function_name = func['known_as'] | 1666 function_name = func['known_as'] |
1658 return_type = func['return_type'] | 1667 return_type = func['return_type'] |
1659 arguments = func['arguments'] | 1668 arguments = func['arguments'] |
1660 file.write('\n') | 1669 file.write('\n') |
1661 file.write('%s %sApiBase::%sFn(%s) {\n' % | 1670 file.write('%s %sApiBase::%sFn(%s) {\n' % |
1662 (return_type, set_name.upper(), function_name, arguments)) | 1671 (return_type, set_name.upper(), function_name, arguments)) |
1663 argument_names = re.sub( | 1672 argument_names = MakeArgNames(arguments) |
1664 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | |
1665 argument_names = re.sub( | |
1666 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | |
1667 if argument_names == 'void' or argument_names == '': | |
1668 argument_names = '' | |
1669 if return_type == 'void': | 1673 if return_type == 'void': |
1670 file.write(' driver_->fn.%sFn(%s);\n' % | 1674 file.write(' driver_->fn.%sFn(%s);\n' % |
1671 (function_name, argument_names)) | 1675 (function_name, argument_names)) |
1672 else: | 1676 else: |
1673 file.write(' return driver_->fn.%sFn(%s);\n' % | 1677 file.write(' return driver_->fn.%sFn(%s);\n' % |
1674 (function_name, argument_names)) | 1678 (function_name, argument_names)) |
1675 file.write('}\n') | 1679 file.write('}\n') |
1676 | 1680 |
1677 # Write TraceGLApi functions | 1681 # Write TraceGLApi functions |
1678 for func in functions: | 1682 for func in functions: |
1679 function_name = func['known_as'] | 1683 function_name = func['known_as'] |
1680 return_type = func['return_type'] | 1684 return_type = func['return_type'] |
1681 arguments = func['arguments'] | 1685 arguments = func['arguments'] |
1682 file.write('\n') | 1686 file.write('\n') |
1683 file.write('%s Trace%sApi::%sFn(%s) {\n' % | 1687 file.write('%s Trace%sApi::%sFn(%s) {\n' % |
1684 (return_type, set_name.upper(), function_name, arguments)) | 1688 (return_type, set_name.upper(), function_name, arguments)) |
1685 argument_names = re.sub( | 1689 argument_names = MakeArgNames(arguments) |
1686 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | |
1687 argument_names = re.sub( | |
1688 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | |
1689 if argument_names == 'void' or argument_names == '': | |
1690 argument_names = '' | |
1691 file.write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "TraceGLAPI::%s")\n' % | 1690 file.write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "TraceGLAPI::%s")\n' % |
1692 function_name) | 1691 function_name) |
1693 if return_type == 'void': | 1692 if return_type == 'void': |
1694 file.write(' %s_api_->%sFn(%s);\n' % | 1693 file.write(' %s_api_->%sFn(%s);\n' % |
1695 (set_name.lower(), function_name, argument_names)) | 1694 (set_name.lower(), function_name, argument_names)) |
1696 else: | 1695 else: |
1697 file.write(' return %s_api_->%sFn(%s);\n' % | 1696 file.write(' return %s_api_->%sFn(%s);\n' % |
1698 (set_name.lower(), function_name, argument_names)) | 1697 (set_name.lower(), function_name, argument_names)) |
1699 file.write('}\n') | 1698 file.write('}\n') |
1700 | 1699 |
| 1700 # Write NoContextGLApi functions |
| 1701 if set_name.upper() == "GL": |
| 1702 for func in functions: |
| 1703 function_name = func['known_as'] |
| 1704 return_type = func['return_type'] |
| 1705 arguments = func['arguments'] |
| 1706 file.write('\n') |
| 1707 file.write('%s NoContextGLApi::%sFn(%s) {\n' % |
| 1708 (return_type, function_name, arguments)) |
| 1709 argument_names = MakeArgNames(arguments) |
| 1710 no_context_error = "Trying to call %s() without current GL context" % func
tion_name |
| 1711 file.write(' NOTREACHED() << "%s";\n' % no_context_error) |
| 1712 file.write(' LOG(ERROR) << "%s";\n' % no_context_error) |
| 1713 default_value = { 'GLenum': 'static_cast<GLenum>(0)', |
| 1714 'GLuint': '0U', |
| 1715 'GLint': '0', |
| 1716 'GLboolean': 'GL_FALSE', |
| 1717 'GLbyte': '0', |
| 1718 'GLubyte': '0', |
| 1719 'GLbutfield': '0', |
| 1720 'GLushort': '0', |
| 1721 'GLsizei': '0', |
| 1722 'GLfloat': '0.0f', |
| 1723 'GLdouble': '0.0', |
| 1724 'GLsync': 'NULL'} |
| 1725 if return_type.endswith('*'): |
| 1726 file.write(' return NULL;\n') |
| 1727 elif return_type != 'void': |
| 1728 file.write(' return %s;\n' % default_value[return_type]) |
| 1729 file.write('}\n') |
| 1730 |
1701 file.write('\n') | 1731 file.write('\n') |
1702 file.write('} // namespace gfx\n') | 1732 file.write('} // namespace gfx\n') |
1703 | 1733 |
1704 | 1734 |
1705 def GetUniquelyNamedFunctions(functions): | 1735 def GetUniquelyNamedFunctions(functions): |
1706 uniquely_named_functions = {} | 1736 uniquely_named_functions = {} |
1707 | 1737 |
1708 for func in functions: | 1738 for func in functions: |
1709 for version in func['versions']: | 1739 for version in func['versions']: |
1710 uniquely_named_functions[version['name']] = ({ | 1740 uniquely_named_functions[version['name']] = ({ |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 | 2044 |
2015 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), | 2045 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), |
2016 'wb') | 2046 'wb') |
2017 GenerateMockBindingsSource(source_file, GL_FUNCTIONS) | 2047 GenerateMockBindingsSource(source_file, GL_FUNCTIONS) |
2018 source_file.close() | 2048 source_file.close() |
2019 return 0 | 2049 return 0 |
2020 | 2050 |
2021 | 2051 |
2022 if __name__ == '__main__': | 2052 if __name__ == '__main__': |
2023 sys.exit(main(sys.argv[1:])) | 2053 sys.exit(main(sys.argv[1:])) |
OLD | NEW |