OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """code generator for GL/GLES extension wrangler.""" | 7 """code generator for GL/GLES extension wrangler.""" |
8 | 8 |
9 import os | 9 import os |
10 import collections | 10 import collections |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 [GL_FUNCTIONS, 'gl', ['../../../third_party/mesa/MesaLib/include/GL/glext.h', | 469 [GL_FUNCTIONS, 'gl', ['../../../third_party/mesa/MesaLib/include/GL/glext.h', |
470 '../../../gpu/GLES2/gl2ext.h']], | 470 '../../../gpu/GLES2/gl2ext.h']], |
471 [OSMESA_FUNCTIONS, 'osmesa', []], | 471 [OSMESA_FUNCTIONS, 'osmesa', []], |
472 [EGL_FUNCTIONS, 'egl', ['../../../gpu/EGL/eglext.h']], | 472 [EGL_FUNCTIONS, 'egl', ['../../../gpu/EGL/eglext.h']], |
473 [WGL_FUNCTIONS, 'wgl', [ | 473 [WGL_FUNCTIONS, 'wgl', [ |
474 '../../../third_party/mesa/MesaLib/include/GL/wglext.h']], | 474 '../../../third_party/mesa/MesaLib/include/GL/wglext.h']], |
475 [GLX_FUNCTIONS, 'glx', [ | 475 [GLX_FUNCTIONS, 'glx', [ |
476 '../../../third_party/mesa/MesaLib/include/GL/glxext.h']], | 476 '../../../third_party/mesa/MesaLib/include/GL/glxext.h']], |
477 ] | 477 ] |
478 | 478 |
479 def GenerateHeader(file, functions, set_name): | 479 def GenerateHeader(file, functions, set_name, used_extension_functions): |
480 """Generates gl_binding_autogen_x.h""" | 480 """Generates gl_binding_autogen_x.h""" |
481 | 481 |
482 # Write file header. | 482 # Write file header. |
483 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') | 483 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') |
484 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') | 484 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') |
485 file.write('// found in the LICENSE file.\n') | 485 file.write('// found in the LICENSE file.\n') |
486 file.write('\n') | 486 file.write('\n') |
487 file.write('// This file is automatically generated.\n') | 487 file.write('// This file is automatically generated.\n') |
488 file.write('\n') | 488 file.write('\n') |
489 file.write('#ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % set_name.upper()) | 489 file.write('#ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % set_name.upper()) |
(...skipping 10 matching lines...) Expand all Loading... |
500 set_name.upper()) | 500 set_name.upper()) |
501 file.write('void InitializeDebugGLBindings%s();\n' % set_name.upper()) | 501 file.write('void InitializeDebugGLBindings%s();\n' % set_name.upper()) |
502 | 502 |
503 # Write typedefs for function pointer types. Always use the GL name for the | 503 # Write typedefs for function pointer types. Always use the GL name for the |
504 # typedef. | 504 # typedef. |
505 file.write('\n') | 505 file.write('\n') |
506 for [return_type, names, arguments] in functions: | 506 for [return_type, names, arguments] in functions: |
507 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % | 507 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % |
508 (return_type, names[0], arguments)) | 508 (return_type, names[0], arguments)) |
509 | 509 |
| 510 # Write declarations for booleans indicating which extensions are available. |
| 511 file.write('\n') |
| 512 for extension, ext_functions in used_extension_functions: |
| 513 file.write('GL_EXPORT extern bool g_%s;\n' % extension) |
| 514 |
510 # Write declarations for function pointers. Always use the GL name for the | 515 # Write declarations for function pointers. Always use the GL name for the |
511 # declaration. | 516 # declaration. |
512 file.write('\n') | 517 file.write('\n') |
513 for [return_type, names, arguments] in functions: | 518 for [return_type, names, arguments] in functions: |
514 file.write('GL_EXPORT extern %sProc g_%s;\n' % (names[0], names[0])) | 519 file.write('GL_EXPORT extern %sProc g_%s;\n' % (names[0], names[0])) |
515 file.write('\n') | 520 file.write('\n') |
516 file.write( '} // namespace gfx\n') | 521 file.write( '} // namespace gfx\n') |
517 | 522 |
518 # Write macros to invoke function pointers. Always use the GL name for the | 523 # Write macros to invoke function pointers. Always use the GL name for the |
519 # macro. | 524 # macro. |
(...skipping 14 matching lines...) Expand all Loading... |
534 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') | 539 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') |
535 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') | 540 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') |
536 file.write('// found in the LICENSE file.\n') | 541 file.write('// found in the LICENSE file.\n') |
537 file.write('\n') | 542 file.write('\n') |
538 file.write('// This file is automatically generated.\n') | 543 file.write('// This file is automatically generated.\n') |
539 file.write('\n') | 544 file.write('\n') |
540 file.write('#include "ui/gfx/gl/gl_bindings.h"\n') | 545 file.write('#include "ui/gfx/gl/gl_bindings.h"\n') |
541 file.write('#include "ui/gfx/gl/gl_context.h"\n') | 546 file.write('#include "ui/gfx/gl/gl_context.h"\n') |
542 file.write('#include "ui/gfx/gl/gl_implementation.h"\n') | 547 file.write('#include "ui/gfx/gl/gl_implementation.h"\n') |
543 | 548 |
544 # Write definitions of function pointers. | 549 # Write definitions for booleans indicating which extensions are available. |
545 file.write('\n') | 550 file.write('\n') |
546 file.write('namespace gfx {\n') | 551 file.write('namespace gfx {\n') |
547 file.write('\n') | 552 file.write('\n') |
| 553 for extension, ext_functions in used_extension_functions: |
| 554 file.write('bool g_%s;\n' % extension) |
| 555 |
| 556 # Write definitions of function pointers. |
| 557 file.write('\n') |
548 file.write('static bool g_debugBindingsInitialized;\n') | 558 file.write('static bool g_debugBindingsInitialized;\n') |
549 file.write('static void UpdateDebugGLExtensionBindings();\n') | 559 file.write('static void UpdateDebugGLExtensionBindings();\n') |
550 file.write('\n') | 560 file.write('\n') |
551 for [return_type, names, arguments] in functions: | 561 for [return_type, names, arguments] in functions: |
552 file.write('%sProc g_%s;\n' % (names[0], names[0])) | 562 file.write('%sProc g_%s;\n' % (names[0], names[0])) |
553 | 563 |
554 file.write('\n') | 564 file.write('\n') |
555 for [return_type, names, arguments] in functions: | 565 for [return_type, names, arguments] in functions: |
556 file.write('static %sProc g_debug_%s;\n' % (names[0], names[0])) | 566 file.write('static %sProc g_debug_%s;\n' % (names[0], names[0])) |
557 | 567 |
(...skipping 11 matching lines...) Expand all Loading... |
569 (names[0], names[0], name)) | 579 (names[0], names[0], name)) |
570 file.write('}\n') | 580 file.write('}\n') |
571 file.write('\n') | 581 file.write('\n') |
572 | 582 |
573 # Write function to initialize the extension function pointers. This function | 583 # Write function to initialize the extension function pointers. This function |
574 # uses a current context to query which extensions are actually supported. | 584 # uses a current context to query which extensions are actually supported. |
575 file.write('void InitializeGLExtensionBindings%s(GLContext* context) {\n' % | 585 file.write('void InitializeGLExtensionBindings%s(GLContext* context) {\n' % |
576 set_name.upper()) | 586 set_name.upper()) |
577 file.write(' DCHECK(context && context->IsCurrent(NULL));\n') | 587 file.write(' DCHECK(context && context->IsCurrent(NULL));\n') |
578 for extension, ext_functions in used_extension_functions: | 588 for extension, ext_functions in used_extension_functions: |
579 file.write(' if (context->HasExtension("%s")) {\n' % extension) | 589 file.write(' if ((g_%s = context->HasExtension("%s"))) {\n' % |
| 590 (extension, extension)) |
580 queried_entry_points = set() | 591 queried_entry_points = set() |
581 for entry_point_name, function_name in ext_functions: | 592 for entry_point_name, function_name in ext_functions: |
582 # Replace the pointer unconditionally unless this extension has several | 593 # Replace the pointer unconditionally unless this extension has several |
583 # alternatives for the same entry point (e.g., | 594 # alternatives for the same entry point (e.g., |
584 # GL_ARB_blend_func_extended). | 595 # GL_ARB_blend_func_extended). |
585 if entry_point_name in queried_entry_points: | 596 if entry_point_name in queried_entry_points: |
586 file.write(' if (!g_%s)\n ' % entry_point_name) | 597 file.write(' if (!g_%s)\n ' % entry_point_name) |
587 file.write( | 598 file.write( |
588 ' g_%s = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % | 599 ' g_%s = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % |
589 (entry_point_name, entry_point_name, function_name)) | 600 (entry_point_name, entry_point_name, function_name)) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 840 |
830 def main(argv): | 841 def main(argv): |
831 """This is the main function.""" | 842 """This is the main function.""" |
832 | 843 |
833 if len(argv) >= 1: | 844 if len(argv) >= 1: |
834 dir = argv[0] | 845 dir = argv[0] |
835 else: | 846 else: |
836 dir = '.' | 847 dir = '.' |
837 | 848 |
838 for [functions, set_name, extension_headers] in FUNCTION_SETS: | 849 for [functions, set_name, extension_headers] in FUNCTION_SETS: |
| 850 used_extension_functions = GetUsedExtensionFunctions( |
| 851 functions, extension_headers) |
| 852 |
839 header_file = open( | 853 header_file = open( |
840 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | 854 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') |
841 GenerateHeader(header_file, functions, set_name) | 855 GenerateHeader(header_file, functions, set_name, used_extension_functions) |
842 header_file.close() | 856 header_file.close() |
843 | 857 |
844 source_file = open( | 858 source_file = open( |
845 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | 859 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') |
846 used_extension_functions = GetUsedExtensionFunctions( | |
847 functions, extension_headers) | |
848 GenerateSource(source_file, functions, set_name, used_extension_functions) | 860 GenerateSource(source_file, functions, set_name, used_extension_functions) |
849 source_file.close() | 861 source_file.close() |
850 | 862 |
851 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 863 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
852 GenerateMockSource(source_file, GL_FUNCTIONS) | 864 GenerateMockSource(source_file, GL_FUNCTIONS) |
853 source_file.close() | 865 source_file.close() |
854 | 866 |
855 | 867 |
856 if __name__ == '__main__': | 868 if __name__ == '__main__': |
857 main(sys.argv[1:]) | 869 main(sys.argv[1:]) |
OLD | NEW |