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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 'GLbitfield mask, GLenum filter', }, | 79 'GLbitfield mask, GLenum filter', }, |
80 { 'return_type': 'void', | 80 { 'return_type': 'void', |
81 'names': ['glBufferData'], | 81 'names': ['glBufferData'], |
82 'arguments': 'GLenum target, GLsizei size, const void* data, GLenum usage', }, | 82 'arguments': 'GLenum target, GLsizei size, const void* data, GLenum usage', }, |
83 { 'return_type': 'void', | 83 { 'return_type': 'void', |
84 'names': ['glBufferSubData'], | 84 'names': ['glBufferSubData'], |
85 'arguments': 'GLenum target, GLint offset, GLsizei size, const void* data', }, | 85 'arguments': 'GLenum target, GLint offset, GLsizei size, const void* data', }, |
86 { 'return_type': 'GLenum', | 86 { 'return_type': 'GLenum', |
87 'names': ['glCheckFramebufferStatusEXT', | 87 'names': ['glCheckFramebufferStatusEXT', |
88 'glCheckFramebufferStatus'], | 88 'glCheckFramebufferStatus'], |
89 'arguments': 'GLenum target', | 89 'arguments': 'GLenum target', }, |
90 'logging_code': """ | |
91 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringEnum(result)); | |
92 """, }, | |
93 { 'return_type': 'void', | 90 { 'return_type': 'void', |
94 'names': ['glClear'], | 91 'names': ['glClear'], |
95 'arguments': 'GLbitfield mask', }, | 92 'arguments': 'GLbitfield mask', }, |
96 { 'return_type': 'void', | 93 { 'return_type': 'void', |
97 'names': ['glClearColor'], | 94 'names': ['glClearColor'], |
98 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', }, | 95 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', }, |
99 { 'return_type': 'void', | 96 { 'return_type': 'void', |
100 'names': ['glClearDepth'], | 97 'names': ['glClearDepth'], |
101 'arguments': 'GLclampd depth', }, | 98 'arguments': 'GLclampd depth', }, |
102 { 'return_type': 'void', | 99 { 'return_type': 'void', |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 'names': ['glGetAttribLocation'], | 283 'names': ['glGetAttribLocation'], |
287 'arguments': 'GLuint program, const char* name', }, | 284 'arguments': 'GLuint program, const char* name', }, |
288 { 'return_type': 'void', | 285 { 'return_type': 'void', |
289 'names': ['glGetBooleanv'], | 286 'names': ['glGetBooleanv'], |
290 'arguments': 'GLenum pname, GLboolean* params', }, | 287 'arguments': 'GLenum pname, GLboolean* params', }, |
291 { 'return_type': 'void', | 288 { 'return_type': 'void', |
292 'names': ['glGetBufferParameteriv'], | 289 'names': ['glGetBufferParameteriv'], |
293 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | 290 'arguments': 'GLenum target, GLenum pname, GLint* params', }, |
294 { 'return_type': 'GLenum', | 291 { 'return_type': 'GLenum', |
295 'names': ['glGetError'], | 292 'names': ['glGetError'], |
296 'arguments': 'void', | 293 'arguments': 'void', }, |
297 'logging_code': """ | |
298 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringError(result)); | |
299 """, }, | |
300 { 'return_type': 'void', | 294 { 'return_type': 'void', |
301 'names': ['glGetFloatv'], | 295 'names': ['glGetFloatv'], |
302 'arguments': 'GLenum pname, GLfloat* params', }, | 296 'arguments': 'GLenum pname, GLfloat* params', }, |
303 { 'return_type': 'void', | 297 { 'return_type': 'void', |
304 'names': ['glGetFramebufferAttachmentParameterivEXT', | 298 'names': ['glGetFramebufferAttachmentParameterivEXT', |
305 'glGetFramebufferAttachmentParameteriv'], | 299 'glGetFramebufferAttachmentParameteriv'], |
306 'arguments': 'GLenum target, ' | 300 'arguments': 'GLenum target, ' |
307 'GLenum attachment, GLenum pname, GLint* params', }, | 301 'GLenum attachment, GLenum pname, GLint* params', }, |
308 { 'return_type': 'GLenum', | 302 { 'return_type': 'GLenum', |
309 'names': ['glGetGraphicsResetStatusARB', | 303 'names': ['glGetGraphicsResetStatusARB', |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 { 'return_type': 'void', | 499 { 'return_type': 'void', |
506 'names': ['glScissor'], | 500 'names': ['glScissor'], |
507 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', }, | 501 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', }, |
508 { 'return_type': 'void', | 502 { 'return_type': 'void', |
509 'names': ['glShaderBinary'], | 503 'names': ['glShaderBinary'], |
510 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, ' | 504 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, ' |
511 'const void* binary, GLsizei length', }, | 505 'const void* binary, GLsizei length', }, |
512 { 'return_type': 'void', | 506 { 'return_type': 'void', |
513 'names': ['glShaderSource'], | 507 'names': ['glShaderSource'], |
514 'arguments': | 508 'arguments': |
515 'GLuint shader, GLsizei count, const char* const* str, const GLint* length
', | 509 'GLuint shader, GLsizei count, const char* const* str, ' |
516 'logging_code': """ | 510 'const GLint* length', }, |
517 GL_SERVICE_LOG_CODE_BLOCK({ | |
518 for (GLsizei ii = 0; ii < count; ++ii) { | |
519 if (str[ii]) { | |
520 if (length && length[ii] >= 0) { | |
521 std::string source(str[ii], length[ii]); | |
522 GL_SERVICE_LOG(" " << ii << ": ---\\n" << source << "\\n---"); | |
523 } else { | |
524 GL_SERVICE_LOG(" " << ii << ": ---\\n" << str[ii] << "\\n---"); | |
525 } | |
526 } else { | |
527 GL_SERVICE_LOG(" " << ii << ": NULL"); | |
528 } | |
529 } | |
530 }); | |
531 """, }, | |
532 { 'return_type': 'void', | 511 { 'return_type': 'void', |
533 'names': ['glStencilFunc'], | 512 'names': ['glStencilFunc'], |
534 'arguments': 'GLenum func, GLint ref, GLuint mask', }, | 513 'arguments': 'GLenum func, GLint ref, GLuint mask', }, |
535 { 'return_type': 'void', | 514 { 'return_type': 'void', |
536 'names': ['glStencilFuncSeparate'], | 515 'names': ['glStencilFuncSeparate'], |
537 'arguments': 'GLenum face, GLenum func, GLint ref, GLuint mask', }, | 516 'arguments': 'GLenum face, GLenum func, GLint ref, GLuint mask', }, |
538 { 'return_type': 'void', | 517 { 'return_type': 'void', |
539 'names': ['glStencilMask'], | 518 'names': ['glStencilMask'], |
540 'arguments': 'GLuint mask', }, | 519 'arguments': 'GLuint mask', }, |
541 { 'return_type': 'void', | 520 { 'return_type': 'void', |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1195 |
1217 def GenerateHeader(file, functions, set_name, used_extension_functions): | 1196 def GenerateHeader(file, functions, set_name, used_extension_functions): |
1218 """Generates gl_bindings_autogen_x.h""" | 1197 """Generates gl_bindings_autogen_x.h""" |
1219 | 1198 |
1220 # Write file header. | 1199 # Write file header. |
1221 file.write( | 1200 file.write( |
1222 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1201 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1223 // Use of this source code is governed by a BSD-style license that can be | 1202 // Use of this source code is governed by a BSD-style license that can be |
1224 // found in the LICENSE file. | 1203 // found in the LICENSE file. |
1225 | 1204 |
1226 // This file is automatically generated. | 1205 // This file is automatically generated by %(script)s. |
1227 | 1206 |
1228 #ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ | 1207 #ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ |
1229 #define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ | 1208 #define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ |
1230 | 1209 |
1231 namespace gfx { | 1210 namespace gfx { |
1232 | 1211 |
1233 class GLContext; | 1212 class GLContext; |
1234 | 1213 |
1235 """ % {'name': set_name.upper()}) | 1214 """ % {'name': set_name.upper(), 'script': sys.argv[0]}) |
1236 | 1215 |
1237 # Write typedefs for function pointer types. Always use the GL name for the | 1216 # Write typedefs for function pointer types. Always use the GL name for the |
1238 # typedef. | 1217 # typedef. |
1239 file.write('\n') | 1218 file.write('\n') |
1240 for func in functions: | 1219 for func in functions: |
1241 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % | 1220 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % |
1242 (func['return_type'], func['names'][0], func['arguments'])) | 1221 (func['return_type'], func['names'][0], func['arguments'])) |
1243 | 1222 |
1244 # Write declarations for booleans indicating which extensions are available. | 1223 # Write declarations for booleans indicating which extensions are available. |
1245 file.write('\n') | 1224 file.write('\n') |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 #include "ui/gl/gl_implementation.h" | 1355 #include "ui/gl/gl_implementation.h" |
1377 #include "ui/gl/gl_%s_api_implementation.h" | 1356 #include "ui/gl/gl_%s_api_implementation.h" |
1378 | 1357 |
1379 using gpu::gles2::GLES2Util; | 1358 using gpu::gles2::GLES2Util; |
1380 | 1359 |
1381 namespace gfx { | 1360 namespace gfx { |
1382 """ % set_name.lower()) | 1361 """ % set_name.lower()) |
1383 | 1362 |
1384 # Write definitions of function pointers. | 1363 # Write definitions of function pointers. |
1385 file.write('\n') | 1364 file.write('\n') |
1386 file.write('static bool g_debugBindingsInitialized;\n') | |
1387 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower())) | 1365 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower())) |
1388 file.write('\n') | 1366 file.write('\n') |
1389 | 1367 |
1390 # Write function to initialize the core function pointers. The code assumes | 1368 # Write function to initialize the core function pointers. The code assumes |
1391 # any non-NULL pointer returned by GetGLCoreProcAddress() is valid, although | 1369 # any non-NULL pointer returned by GetGLCoreProcAddress() is valid, although |
1392 # it may be overwritten by an extension function pointer later. | 1370 # it may be overwritten by an extension function pointer later. |
1393 file.write('\n') | 1371 file.write('\n') |
1394 file.write('void Driver%s::InitializeBindings() {\n' % | 1372 file.write('void Driver%s::InitializeBindings() {\n' % |
1395 set_name.upper()) | 1373 set_name.upper()) |
1396 for func in functions: | 1374 for func in functions: |
(...skipping 24 matching lines...) Expand all Loading... |
1421 # Replace the pointer unconditionally unless this extension has several | 1399 # Replace the pointer unconditionally unless this extension has several |
1422 # alternatives for the same entry point (e.g., | 1400 # alternatives for the same entry point (e.g., |
1423 # GL_ARB_blend_func_extended). | 1401 # GL_ARB_blend_func_extended). |
1424 if entry_point_name in queried_entry_points: | 1402 if entry_point_name in queried_entry_points: |
1425 file.write(' if (!fn.%sFn)\n ' % entry_point_name) | 1403 file.write(' if (!fn.%sFn)\n ' % entry_point_name) |
1426 file.write( | 1404 file.write( |
1427 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % | 1405 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % |
1428 (entry_point_name, entry_point_name, function_name)) | 1406 (entry_point_name, entry_point_name, function_name)) |
1429 queried_entry_points.add(entry_point_name) | 1407 queried_entry_points.add(entry_point_name) |
1430 file.write(' }\n') | 1408 file.write(' }\n') |
1431 file.write(' if (g_debugBindingsInitialized)\n') | |
1432 file.write(' UpdateDebugExtensionBindings();\n') | |
1433 file.write('}\n') | 1409 file.write('}\n') |
1434 file.write('\n') | 1410 file.write('\n') |
1435 | 1411 |
1436 # Write logging wrappers for each function. | |
1437 file.write('extern "C" {\n') | |
1438 for func in functions: | |
1439 names = func['names'] | |
1440 return_type = func['return_type'] | |
1441 arguments = func['arguments'] | |
1442 file.write('\n') | |
1443 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % | |
1444 (return_type, names[0], arguments)) | |
1445 argument_names = re.sub( | |
1446 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | |
1447 argument_names = re.sub( | |
1448 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | |
1449 log_argument_names = re.sub( | |
1450 r'const char\* ([a-zA-Z0-9_]+)', r'CONSTCHAR_\1', arguments) | |
1451 log_argument_names = re.sub( | |
1452 r'(const )?[a-zA-Z0-9_]+\* ([a-zA-Z0-9_]+)', | |
1453 r'CONSTVOID_\2', log_argument_names) | |
1454 log_argument_names = re.sub( | |
1455 r'(?<!E)GLenum ([a-zA-Z0-9_]+)', r'GLenum_\1', log_argument_names) | |
1456 log_argument_names = re.sub( | |
1457 r'(?<!E)GLboolean ([a-zA-Z0-9_]+)', r'GLboolean_\1', log_argument_names) | |
1458 log_argument_names = re.sub( | |
1459 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', | |
1460 log_argument_names) | |
1461 log_argument_names = re.sub( | |
1462 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', | |
1463 log_argument_names) | |
1464 log_argument_names = re.sub( | |
1465 r'CONSTVOID_([a-zA-Z0-9_]+)', | |
1466 r'static_cast<const void*>(\1)', log_argument_names); | |
1467 log_argument_names = re.sub( | |
1468 r'CONSTCHAR_([a-zA-Z0-9_]+)', r'\1', log_argument_names); | |
1469 log_argument_names = re.sub( | |
1470 r'GLenum_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringEnum(\1)', | |
1471 log_argument_names) | |
1472 log_argument_names = re.sub( | |
1473 r'GLboolean_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringBool(\1)', | |
1474 log_argument_names) | |
1475 log_argument_names = log_argument_names.replace(',', ' << ", " <<') | |
1476 if argument_names == 'void' or argument_names == '': | |
1477 argument_names = '' | |
1478 log_argument_names = '' | |
1479 else: | |
1480 log_argument_names = " << " + log_argument_names | |
1481 function_name = names[0] | |
1482 if return_type == 'void': | |
1483 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % | |
1484 (function_name, log_argument_names)) | |
1485 file.write(' g_driver_%s.debug_fn.%sFn(%s);\n' % | |
1486 (set_name.lower(), function_name, argument_names)) | |
1487 if 'logging_code' in func: | |
1488 file.write("%s\n" % func['logging_code']) | |
1489 else: | |
1490 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % | |
1491 (function_name, log_argument_names)) | |
1492 file.write(' %s result = g_driver_%s.debug_fn.%sFn(%s);\n' % | |
1493 (return_type, set_name.lower(), function_name, argument_names)) | |
1494 if 'logging_code' in func: | |
1495 file.write("%s\n" % func['logging_code']) | |
1496 else: | |
1497 file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n'); | |
1498 file.write(' return result;\n') | |
1499 file.write('}\n') | |
1500 file.write('} // extern "C"\n') | |
1501 | |
1502 # Write function to initialize the debug function pointers. | |
1503 file.write('\n') | |
1504 file.write('void Driver%s::InitializeDebugBindings() {\n' % | |
1505 set_name.upper()) | |
1506 for func in functions: | |
1507 first_name = func['names'][0] | |
1508 file.write(' if (!debug_fn.%sFn) {\n' % first_name) | |
1509 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) | |
1510 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) | |
1511 file.write(' }\n') | |
1512 file.write(' g_debugBindingsInitialized = true;\n') | |
1513 file.write('}\n') | |
1514 | |
1515 # Write function to update the debug function pointers to extension functions | |
1516 # after the extensions have been initialized. | |
1517 file.write('\n') | |
1518 file.write('void Driver%s::UpdateDebugExtensionBindings() {\n' % | |
1519 set_name.upper()) | |
1520 for extension, ext_functions in used_extension_functions: | |
1521 for name, _ in ext_functions: | |
1522 file.write(' if (debug_fn.%sFn != fn.%sFn &&\n' % (name, name)) | |
1523 file.write(' fn.%sFn != Debug_%s) {\n' % (name, name)) | |
1524 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (name, name)) | |
1525 file.write(' fn.%sFn = Debug_%s;\n' % (name, name)) | |
1526 file.write(' }\n') | |
1527 file.write('}\n') | |
1528 | |
1529 # Write function to clear all function pointers. | 1412 # Write function to clear all function pointers. |
1530 file.write('\n') | 1413 file.write('\n') |
1531 file.write("""void Driver%s::ClearBindings() { | 1414 file.write("""void Driver%s::ClearBindings() { |
1532 memset(this, 0, sizeof(*this)); | 1415 memset(this, 0, sizeof(*this)); |
1533 } | 1416 } |
1534 """ % set_name.upper()) | 1417 """ % set_name.upper()) |
1535 | 1418 |
1536 # Write GLApiBase functions | 1419 # Write GLApiBase functions |
1537 for func in functions: | 1420 for func in functions: |
1538 names = func['names'] | 1421 names = func['names'] |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 header_file.close() | 1724 header_file.close() |
1842 | 1725 |
1843 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 1726 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
1844 GenerateMockSource(source_file, GL_FUNCTIONS) | 1727 GenerateMockSource(source_file, GL_FUNCTIONS) |
1845 source_file.close() | 1728 source_file.close() |
1846 return 0 | 1729 return 0 |
1847 | 1730 |
1848 | 1731 |
1849 if __name__ == '__main__': | 1732 if __name__ == '__main__': |
1850 sys.exit(main(sys.argv[1:])) | 1733 sys.exit(main(sys.argv[1:])) |
OLD | NEW |