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

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

Issue 145293007: ui: No more TestCompositor. Use NullDraw contexts in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: testsnulldraw: Created 6 years, 10 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 optparse
9 import os 9 import os
10 import collections 10 import collections
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 'known_as': 'glDiscardFramebufferEXT', 814 'known_as': 'glDiscardFramebufferEXT',
815 'versions': [{ 'name': 'glInvalidateFramebuffer', 815 'versions': [{ 'name': 'glInvalidateFramebuffer',
816 'gl_versions': ['es3'], 816 'gl_versions': ['es3'],
817 'extensions': [] }, 817 'extensions': [] },
818 { 'name': 'glDiscardFramebufferEXT', 818 { 'name': 'glDiscardFramebufferEXT',
819 'gl_versions': ['es1', 'es2'] }], 819 'gl_versions': ['es1', 'es2'] }],
820 'arguments': 'GLenum target, GLsizei numAttachments, ' 820 'arguments': 'GLenum target, GLsizei numAttachments, '
821 'const GLenum* attachments' }, 821 'const GLenum* attachments' },
822 ] 822 ]
823 823
824 GL_NULLDRAW_FUNCTIONS = [
825 { 'return_type': 'void',
826 'names': ['glClear'],
827 'arguments': 'GLbitfield mask', },
828 { 'return_type': 'void',
829 'names': ['glDrawArrays'],
830 'arguments': 'GLenum mode, GLint first, GLsizei count', },
831 { 'return_type': 'void',
832 'names': ['glDrawElements'],
833 'arguments':
834 'GLenum mode, GLsizei count, GLenum type, const void* indices', },
835 ]
836
837 OSMESA_FUNCTIONS = [ 824 OSMESA_FUNCTIONS = [
838 { 'return_type': 'OSMesaContext', 825 { 'return_type': 'OSMesaContext',
839 'names': ['OSMesaCreateContext'], 826 'names': ['OSMesaCreateContext'],
840 'arguments': 'GLenum format, OSMesaContext sharelist', }, 827 'arguments': 'GLenum format, OSMesaContext sharelist', },
841 { 'return_type': 'OSMesaContext', 828 { 'return_type': 'OSMesaContext',
842 'names': ['OSMesaCreateContextExt'], 829 'names': ['OSMesaCreateContextExt'],
843 'arguments': 830 'arguments':
844 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' 831 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, '
845 'OSMesaContext sharelist', }, 832 'OSMesaContext sharelist', },
846 { 'return_type': 'void', 833 { 'return_type': 'void',
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, ' 1244 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, '
1258 'int64* sbc' }, 1245 'int64* sbc' },
1259 { 'return_type': 'bool', 1246 { 'return_type': 'bool',
1260 'names': ['glXGetMscRateOML'], 1247 'names': ['glXGetMscRateOML'],
1261 'arguments': 1248 'arguments':
1262 'Display* dpy, GLXDrawable drawable, int32* numerator, ' 1249 'Display* dpy, GLXDrawable drawable, int32* numerator, '
1263 'int32* denominator' }, 1250 'int32* denominator' },
1264 ] 1251 ]
1265 1252
1266 FUNCTION_SETS = [ 1253 FUNCTION_SETS = [
1267 [GL_FUNCTIONS, GL_NULLDRAW_FUNCTIONS, 'gl', [ 1254 [GL_FUNCTIONS, 'gl', [
1268 'GL/glext.h', 1255 'GL/glext.h',
1269 'GLES2/gl2ext.h', 1256 'GLES2/gl2ext.h',
1270 # Files below are Chromium-specific and shipped with Chromium sources. 1257 # Files below are Chromium-specific and shipped with Chromium sources.
1271 'GL/glextchromium.h', 1258 'GL/glextchromium.h',
1272 'GLES2/gl2chromium.h', 1259 'GLES2/gl2chromium.h',
1273 'GLES2/gl2extchromium.h' 1260 'GLES2/gl2extchromium.h'
1274 ], []], 1261 ], []],
1275 [OSMESA_FUNCTIONS, [], 'osmesa', [], []], 1262 [OSMESA_FUNCTIONS, 'osmesa', [], []],
1276 [EGL_FUNCTIONS, [], 'egl', [ 1263 [EGL_FUNCTIONS, 'egl', [
1277 'EGL/eglext.h', 1264 'EGL/eglext.h',
1278 # Files below are Chromium-specific and shipped with Chromium sources. 1265 # Files below are Chromium-specific and shipped with Chromium sources.
1279 'EGL/eglextchromium.h', 1266 'EGL/eglextchromium.h',
1280 ], 1267 ],
1281 [ 1268 [
1282 'EGL_ANGLE_d3d_share_handle_client_buffer', 1269 'EGL_ANGLE_d3d_share_handle_client_buffer',
1283 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', 1270 'EGL_ANGLE_surface_d3d_texture_2d_share_handle',
1284 ], 1271 ],
1285 ], 1272 ],
1286 [WGL_FUNCTIONS, [], 'wgl', ['GL/wglext.h'], []], 1273 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []],
1287 [GLX_FUNCTIONS, [], 'glx', ['GL/glx.h', 'GL/glxext.h'], []], 1274 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []],
1288 ] 1275 ]
1289 1276
1290 def GenerateHeader(file, functions, set_name, used_extensions): 1277 def GenerateHeader(file, functions, set_name, used_extensions):
1291 """Generates gl_bindings_autogen_x.h""" 1278 """Generates gl_bindings_autogen_x.h"""
1292 1279
1293 # Write file header. 1280 # Write file header.
1294 file.write( 1281 file.write(
1295 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1282 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1296 // Use of this source code is governed by a BSD-style license that can be 1283 // Use of this source code is governed by a BSD-style license that can be
1297 // found in the LICENSE file. 1284 // found in the LICENSE file.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 args = '' 1385 args = ''
1399 arg_count = 0 1386 arg_count = 0
1400 if len(args): 1387 if len(args):
1401 arg_count = func['arguments'].count(',') + 1 1388 arg_count = func['arguments'].count(',') + 1
1402 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % 1389 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' %
1403 (arg_count, func['known_as'][2:], func['return_type'], args)) 1390 (arg_count, func['known_as'][2:], func['return_type'], args))
1404 1391
1405 file.write('\n') 1392 file.write('\n')
1406 1393
1407 1394
1408 def GenerateSource( 1395 def GenerateSource(file, functions, set_name, used_extensions):
1409 file, functions, nulldraw_functions, set_name, used_extensions):
1410 """Generates gl_bindings_autogen_x.cc""" 1396 """Generates gl_bindings_autogen_x.cc"""
1411 1397
1412 # Write file header. 1398 # Write file header.
1413 file.write( 1399 file.write(
1414 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. 1400 """// Copyright (c) 2011 The Chromium Authors. All rights reserved.
1415 // Use of this source code is governed by a BSD-style license that can be 1401 // Use of this source code is governed by a BSD-style license that can be
1416 // found in the LICENSE file. 1402 // found in the LICENSE file.
1417 1403
1418 // This file is automatically generated. 1404 // This file is automatically generated.
1419 1405
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 file.write(' debug_fn.%sFn = 0;\n' % func['known_as']) 1546 file.write(' debug_fn.%sFn = 0;\n' % func['known_as'])
1561 WriteConditionalFuncBinding(file, func) 1547 WriteConditionalFuncBinding(file, func)
1562 1548
1563 # Some new function pointers have been added, so update them in debug bindings 1549 # Some new function pointers have been added, so update them in debug bindings
1564 file.write('\n') 1550 file.write('\n')
1565 file.write(' if (g_debugBindingsInitialized)\n') 1551 file.write(' if (g_debugBindingsInitialized)\n')
1566 file.write(' InitializeDebugBindings();\n') 1552 file.write(' InitializeDebugBindings();\n')
1567 file.write('}\n') 1553 file.write('}\n')
1568 file.write('\n') 1554 file.write('\n')
1569 1555
1570 # Write empty stubs for functions that want one.
1571 file.write('extern "C" {\n')
1572 for func in nulldraw_functions:
1573 known_as = func['known_as']
1574 return_type = func['return_type']
1575 arguments = func['arguments']
1576 file.write('\n')
1577 file.write('static %s GL_BINDING_CALL Stub_%s(%s) {}\n' %
1578 (return_type, known_as, arguments))
1579 file.write('} // extern "C"\n')
1580
1581 # Write logging wrappers for each function. 1556 # Write logging wrappers for each function.
1582 file.write('extern "C" {\n') 1557 file.write('extern "C" {\n')
1583 for func in functions: 1558 for func in functions:
1584 return_type = func['return_type'] 1559 return_type = func['return_type']
1585 arguments = func['arguments'] 1560 arguments = func['arguments']
1586 file.write('\n') 1561 file.write('\n')
1587 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % 1562 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' %
1588 (return_type, func['known_as'], arguments)) 1563 (return_type, func['known_as'], arguments))
1589 argument_names = re.sub( 1564 argument_names = re.sub(
1590 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) 1565 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 set_name.upper()) 1624 set_name.upper())
1650 for func in functions: 1625 for func in functions:
1651 first_name = func['known_as'] 1626 first_name = func['known_as']
1652 file.write(' if (!debug_fn.%sFn) {\n' % first_name) 1627 file.write(' if (!debug_fn.%sFn) {\n' % first_name)
1653 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) 1628 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name))
1654 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) 1629 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name))
1655 file.write(' }\n') 1630 file.write(' }\n')
1656 file.write(' g_debugBindingsInitialized = true;\n') 1631 file.write(' g_debugBindingsInitialized = true;\n')
1657 file.write('}\n') 1632 file.write('}\n')
1658 1633
1659 # Write function to initialize the nulldraw function pointers.
1660 if nulldraw_functions:
1661 file.write('\n')
1662 file.write('void Driver%s::InitializeNullDrawBindings() {\n' %
1663 set_name.upper())
1664
1665 for func in nulldraw_functions:
1666 first_name = func['known_as']
1667 file.write(' fn.%sFn = Stub_%s;\n' % (first_name, first_name))
1668 file.write('}\n')
1669
1670 # Write function to clear all function pointers. 1634 # Write function to clear all function pointers.
1671 file.write('\n') 1635 file.write('\n')
1672 file.write("""void Driver%s::ClearBindings() { 1636 file.write("""void Driver%s::ClearBindings() {
1673 memset(this, 0, sizeof(*this)); 1637 memset(this, 0, sizeof(*this));
1674 } 1638 }
1675 """ % set_name.upper()) 1639 """ % set_name.upper())
1676 1640
1677 # Write GLApiBase functions 1641 # Write GLApiBase functions
1678 for func in functions: 1642 for func in functions:
1679 function_name = func['known_as'] 1643 function_name = func['known_as']
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 def main(argv): 1907 def main(argv):
1944 """This is the main function.""" 1908 """This is the main function."""
1945 1909
1946 parser = optparse.OptionParser() 1910 parser = optparse.OptionParser()
1947 parser.add_option('--inputs', action='store_true') 1911 parser.add_option('--inputs', action='store_true')
1948 parser.add_option('--header-paths') 1912 parser.add_option('--header-paths')
1949 1913
1950 options, args = parser.parse_args(argv) 1914 options, args = parser.parse_args(argv)
1951 1915
1952 if options.inputs: 1916 if options.inputs:
1953 for [_, _, _, headers, _] in FUNCTION_SETS: 1917 for [_, _, headers, _] in FUNCTION_SETS:
1954 for header in headers: 1918 for header in headers:
1955 print ResolveHeader(header, options.header_paths) 1919 print ResolveHeader(header, options.header_paths)
1956 return 0 1920 return 0
1957 1921
1958 directory = '.' 1922 directory = '.'
1959 if len(args) >= 1: 1923 if len(args) >= 1:
1960 directory = args[0] 1924 directory = args[0]
1961 1925
1962 for [functions, 1926 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS:
1963 nulldraw_functions,
1964 set_name,
1965 extension_headers,
1966 extensions] in FUNCTION_SETS:
1967 # Function names can be specified in two ways (list of unique names or list 1927 # Function names can be specified in two ways (list of unique names or list
1968 # of versions with different binding conditions). Fill in the data to the 1928 # of versions with different binding conditions). Fill in the data to the
1969 # versions list in case it is missing, so that can be used from here on: 1929 # versions list in case it is missing, so that can be used from here on:
1970 for func in functions + nulldraw_functions: 1930 for func in functions:
1971 assert 'versions' in func or 'names' in func, 'Function with no names' 1931 assert 'versions' in func or 'names' in func, 'Function with no names'
1972 if 'versions' not in func: 1932 if 'versions' not in func:
1973 func['versions'] = [{'name': n} for n in func['names']] 1933 func['versions'] = [{'name': n} for n in func['names']]
1974 # Use the first version's name unless otherwise specified 1934 # Use the first version's name unless otherwise specified
1975 if 'known_as' not in func: 1935 if 'known_as' not in func:
1976 func['known_as'] = func['versions'][0]['name'] 1936 func['known_as'] = func['versions'][0]['name']
1977 # Make sure that 'names' is not accidentally used instead of 'versions' 1937 # Make sure that 'names' is not accidentally used instead of 'versions'
1978 if 'names' in func: 1938 if 'names' in func:
1979 del func['names'] 1939 del func['names']
1980 1940
1981 extension_headers = [ResolveHeader(h, options.header_paths) 1941 extension_headers = [ResolveHeader(h, options.header_paths)
1982 for h in extension_headers] 1942 for h in extension_headers]
1983 used_extensions = FillExtensionsFromHeaders( 1943 used_extensions = FillExtensionsFromHeaders(
1984 functions, extension_headers, extensions) 1944 functions, extension_headers, extensions)
1985 1945
1986 header_file = open( 1946 header_file = open(
1987 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb') 1947 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb')
1988 GenerateHeader(header_file, functions, set_name, used_extensions) 1948 GenerateHeader(header_file, functions, set_name, used_extensions)
1989 header_file.close() 1949 header_file.close()
1990 1950
1991 header_file = open( 1951 header_file = open(
1992 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name), 1952 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name),
1993 'wb') 1953 'wb')
1994 GenerateAPIHeader(header_file, functions, set_name) 1954 GenerateAPIHeader(header_file, functions, set_name)
1995 header_file.close() 1955 header_file.close()
1996 1956
1997 source_file = open( 1957 source_file = open(
1998 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') 1958 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb')
1999 GenerateSource(source_file, 1959 GenerateSource(source_file, functions, set_name, used_extensions)
2000 functions,
2001 nulldraw_functions,
2002 set_name,
2003 used_extensions)
2004 source_file.close() 1960 source_file.close()
2005 1961
2006 header_file = open( 1962 header_file = open(
2007 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb') 1963 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb')
2008 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl') 1964 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl')
2009 header_file.close() 1965 header_file.close()
2010 1966
2011 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'), 1967 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'),
2012 'wb') 1968 'wb')
2013 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS) 1969 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS)
2014 header_file.close() 1970 header_file.close()
2015 1971
2016 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), 1972 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'),
2017 'wb') 1973 'wb')
2018 GenerateMockBindingsSource(source_file, GL_FUNCTIONS) 1974 GenerateMockBindingsSource(source_file, GL_FUNCTIONS)
2019 source_file.close() 1975 source_file.close()
2020 return 0 1976 return 0
2021 1977
2022 1978
2023 if __name__ == '__main__': 1979 if __name__ == '__main__':
2024 sys.exit(main(sys.argv[1:])) 1980 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698