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

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

Issue 1998723002: Move code in ui/gl/* from gfx:: to gl:: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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
« no previous file with comments | « ui/gl/egl_api_unittest.cc ('k') | ui/gl/gl_api_unittest.cc » ('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 optparse
9 import os 9 import os
10 import collections 10 import collections
(...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 used_extensions, used_client_extensions): 1901 used_extensions, used_client_extensions):
1902 """Generates gl_bindings_autogen_x.h""" 1902 """Generates gl_bindings_autogen_x.h"""
1903 1903
1904 # Write file header. 1904 # Write file header.
1905 file.write(LICENSE_AND_HEADER + 1905 file.write(LICENSE_AND_HEADER +
1906 """ 1906 """
1907 1907
1908 #ifndef UI_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ 1908 #ifndef UI_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_
1909 #define UI_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ 1909 #define UI_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_
1910 1910
1911 namespace gfx { 1911 namespace gl {
1912 1912
1913 class GLContext; 1913 class GLContext;
1914 1914
1915 """ % {'name': set_name.upper()}) 1915 """ % {'name': set_name.upper()})
1916 1916
1917 # Write typedefs for function pointer types. Always use the GL name for the 1917 # Write typedefs for function pointer types. Always use the GL name for the
1918 # typedef. 1918 # typedef.
1919 file.write('\n') 1919 file.write('\n')
1920 for func in functions: 1920 for func in functions:
1921 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % 1921 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' %
(...skipping 23 matching lines...) Expand all
1945 %(name)sApi(); 1945 %(name)sApi();
1946 virtual ~%(name)sApi(); 1946 virtual ~%(name)sApi();
1947 1947
1948 """ % {'name': set_name.upper()}) 1948 """ % {'name': set_name.upper()})
1949 for func in functions: 1949 for func in functions:
1950 file.write(' virtual %s %sFn(%s) = 0;\n' % 1950 file.write(' virtual %s %sFn(%s) = 0;\n' %
1951 (func['return_type'], func['known_as'], func['arguments'])) 1951 (func['return_type'], func['known_as'], func['arguments']))
1952 file.write('};\n') 1952 file.write('};\n')
1953 file.write('\n') 1953 file.write('\n')
1954 1954
1955 file.write( '} // namespace gfx\n') 1955 file.write( '} // namespace gl\n')
1956 1956
1957 # Write macros to invoke function pointers. Always use the GL name for the 1957 # Write macros to invoke function pointers. Always use the GL name for the
1958 # macro. 1958 # macro.
1959 file.write('\n') 1959 file.write('\n')
1960 for func in functions: 1960 for func in functions:
1961 file.write('#define %s ::gfx::g_current_%s_context->%sFn\n' % 1961 file.write('#define %s ::gl::g_current_%s_context->%sFn\n' %
1962 (func['known_as'], set_name.lower(), func['known_as'])) 1962 (func['known_as'], set_name.lower(), func['known_as']))
1963 1963
1964 file.write('\n') 1964 file.write('\n')
1965 file.write('#endif // UI_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % 1965 file.write('#endif // UI_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' %
1966 set_name.upper()) 1966 set_name.upper())
1967 1967
1968 1968
1969 def GenerateAPIHeader(file, functions, set_name): 1969 def GenerateAPIHeader(file, functions, set_name):
1970 """Generates gl_bindings_api_autogen_x.h""" 1970 """Generates gl_bindings_api_autogen_x.h"""
1971 1971
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 for h in sorted(include_list)]) 2024 for h in sorted(include_list)])
2025 2025
2026 # Write file header. 2026 # Write file header.
2027 file.write(LICENSE_AND_HEADER + 2027 file.write(LICENSE_AND_HEADER +
2028 """ 2028 """
2029 2029
2030 #include <string> 2030 #include <string>
2031 2031
2032 %s 2032 %s
2033 2033
2034 namespace gfx { 2034 namespace gl {
2035 """ % includes_string) 2035 """ % includes_string)
2036 2036
2037 file.write('\n') 2037 file.write('\n')
2038 file.write('static bool g_debugBindingsInitialized;\n') 2038 file.write('static bool g_debugBindingsInitialized;\n')
2039 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower())) 2039 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower()))
2040 file.write('\n') 2040 file.write('\n')
2041 2041
2042 # Write stub functions that take the place of some functions before a context 2042 # Write stub functions that take the place of some functions before a context
2043 # is initialized. This is done to provide clear asserts on debug build and to 2043 # is initialized. This is done to provide clear asserts on debug build and to
2044 # avoid crashing in case of a bug on release build. 2044 # avoid crashing in case of a bug on release build.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 'GLfloat': '0.0f', 2361 'GLfloat': '0.0f',
2362 'GLdouble': '0.0', 2362 'GLdouble': '0.0',
2363 'GLsync': 'NULL'} 2363 'GLsync': 'NULL'}
2364 if return_type.endswith('*'): 2364 if return_type.endswith('*'):
2365 file.write(' return NULL;\n') 2365 file.write(' return NULL;\n')
2366 elif return_type != 'void': 2366 elif return_type != 'void':
2367 file.write(' return %s;\n' % default_value[return_type]) 2367 file.write(' return %s;\n' % default_value[return_type])
2368 file.write('}\n') 2368 file.write('}\n')
2369 2369
2370 file.write('\n') 2370 file.write('\n')
2371 file.write('} // namespace gfx\n') 2371 file.write('} // namespace gl\n')
2372 2372
2373 2373
2374 def GetUniquelyNamedFunctions(functions): 2374 def GetUniquelyNamedFunctions(functions):
2375 uniquely_named_functions = {} 2375 uniquely_named_functions = {}
2376 2376
2377 for func in functions: 2377 for func in functions:
2378 for version in func['versions']: 2378 for version in func['versions']:
2379 uniquely_named_functions[version['name']] = ({ 2379 uniquely_named_functions[version['name']] = ({
2380 'name': version['name'], 2380 'name': version['name'],
2381 'return_type': func['return_type'], 2381 'return_type': func['return_type'],
(...skipping 19 matching lines...) Expand all
2401 """Generates functions that invoke MockGLInterface members and a 2401 """Generates functions that invoke MockGLInterface members and a
2402 GetGLProcAddress function that returns addresses to those functions.""" 2402 GetGLProcAddress function that returns addresses to those functions."""
2403 2403
2404 file.write(LICENSE_AND_HEADER + 2404 file.write(LICENSE_AND_HEADER +
2405 """ 2405 """
2406 2406
2407 #include <string.h> 2407 #include <string.h>
2408 2408
2409 #include "ui/gl/gl_mock.h" 2409 #include "ui/gl/gl_mock.h"
2410 2410
2411 namespace gfx { 2411 namespace gl {
2412 2412
2413 // This is called mainly to prevent the compiler combining the code of mock 2413 // This is called mainly to prevent the compiler combining the code of mock
2414 // functions with identical contents, so that their function pointers will be 2414 // functions with identical contents, so that their function pointers will be
2415 // different. 2415 // different.
2416 void MakeFunctionUnique(const char *func_name) { 2416 void MakeFunctionUnique(const char *func_name) {
2417 VLOG(2) << "Calling mock " << func_name; 2417 VLOG(2) << "Calling mock " << func_name;
2418 } 2418 }
2419 2419
2420 """) 2420 """)
2421 # Write functions that trampoline into the set MockGLInterface instance. 2421 # Write functions that trampoline into the set MockGLInterface instance.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 'MockGLInterface::GetGLProcAddress(const char* name) {\n') 2455 'MockGLInterface::GetGLProcAddress(const char* name) {\n')
2456 for key in sorted_function_names: 2456 for key in sorted_function_names:
2457 name = uniquely_named_functions[key]['name'] 2457 name = uniquely_named_functions[key]['name']
2458 file.write(' if (strcmp(name, "%s") == 0)\n' % name) 2458 file.write(' if (strcmp(name, "%s") == 0)\n' % name)
2459 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % name) 2459 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % name)
2460 # Always return a non-NULL pointer like some EGL implementations do. 2460 # Always return a non-NULL pointer like some EGL implementations do.
2461 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n') 2461 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n')
2462 file.write('}\n') 2462 file.write('}\n')
2463 2463
2464 file.write('\n') 2464 file.write('\n')
2465 file.write('} // namespace gfx\n') 2465 file.write('} // namespace gl\n')
2466 2466
2467 def GenerateEnumUtils(out_file, input_filenames): 2467 def GenerateEnumUtils(out_file, input_filenames):
2468 enum_re = re.compile(r'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)') 2468 enum_re = re.compile(r'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)')
2469 dict = {} 2469 dict = {}
2470 for fname in input_filenames: 2470 for fname in input_filenames:
2471 lines = open(fname).readlines() 2471 lines = open(fname).readlines()
2472 for line in lines: 2472 for line in lines:
2473 m = enum_re.match(line) 2473 m = enum_re.match(line)
2474 if m: 2474 if m:
2475 name = m.group(1) 2475 name = m.group(1)
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2845 'gl_enums_implementation_autogen.h'), 2845 'gl_enums_implementation_autogen.h'),
2846 'wb') 2846 'wb')
2847 GenerateEnumUtils(header_file, enum_header_filenames) 2847 GenerateEnumUtils(header_file, enum_header_filenames)
2848 header_file.close() 2848 header_file.close()
2849 ClangFormat(header_file.name) 2849 ClangFormat(header_file.name)
2850 return 0 2850 return 0
2851 2851
2852 2852
2853 if __name__ == '__main__': 2853 if __name__ == '__main__':
2854 sys.exit(main(sys.argv[1:])) 2854 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « ui/gl/egl_api_unittest.cc ('k') | ui/gl/gl_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698