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 |
11 import re | 11 import re |
12 import sys | 12 import sys |
13 | 13 |
14 """In case there are multiple versions of the same function, one that's listed | |
15 first takes priority if its conditions are met. If the function is an extension | |
16 function, finding the extension from the extension string is a condition for | |
17 binding it. The last version of the function is treated as a fallback option in | |
18 case no other versions were bound, so a non-null function pointer in the | |
19 bindings does not guarantee that the function is supported. | |
20 | |
21 Function binding conditions can be specified manually by supplying a versions | |
22 array instead of the names array. Each version has the following keys: | |
23 name: Mandatory. Name of the function. Multiple versions can have the same | |
24 name but different conditions. | |
25 gl_versions: List of GL versions where the function is found. | |
26 extension/extensions: Extensions where the function is found. If not | |
27 specified, the extensions are determined based on GL | |
28 header files. | |
29 If the function exists in an extension header, you | |
30 may specify an empty array to prevent making that a | |
31 condition for binding. | |
32 """ | |
14 GL_FUNCTIONS = [ | 33 GL_FUNCTIONS = [ |
15 { 'return_type': 'void', | 34 { 'return_type': 'void', |
16 'names': ['glActiveTexture'], | 35 'names': ['glActiveTexture'], |
17 'arguments': 'GLenum texture', }, | 36 'arguments': 'GLenum texture', }, |
18 { 'return_type': 'void', | 37 { 'return_type': 'void', |
19 'names': ['glAttachShader'], | 38 'names': ['glAttachShader'], |
20 'arguments': 'GLuint program, GLuint shader', }, | 39 'arguments': 'GLuint program, GLuint shader', }, |
21 { 'return_type': 'void', | 40 { 'return_type': 'void', |
22 'names': ['glBeginQuery'], | 41 'names': ['glBeginQuery'], |
23 'arguments': 'GLenum target, GLuint id', }, | 42 'arguments': 'GLenum target, GLuint id', }, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 'arguments': 'GLenum target, ' | 325 'arguments': 'GLenum target, ' |
307 'GLenum attachment, GLenum pname, GLint* params', }, | 326 'GLenum attachment, GLenum pname, GLint* params', }, |
308 { 'return_type': 'GLenum', | 327 { 'return_type': 'GLenum', |
309 'names': ['glGetGraphicsResetStatusARB', | 328 'names': ['glGetGraphicsResetStatusARB', |
310 'glGetGraphicsResetStatusEXT'], | 329 'glGetGraphicsResetStatusEXT'], |
311 'arguments': 'void', }, | 330 'arguments': 'void', }, |
312 { 'return_type': 'void', | 331 { 'return_type': 'void', |
313 'names': ['glGetIntegerv'], | 332 'names': ['glGetIntegerv'], |
314 'arguments': 'GLenum pname, GLint* params', }, | 333 'arguments': 'GLenum pname, GLint* params', }, |
315 { 'return_type': 'void', | 334 { 'return_type': 'void', |
316 'names': ['glGetProgramBinary', 'glGetProgramBinaryOES'], | 335 'known_as': 'glGetProgramBinary', |
336 'versions': [{ 'name': 'glGetProgramBinaryOES' }, | |
337 { 'name': 'glGetProgramBinary', | |
338 'extension': 'GL_ARB_get_program_binary' }, | |
339 { 'name': 'glGetProgramBinary' }], | |
317 'arguments': 'GLuint program, GLsizei bufSize, GLsizei* length, ' | 340 'arguments': 'GLuint program, GLsizei bufSize, GLsizei* length, ' |
318 'GLenum* binaryFormat, GLvoid* binary', | 341 'GLenum* binaryFormat, GLvoid* binary' }, |
319 'other_extensions': ['ARB_get_program_binary', | |
320 'OES_get_program_binary'] }, | |
321 { 'return_type': 'void', | 342 { 'return_type': 'void', |
322 'names': ['glGetProgramiv'], | 343 'names': ['glGetProgramiv'], |
323 'arguments': 'GLuint program, GLenum pname, GLint* params', }, | 344 'arguments': 'GLuint program, GLenum pname, GLint* params', }, |
324 { 'return_type': 'void', | 345 { 'return_type': 'void', |
325 'names': ['glGetProgramInfoLog'], | 346 'names': ['glGetProgramInfoLog'], |
326 'arguments': | 347 'arguments': |
327 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', }, | 348 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', }, |
328 { 'return_type': 'void', | 349 { 'return_type': 'void', |
329 'names': ['glGetQueryiv'], | 350 'names': ['glGetQueryiv'], |
330 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | 351 'arguments': 'GLenum target, GLenum pname, GLint* params', }, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 { 'return_type': 'GLboolean', | 449 { 'return_type': 'GLboolean', |
429 'names': ['glIsTexture'], | 450 'names': ['glIsTexture'], |
430 'arguments': 'GLuint texture', }, | 451 'arguments': 'GLuint texture', }, |
431 { 'return_type': 'void', | 452 { 'return_type': 'void', |
432 'names': ['glLineWidth'], | 453 'names': ['glLineWidth'], |
433 'arguments': 'GLfloat width', }, | 454 'arguments': 'GLfloat width', }, |
434 { 'return_type': 'void', | 455 { 'return_type': 'void', |
435 'names': ['glLinkProgram'], | 456 'names': ['glLinkProgram'], |
436 'arguments': 'GLuint program', }, | 457 'arguments': 'GLuint program', }, |
437 { 'return_type': 'void*', | 458 { 'return_type': 'void*', |
438 'names': ['glMapBuffer', 'glMapBufferOES'], | 459 'known_as': 'glMapBuffer', |
460 'names': ['glMapBufferOES', 'glMapBuffer'], | |
439 'arguments': 'GLenum target, GLenum access', }, | 461 'arguments': 'GLenum target, GLenum access', }, |
440 { 'return_type': 'void*', | 462 { 'return_type': 'void*', |
441 'names': ['glMapBufferRange'], | 463 'names': ['glMapBufferRange'], |
442 'arguments': | 464 'arguments': |
443 'GLenum target, GLintptr offset, GLsizeiptr length, GLenum access', }, | 465 'GLenum target, GLintptr offset, GLsizeiptr length, GLenum access', }, |
444 { 'return_type': 'void', | 466 { 'return_type': 'void', |
445 'names': ['glFlushMappedBufferRange'], | 467 'names': ['glFlushMappedBufferRange'], |
446 'arguments': 'GLenum target, GLintptr offset, GLsizeiptr length', }, | 468 'arguments': 'GLenum target, GLintptr offset, GLsizeiptr length', }, |
447 { 'return_type': 'void', | 469 { 'return_type': 'void', |
448 'names': ['glPixelStorei'], | 470 'names': ['glPixelStorei'], |
449 'arguments': 'GLenum pname, GLint param', }, | 471 'arguments': 'GLenum pname, GLint param', }, |
450 { 'return_type': 'void', | 472 { 'return_type': 'void', |
451 'names': ['glPointParameteri'], | 473 'names': ['glPointParameteri'], |
452 'arguments': 'GLenum pname, GLint param', }, | 474 'arguments': 'GLenum pname, GLint param', }, |
453 { 'return_type': 'void', | 475 { 'return_type': 'void', |
454 'names': ['glPolygonOffset'], | 476 'names': ['glPolygonOffset'], |
455 'arguments': 'GLfloat factor, GLfloat units', }, | 477 'arguments': 'GLfloat factor, GLfloat units', }, |
456 { 'return_type': 'void', | 478 { 'return_type': 'void', |
457 'names': ['glProgramBinary', 'glProgramBinaryOES'], | 479 'known_as': 'glProgramBinary', |
480 'versions': [{ 'name': 'glProgramBinaryOES' }, | |
481 { 'name': 'glProgramBinary', | |
482 'extension': 'GL_ARB_get_program_binary' }, | |
483 { 'name': 'glProgramBinary' }], | |
458 'arguments': 'GLuint program, GLenum binaryFormat, ' | 484 'arguments': 'GLuint program, GLenum binaryFormat, ' |
459 'const GLvoid* binary, GLsizei length', | 485 'const GLvoid* binary, GLsizei length' }, |
460 'other_extensions': ['ARB_get_program_binary', | |
461 'OES_get_program_binary'] }, | |
462 { 'return_type': 'void', | 486 { 'return_type': 'void', |
463 'names': ['glProgramParameteri'], | 487 'versions': [{ 'name': 'glProgramParameteri', |
464 'arguments': 'GLuint program, GLenum pname, GLint value', | 488 'extension': 'GL_ARB_get_program_binary' }, |
465 'other_extensions': ['ARB_get_program_binary'] }, | 489 { 'name': 'glProgramParameteri' }], |
490 'arguments': 'GLuint program, GLenum pname, GLint value' }, | |
466 { 'return_type': 'void', | 491 { 'return_type': 'void', |
467 'names': ['glQueryCounter'], | 492 'names': ['glQueryCounter'], |
468 'arguments': 'GLuint id, GLenum target', }, | 493 'arguments': 'GLuint id, GLenum target', }, |
469 { 'return_type': 'void', | 494 { 'return_type': 'void', |
470 'names': ['glReadBuffer'], | 495 'names': ['glReadBuffer'], |
471 'arguments': 'GLenum src', }, | 496 'arguments': 'GLenum src', }, |
472 { 'return_type': 'void', | 497 { 'return_type': 'void', |
473 'names': ['glReadPixels'], | 498 'names': ['glReadPixels'], |
474 'arguments': | 499 'arguments': |
475 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, ' | 500 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, ' |
476 'GLenum type, void* pixels', }, | 501 'GLenum type, void* pixels', }, |
477 { 'return_type': 'void', | 502 { 'return_type': 'void', |
478 'names': ['glReleaseShaderCompiler'], | 503 'names': ['glReleaseShaderCompiler'], |
479 'arguments': 'void', }, | 504 'arguments': 'void', }, |
505 # Multiple definitions of the same function like this cause weirdness in the | |
506 # mock bindings and add overhead. However, some devices perform worse with the | |
507 # ES3 core multisampling compared to an extension, which complicates combining | |
508 # the functions to one. | |
480 { 'return_type': 'void', | 509 { 'return_type': 'void', |
481 'names': ['glRenderbufferStorageMultisample'], | 510 'names': ['glRenderbufferStorageMultisample'], |
482 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, ' | 511 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, ' |
483 'GLsizei width, GLsizei height', }, | 512 'GLsizei width, GLsizei height', }, |
484 { 'return_type': 'void', | 513 { 'return_type': 'void', |
485 'names': ['glRenderbufferStorageMultisampleEXT', | 514 'names': ['glRenderbufferStorageMultisampleEXT', |
486 'glRenderbufferStorageMultisample'], | 515 'glRenderbufferStorageMultisample'], |
487 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, ' | 516 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, ' |
488 'GLsizei width, GLsizei height', }, | 517 'GLsizei width, GLsizei height', }, |
489 { 'return_type': 'void', | 518 { 'return_type': 'void', |
(...skipping 14 matching lines...) Expand all Loading... | |
504 'arguments': 'GLclampf value, GLboolean invert', }, | 533 'arguments': 'GLclampf value, GLboolean invert', }, |
505 { 'return_type': 'void', | 534 { 'return_type': 'void', |
506 'names': ['glScissor'], | 535 'names': ['glScissor'], |
507 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', }, | 536 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', }, |
508 { 'return_type': 'void', | 537 { 'return_type': 'void', |
509 'names': ['glShaderBinary'], | 538 'names': ['glShaderBinary'], |
510 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, ' | 539 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, ' |
511 'const void* binary, GLsizei length', }, | 540 'const void* binary, GLsizei length', }, |
512 { 'return_type': 'void', | 541 { 'return_type': 'void', |
513 'names': ['glShaderSource'], | 542 'names': ['glShaderSource'], |
514 'arguments': | 543 'arguments': 'GLuint shader, GLsizei count, const char* const* str, ' |
515 'GLuint shader, GLsizei count, const char* const* str, const GLint* length ', | 544 'const GLint* length', |
516 'logging_code': """ | 545 'logging_code': """ |
517 GL_SERVICE_LOG_CODE_BLOCK({ | 546 GL_SERVICE_LOG_CODE_BLOCK({ |
518 for (GLsizei ii = 0; ii < count; ++ii) { | 547 for (GLsizei ii = 0; ii < count; ++ii) { |
519 if (str[ii]) { | 548 if (str[ii]) { |
520 if (length && length[ii] >= 0) { | 549 if (length && length[ii] >= 0) { |
521 std::string source(str[ii], length[ii]); | 550 std::string source(str[ii], length[ii]); |
522 GL_SERVICE_LOG(" " << ii << ": ---\\n" << source << "\\n---"); | 551 GL_SERVICE_LOG(" " << ii << ": ---\\n" << source << "\\n---"); |
523 } else { | 552 } else { |
524 GL_SERVICE_LOG(" " << ii << ": ---\\n" << str[ii] << "\\n---"); | 553 GL_SERVICE_LOG(" " << ii << ": ---\\n" << str[ii] << "\\n---"); |
525 } | 554 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 'GLboolean transpose, const GLfloat* value', }, | 658 'GLboolean transpose, const GLfloat* value', }, |
630 { 'return_type': 'void', | 659 { 'return_type': 'void', |
631 'names': ['glUniformMatrix3fv'], | 660 'names': ['glUniformMatrix3fv'], |
632 'arguments': 'GLint location, GLsizei count, ' | 661 'arguments': 'GLint location, GLsizei count, ' |
633 'GLboolean transpose, const GLfloat* value', }, | 662 'GLboolean transpose, const GLfloat* value', }, |
634 { 'return_type': 'void', | 663 { 'return_type': 'void', |
635 'names': ['glUniformMatrix4fv'], | 664 'names': ['glUniformMatrix4fv'], |
636 'arguments': 'GLint location, GLsizei count, ' | 665 'arguments': 'GLint location, GLsizei count, ' |
637 'GLboolean transpose, const GLfloat* value', }, | 666 'GLboolean transpose, const GLfloat* value', }, |
638 { 'return_type': 'GLboolean', | 667 { 'return_type': 'GLboolean', |
639 'names': ['glUnmapBuffer', 'glUnmapBufferOES'], | 668 'known_as': 'glUnmapBuffer', |
669 'names': ['glUnmapBufferOES', 'glUnmapBuffer'], | |
640 'arguments': 'GLenum target', }, | 670 'arguments': 'GLenum target', }, |
641 { 'return_type': 'void', | 671 { 'return_type': 'void', |
642 'names': ['glUseProgram'], | 672 'names': ['glUseProgram'], |
643 'arguments': 'GLuint program', }, | 673 'arguments': 'GLuint program', }, |
644 { 'return_type': 'void', | 674 { 'return_type': 'void', |
645 'names': ['glValidateProgram'], | 675 'names': ['glValidateProgram'], |
646 'arguments': 'GLuint program', }, | 676 'arguments': 'GLuint program', }, |
647 { 'return_type': 'void', | 677 { 'return_type': 'void', |
648 'names': ['glVertexAttrib1f'], | 678 'names': ['glVertexAttrib1f'], |
649 'arguments': 'GLuint indx, GLfloat x', }, | 679 'arguments': 'GLuint indx, GLfloat x', }, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 { 'return_type': 'void', | 735 { 'return_type': 'void', |
706 'names': ['glGetSynciv'], | 736 'names': ['glGetSynciv'], |
707 'arguments': | 737 'arguments': |
708 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,' | 738 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,' |
709 'GLint* values', }, | 739 'GLint* values', }, |
710 { 'return_type': 'GLenum', | 740 { 'return_type': 'GLenum', |
711 'names': ['glClientWaitSync'], | 741 'names': ['glClientWaitSync'], |
712 'arguments': | 742 'arguments': |
713 'GLsync sync, GLbitfield flags, GLuint64 timeout', }, | 743 'GLsync sync, GLbitfield flags, GLuint64 timeout', }, |
714 { 'return_type': 'void', | 744 { 'return_type': 'void', |
715 'names': ['glDrawArraysInstancedANGLE', 'glDrawArraysInstancedARB'], | 745 'known_as': 'glDrawArraysInstancedANGLE', |
746 'names': ['glDrawArraysInstancedARB', 'glDrawArraysInstancedANGLE'], | |
716 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', }, | 747 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', }, |
717 { 'return_type': 'void', | 748 { 'return_type': 'void', |
718 'names': ['glDrawElementsInstancedANGLE', 'glDrawElementsInstancedARB'], | 749 'known_as': 'glDrawElementsInstancedANGLE', |
750 'names': ['glDrawElementsInstancedARB', 'glDrawElementsInstancedANGLE'], | |
719 'arguments': | 751 'arguments': |
720 'GLenum mode, GLsizei count, GLenum type, const void* indices, ' | 752 'GLenum mode, GLsizei count, GLenum type, const void* indices, ' |
721 'GLsizei primcount', }, | 753 'GLsizei primcount', }, |
722 { 'return_type': 'void', | 754 { 'return_type': 'void', |
723 'names': ['glVertexAttribDivisorANGLE', 'glVertexAttribDivisorARB'], | 755 'known_as': 'glVertexAttribDivisorANGLE', |
756 'names': ['glVertexAttribDivisorARB', 'glVertexAttribDivisorANGLE'], | |
724 'arguments': | 757 'arguments': |
725 'GLuint index, GLuint divisor', }, | 758 'GLuint index, GLuint divisor', }, |
726 { 'return_type': 'void', | 759 { 'return_type': 'void', |
727 'names': ['glGenVertexArraysOES', | 760 'known_as': 'glGenVertexArraysOES', |
728 'glGenVertexArraysAPPLE', | 761 'versions': [{ 'name': 'glGenVertexArrays', |
729 'glGenVertexArrays'], | 762 'gl_versions': ['gl3', 'gl4'] }, |
730 'arguments': 'GLsizei n, GLuint* arrays', | 763 { 'name': 'glGenVertexArrays', |
731 'other_extensions': ['OES_vertex_array_object', | 764 'extension': 'GL_ARB_vertex_array_object' }, |
732 'APPLE_vertex_array_object', | 765 { 'name': 'glGenVertexArraysOES' }, |
733 'ARB_vertex_array_object'] }, | 766 { 'name': 'glGenVertexArraysAPPLE', |
767 'extension': 'GL_APPLE_vertex_array_object' }], | |
768 'arguments': 'GLsizei n, GLuint* arrays', }, | |
734 { 'return_type': 'void', | 769 { 'return_type': 'void', |
735 'names': ['glDeleteVertexArraysOES', | 770 'known_as': 'glDeleteVertexArraysOES', |
736 'glDeleteVertexArraysAPPLE', | 771 'versions': [{ 'name': 'glDeleteVertexArrays', |
737 'glDeleteVertexArrays'], | 772 'gl_versions': ['gl3', 'gl4'] }, |
738 'arguments': 'GLsizei n, const GLuint* arrays', | 773 { 'name': 'glDeleteVertexArrays', |
739 'other_extensions': ['OES_vertex_array_object', | 774 'extension': 'GL_ARB_vertex_array_object' }, |
740 'APPLE_vertex_array_object', | 775 { 'name': 'glDeleteVertexArraysOES' }, |
741 'ARB_vertex_array_object'] }, | 776 { 'name': 'glDeleteVertexArraysAPPLE', |
777 'extension': 'GL_APPLE_vertex_array_object' }], | |
778 'arguments': 'GLsizei n, const GLuint* arrays' }, | |
742 { 'return_type': 'void', | 779 { 'return_type': 'void', |
743 'names': ['glBindVertexArrayOES', | 780 'known_as': 'glBindVertexArrayOES', |
744 'glBindVertexArrayAPPLE', | 781 'versions': [{ 'name': 'glBindVertexArray', |
745 'glBindVertexArray'], | 782 'gl_versions': ['gl3', 'gl4'] }, |
746 'arguments': 'GLuint array', | 783 { 'name': 'glBindVertexArray', |
747 'other_extensions': ['OES_vertex_array_object', | 784 'extension': 'GL_ARB_vertex_array_object' }, |
748 'APPLE_vertex_array_object', | 785 { 'name': 'glBindVertexArrayOES' }, |
749 'ARB_vertex_array_object'] }, | 786 { 'name': 'glBindVertexArrayAPPLE', |
787 'extension': 'GL_APPLE_vertex_array_object' }], | |
788 'arguments': 'GLuint array' }, | |
750 { 'return_type': 'GLboolean', | 789 { 'return_type': 'GLboolean', |
751 'names': ['glIsVertexArrayOES', | 790 'known_as': 'glIsVertexArrayOES', |
752 'glIsVertexArrayAPPLE', | 791 'versions': [{ 'name': 'glIsVertexArray', |
753 'glIsVertexArray'], | 792 'gl_versions': ['gl3', 'gl4'] }, |
754 'arguments': 'GLuint array', | 793 { 'name': 'glIsVertexArray', |
755 'other_extensions': ['OES_vertex_array_object', | 794 'extension': 'GL_ARB_vertex_array_object' }, |
756 'APPLE_vertex_array_object', | 795 { 'name': 'glIsVertexArrayOES' }, |
757 'ARB_vertex_array_object'] }, | 796 { 'name': 'glIsVertexArrayAPPLE', |
797 'extension': 'GL_APPLE_vertex_array_object' }], | |
798 'arguments': 'GLuint array' }, | |
758 { 'return_type': 'void', | 799 { 'return_type': 'void', |
759 'names': ['glDiscardFramebufferEXT', 'glInvalidateFramebuffer'], | 800 'known_as': 'glDiscardFramebufferEXT', |
801 'versions': [{ 'name': 'glInvalidateFramebuffer', | |
802 'gl_versions': ['es3'], | |
803 'extensions': [] }, | |
804 { 'name': 'glDiscardFramebufferEXT', | |
805 'gl_versions': ['es1', 'es2'] }], | |
760 'arguments': 'GLenum target, GLsizei numAttachments, ' | 806 'arguments': 'GLenum target, GLsizei numAttachments, ' |
761 'const GLenum* attachments' }, | 807 'const GLenum* attachments' }, |
762 ] | 808 ] |
763 | 809 |
764 OSMESA_FUNCTIONS = [ | 810 OSMESA_FUNCTIONS = [ |
765 { 'return_type': 'OSMesaContext', | 811 { 'return_type': 'OSMesaContext', |
766 'names': ['OSMesaCreateContext'], | 812 'names': ['OSMesaCreateContext'], |
767 'arguments': 'GLenum format, OSMesaContext sharelist', }, | 813 'arguments': 'GLenum format, OSMesaContext sharelist', }, |
768 { 'return_type': 'OSMesaContext', | 814 { 'return_type': 'OSMesaContext', |
769 'names': ['OSMesaCreateContextExt'], | 815 'names': ['OSMesaCreateContextExt'], |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 'EGLint* num_config', }, | 871 'EGLint* num_config', }, |
826 { 'return_type': 'EGLBoolean', | 872 { 'return_type': 'EGLBoolean', |
827 'names': ['eglChooseConfig'], | 873 'names': ['eglChooseConfig'], |
828 'arguments': 'EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, ' | 874 'arguments': 'EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, ' |
829 'EGLint config_size, EGLint* num_config', }, | 875 'EGLint config_size, EGLint* num_config', }, |
830 { 'return_type': 'EGLBoolean', | 876 { 'return_type': 'EGLBoolean', |
831 'names': ['eglGetConfigAttrib'], | 877 'names': ['eglGetConfigAttrib'], |
832 'arguments': | 878 'arguments': |
833 'EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value', }, | 879 'EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value', }, |
834 { 'return_type': 'EGLImageKHR', | 880 { 'return_type': 'EGLImageKHR', |
835 'names': ['eglCreateImageKHR'], | 881 'versions': [{ 'name': 'eglCreateImageKHR', |
882 'extension': 'EGL_KHR_image_base' }], | |
836 'arguments': | 883 'arguments': |
837 'EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, ' | 884 'EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, ' |
838 'const EGLint* attrib_list', | 885 'const EGLint* attrib_list' }, |
839 'other_extensions': ['EGL_KHR_image_base'] }, | |
840 { 'return_type': 'EGLBoolean', | 886 { 'return_type': 'EGLBoolean', |
841 'names': ['eglDestroyImageKHR'], | 887 'versions': [{ 'name' : 'eglDestroyImageKHR', |
842 'arguments': 'EGLDisplay dpy, EGLImageKHR image', | 888 'extension': 'EGL_KHR_image_base' }], |
843 'other_extensions': ['EGL_KHR_image_base'] }, | 889 'arguments': 'EGLDisplay dpy, EGLImageKHR image' }, |
844 { 'return_type': 'EGLSurface', | 890 { 'return_type': 'EGLSurface', |
845 'names': ['eglCreateWindowSurface'], | 891 'names': ['eglCreateWindowSurface'], |
846 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, ' | 892 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, ' |
847 'const EGLint* attrib_list', }, | 893 'const EGLint* attrib_list', }, |
848 { 'return_type': 'EGLSurface', | 894 { 'return_type': 'EGLSurface', |
849 'names': ['eglCreatePbufferSurface'], | 895 'names': ['eglCreatePbufferSurface'], |
850 'arguments': 'EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list', }, | 896 'arguments': 'EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list', }, |
851 { 'return_type': 'EGLSurface', | 897 { 'return_type': 'EGLSurface', |
852 'names': ['eglCreatePixmapSurface'], | 898 'names': ['eglCreatePixmapSurface'], |
853 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, ' | 899 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, ' |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 'arguments': 'const char* procname', }, | 977 'arguments': 'const char* procname', }, |
932 { 'return_type': 'EGLBoolean', | 978 { 'return_type': 'EGLBoolean', |
933 'names': ['eglPostSubBufferNV'], | 979 'names': ['eglPostSubBufferNV'], |
934 'arguments': 'EGLDisplay dpy, EGLSurface surface, ' | 980 'arguments': 'EGLDisplay dpy, EGLSurface surface, ' |
935 'EGLint x, EGLint y, EGLint width, EGLint height', }, | 981 'EGLint x, EGLint y, EGLint width, EGLint height', }, |
936 { 'return_type': 'EGLBoolean', | 982 { 'return_type': 'EGLBoolean', |
937 'names': ['eglQuerySurfacePointerANGLE'], | 983 'names': ['eglQuerySurfacePointerANGLE'], |
938 'arguments': | 984 'arguments': |
939 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, void** value', }, | 985 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, void** value', }, |
940 { 'return_type': 'EGLSyncKHR', | 986 { 'return_type': 'EGLSyncKHR', |
941 'names': ['eglCreateSyncKHR'], | 987 'versions': [{ 'name': 'eglCreateSyncKHR', |
942 'arguments': 'EGLDisplay dpy, EGLenum type, const EGLint* attrib_list', | 988 'extension': 'EGL_KHR_fence_sync' }], |
943 'other_extensions': ['EGL_KHR_fence_sync'] }, | 989 'arguments': 'EGLDisplay dpy, EGLenum type, const EGLint* attrib_list' }, |
944 { 'return_type': 'EGLint', | 990 { 'return_type': 'EGLint', |
945 'names': ['eglClientWaitSyncKHR'], | 991 'versions': [{ 'name': 'eglClientWaitSyncKHR', |
992 'extension': 'EGL_KHR_fence_sync' }], | |
946 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, ' | 993 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, ' |
947 'EGLTimeKHR timeout', | 994 'EGLTimeKHR timeout' }, |
948 'other_extensions': ['EGL_KHR_fence_sync'] }, | |
949 { 'return_type': 'EGLBoolean', | 995 { 'return_type': 'EGLBoolean', |
950 'names': ['eglGetSyncAttribKHR'], | 996 'versions': [{ 'name': 'eglGetSyncAttribKHR', |
997 'extension': 'EGL_KHR_fence_sync' }], | |
951 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, ' | 998 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, ' |
952 'EGLint* value', | 999 'EGLint* value' }, |
953 'other_extensions': ['EGL_KHR_fence_sync'] }, | |
954 { 'return_type': 'EGLBoolean', | 1000 { 'return_type': 'EGLBoolean', |
955 'names': ['eglDestroySyncKHR'], | 1001 'versions': [{ 'name': 'eglDestroySyncKHR', |
956 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync', | 1002 'extension': 'EGL_KHR_fence_sync' }], |
957 'other_extensions': ['EGL_KHR_fence_sync'] }, | 1003 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync' }, |
958 { 'return_type': 'EGLBoolean', | 1004 { 'return_type': 'EGLBoolean', |
959 'names': ['eglGetSyncValuesCHROMIUM'], | 1005 'names': ['eglGetSyncValuesCHROMIUM'], |
960 'arguments': | 1006 'arguments': |
961 'EGLDisplay dpy, EGLSurface surface, ' | 1007 'EGLDisplay dpy, EGLSurface surface, ' |
962 'EGLuint64CHROMIUM* ust, EGLuint64CHROMIUM* msc, ' | 1008 'EGLuint64CHROMIUM* ust, EGLuint64CHROMIUM* msc, ' |
963 'EGLuint64CHROMIUM* sbc', }, | 1009 'EGLuint64CHROMIUM* sbc', }, |
964 { 'return_type': 'EGLint', | 1010 { 'return_type': 'EGLint', |
965 'names': ['eglWaitSyncKHR'], | 1011 'versions': [{ 'name': 'eglWaitSyncKHR', |
966 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags', | 1012 'extension': 'EGL_KHR_fence_sync' }], |
967 'other_extensions': ['EGL_KHR_wait_sync'] }, | 1013 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags' } |
968 ] | 1014 ] |
969 | 1015 |
970 WGL_FUNCTIONS = [ | 1016 WGL_FUNCTIONS = [ |
971 { 'return_type': 'HGLRC', | 1017 { 'return_type': 'HGLRC', |
972 'names': ['wglCreateContext'], | 1018 'names': ['wglCreateContext'], |
973 'arguments': 'HDC hdc', }, | 1019 'arguments': 'HDC hdc', }, |
974 { 'return_type': 'HGLRC', | 1020 { 'return_type': 'HGLRC', |
975 'names': ['wglCreateLayerContext'], | 1021 'names': ['wglCreateLayerContext'], |
976 'arguments': 'HDC hdc, int iLayerPlane', }, | 1022 'arguments': 'HDC hdc, int iLayerPlane', }, |
977 { 'return_type': 'BOOL', | 1023 { 'return_type': 'BOOL', |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1207 ], | 1253 ], |
1208 [ | 1254 [ |
1209 'EGL_ANGLE_d3d_share_handle_client_buffer', | 1255 'EGL_ANGLE_d3d_share_handle_client_buffer', |
1210 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', | 1256 'EGL_ANGLE_surface_d3d_texture_2d_share_handle', |
1211 ], | 1257 ], |
1212 ], | 1258 ], |
1213 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []], | 1259 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []], |
1214 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []], | 1260 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []], |
1215 ] | 1261 ] |
1216 | 1262 |
1217 def GenerateHeader(file, functions, set_name, used_extension_functions): | 1263 def GenerateHeader(file, functions, set_name, used_extensions): |
1218 """Generates gl_bindings_autogen_x.h""" | 1264 """Generates gl_bindings_autogen_x.h""" |
1219 | 1265 |
1220 # Write file header. | 1266 # Write file header. |
1221 file.write( | 1267 file.write( |
1222 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1268 """// 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 | 1269 // Use of this source code is governed by a BSD-style license that can be |
1224 // found in the LICENSE file. | 1270 // found in the LICENSE file. |
1225 | 1271 |
1226 // This file is automatically generated. | 1272 // This file is automatically generated. |
1227 | 1273 |
1228 #ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ | 1274 #ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ |
1229 #define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ | 1275 #define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_ |
1230 | 1276 |
1231 namespace gfx { | 1277 namespace gfx { |
1232 | 1278 |
1233 class GLContext; | 1279 class GLContext; |
1234 | 1280 |
1235 """ % {'name': set_name.upper()}) | 1281 """ % {'name': set_name.upper()}) |
1236 | 1282 |
1237 # Write typedefs for function pointer types. Always use the GL name for the | 1283 # Write typedefs for function pointer types. Always use the GL name for the |
1238 # typedef. | 1284 # typedef. |
1239 file.write('\n') | 1285 file.write('\n') |
1240 for func in functions: | 1286 for func in functions: |
1241 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % | 1287 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % |
1242 (func['return_type'], func['names'][0], func['arguments'])) | 1288 (func['return_type'], func['known_as'], func['arguments'])) |
1243 | 1289 |
1244 # Write declarations for booleans indicating which extensions are available. | 1290 # Write declarations for booleans indicating which extensions are available. |
1245 file.write('\n') | 1291 file.write('\n') |
1246 file.write("struct Extensions%s {\n" % set_name.upper()) | 1292 file.write("struct Extensions%s {\n" % set_name.upper()) |
1247 for extension, ext_functions in used_extension_functions: | 1293 for extension in used_extensions: |
1248 file.write(' bool b_%s;\n' % extension) | 1294 file.write(' bool b_%s;\n' % extension) |
1249 file.write('};\n') | 1295 file.write('};\n') |
1250 file.write('\n') | 1296 file.write('\n') |
1251 | 1297 |
1252 # Write Procs struct. | 1298 # Write Procs struct. |
1253 file.write("struct Procs%s {\n" % set_name.upper()) | 1299 file.write("struct Procs%s {\n" % set_name.upper()) |
1254 for func in functions: | 1300 for func in functions: |
1255 file.write(' %sProc %sFn;\n' % (func['names'][0], func['names'][0])) | 1301 file.write(' %sProc %sFn;\n' % (func['known_as'], func['known_as'])) |
1256 file.write('};\n') | 1302 file.write('};\n') |
1257 file.write('\n') | 1303 file.write('\n') |
1258 | 1304 |
1259 # Write Api class. | 1305 # Write Api class. |
1260 file.write( | 1306 file.write( |
1261 """class GL_EXPORT %(name)sApi { | 1307 """class GL_EXPORT %(name)sApi { |
1262 public: | 1308 public: |
1263 %(name)sApi(); | 1309 %(name)sApi(); |
1264 virtual ~%(name)sApi(); | 1310 virtual ~%(name)sApi(); |
1265 | 1311 |
1266 """ % {'name': set_name.upper()}) | 1312 """ % {'name': set_name.upper()}) |
1267 for func in functions: | 1313 for func in functions: |
1268 file.write(' virtual %s %sFn(%s) = 0;\n' % | 1314 file.write(' virtual %s %sFn(%s) = 0;\n' % |
1269 (func['return_type'], func['names'][0], func['arguments'])) | 1315 (func['return_type'], func['known_as'], func['arguments'])) |
1270 file.write('};\n') | 1316 file.write('};\n') |
1271 file.write('\n') | 1317 file.write('\n') |
1272 | 1318 |
1273 file.write( '} // namespace gfx\n') | 1319 file.write( '} // namespace gfx\n') |
1274 | 1320 |
1275 # Write macros to invoke function pointers. Always use the GL name for the | 1321 # Write macros to invoke function pointers. Always use the GL name for the |
1276 # macro. | 1322 # macro. |
1277 file.write('\n') | 1323 file.write('\n') |
1278 for func in functions: | 1324 for func in functions: |
1279 file.write('#define %s ::gfx::g_current_%s_context->%sFn\n' % | 1325 file.write('#define %s ::gfx::g_current_%s_context->%sFn\n' % |
1280 (func['names'][0], set_name.lower(), func['names'][0])) | 1326 (func['known_as'], set_name.lower(), func['known_as'])) |
1281 | 1327 |
1282 file.write('\n') | 1328 file.write('\n') |
1283 file.write('#endif // UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % | 1329 file.write('#endif // UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % |
1284 set_name.upper()) | 1330 set_name.upper()) |
1285 | 1331 |
1286 | 1332 |
1287 def GenerateAPIHeader(file, functions, set_name, used_extension_functions): | 1333 def GenerateAPIHeader(file, functions, set_name): |
1288 """Generates gl_bindings_api_autogen_x.h""" | 1334 """Generates gl_bindings_api_autogen_x.h""" |
1289 | 1335 |
1290 # Write file header. | 1336 # Write file header. |
1291 file.write( | 1337 file.write( |
1292 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1338 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1293 // Use of this source code is governed by a BSD-style license that can be | 1339 // Use of this source code is governed by a BSD-style license that can be |
1294 // found in the LICENSE file. | 1340 // found in the LICENSE file. |
1295 | 1341 |
1296 // This file is automatically generated. | 1342 // This file is automatically generated. |
1297 | 1343 |
1298 """ % {'name': set_name.upper()}) | 1344 """ % {'name': set_name.upper()}) |
1299 | 1345 |
1300 # Write API declaration. | 1346 # Write API declaration. |
1301 for func in functions: | 1347 for func in functions: |
1302 file.write(' virtual %s %sFn(%s) OVERRIDE;\n' % | 1348 file.write(' virtual %s %sFn(%s) OVERRIDE;\n' % |
1303 (func['return_type'], func['names'][0], func['arguments'])) | 1349 (func['return_type'], func['known_as'], func['arguments'])) |
1304 | 1350 |
1305 file.write('\n') | 1351 file.write('\n') |
1306 | 1352 |
1307 | 1353 |
1308 def GenerateMockHeader(file, functions, set_name, used_extension_functions): | 1354 def GenerateMockHeader(file, functions, set_name): |
1309 """Generates gl_mock_autogen_x.h""" | 1355 """Generates gl_mock_autogen_x.h""" |
1310 | 1356 |
1311 # Write file header. | 1357 # Write file header. |
1312 file.write( | 1358 file.write( |
1313 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1359 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1314 // Use of this source code is governed by a BSD-style license that can be | 1360 // Use of this source code is governed by a BSD-style license that can be |
1315 // found in the LICENSE file. | 1361 // found in the LICENSE file. |
1316 | 1362 |
1317 // This file is automatically generated. | 1363 // This file is automatically generated. |
1318 | 1364 |
1319 """ % {'name': set_name.upper()}) | 1365 """ % {'name': set_name.upper()}) |
1320 | 1366 |
1321 # Write API declaration. | 1367 # Write API declaration. |
1322 for func in functions: | 1368 for func in functions: |
1323 args = func['arguments'] | 1369 args = func['arguments'] |
1324 if args == 'void': | 1370 if args == 'void': |
1325 args = '' | 1371 args = '' |
1326 arg_count = 0 | 1372 arg_count = 0 |
1327 if len(args): | 1373 if len(args): |
1328 arg_count = func['arguments'].count(',') + 1 | 1374 arg_count = func['arguments'].count(',') + 1 |
1329 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % | 1375 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' % |
1330 (arg_count, func['names'][0][2:], func['return_type'], args)) | 1376 (arg_count, func['known_as'][2:], func['return_type'], args)) |
1331 | 1377 |
1332 file.write('\n') | 1378 file.write('\n') |
1333 | 1379 |
1334 | 1380 |
1335 def GenerateInterfaceHeader( | 1381 def GenerateInterfaceHeader(file, functions, set_name): |
1336 file, functions, set_name, used_extension_functions): | |
1337 """Generates gl_interface_autogen_x.h""" | 1382 """Generates gl_interface_autogen_x.h""" |
1338 | 1383 |
1339 # Write file header. | 1384 # Write file header. |
1340 file.write( | 1385 file.write( |
1341 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1386 """// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1342 // Use of this source code is governed by a BSD-style license that can be | 1387 // Use of this source code is governed by a BSD-style license that can be |
1343 // found in the LICENSE file. | 1388 // found in the LICENSE file. |
1344 | 1389 |
1345 // This file is automatically generated. | 1390 // This file is automatically generated. |
1346 | 1391 |
1347 """ % {'name': set_name.upper()}) | 1392 """ % {'name': set_name.upper()}) |
1348 | 1393 |
1349 # Write API declaration. | 1394 # Write API declaration. |
1350 for func in functions: | 1395 for func in functions: |
1351 args = func['arguments'] | 1396 args = func['arguments'] |
1352 if args == 'void': | 1397 if args == 'void': |
1353 args = '' | 1398 args = '' |
1354 file.write(' virtual %s %s(%s) = 0;\n' % | 1399 file.write(' virtual %s %s(%s) = 0;\n' % |
1355 (func['return_type'], func['names'][0][2:], args)) | 1400 (func['return_type'], func['known_as'][2:], args)) |
1356 | 1401 |
1357 file.write('\n') | 1402 file.write('\n') |
1358 | 1403 |
1359 | 1404 |
1360 def GenerateSource(file, functions, set_name, used_extension_functions): | 1405 def GenerateSource(file, functions, set_name, used_extensions): |
1361 """Generates gl_bindings_autogen_x.cc""" | 1406 """Generates gl_bindings_autogen_x.cc""" |
1362 | 1407 |
1363 # Write file header. | 1408 # Write file header. |
1364 file.write( | 1409 file.write( |
1365 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1410 """// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
1366 // Use of this source code is governed by a BSD-style license that can be | 1411 // Use of this source code is governed by a BSD-style license that can be |
1367 // found in the LICENSE file. | 1412 // found in the LICENSE file. |
1368 | 1413 |
1369 // This file is automatically generated. | 1414 // This file is automatically generated. |
1370 | 1415 |
1371 #include <string> | 1416 #include <string> |
1372 #include "base/debug/trace_event.h" | 1417 #include "base/debug/trace_event.h" |
1373 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 1418 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
1374 #include "ui/gl/gl_bindings.h" | 1419 #include "ui/gl/gl_bindings.h" |
1375 #include "ui/gl/gl_context.h" | 1420 #include "ui/gl/gl_context.h" |
1376 #include "ui/gl/gl_implementation.h" | 1421 #include "ui/gl/gl_implementation.h" |
1422 #include "ui/gl/gl_version_info.h" | |
1377 #include "ui/gl/gl_%s_api_implementation.h" | 1423 #include "ui/gl/gl_%s_api_implementation.h" |
1378 | 1424 |
1379 using gpu::gles2::GLES2Util; | 1425 using gpu::gles2::GLES2Util; |
1380 | 1426 |
1381 namespace gfx { | 1427 namespace gfx { |
1382 """ % set_name.lower()) | 1428 """ % set_name.lower()) |
1383 | 1429 |
1384 # Write definitions of function pointers. | 1430 # Write definitions of function pointers. |
1385 file.write('\n') | 1431 file.write('\n') |
1386 file.write('static bool g_debugBindingsInitialized;\n') | 1432 file.write('static bool g_debugBindingsInitialized;\n') |
1387 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower())) | 1433 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower())) |
1388 file.write('\n') | 1434 file.write('\n') |
1389 | 1435 |
1390 # Write function to initialize the core function pointers. The code assumes | 1436 # Write function to initialize the function pointers that are always the same. |
1391 # any non-NULL pointer returned by GetGLCoreProcAddress() is valid, although | |
1392 # it may be overwritten by an extension function pointer later. | |
1393 file.write('\n') | 1437 file.write('\n') |
1394 file.write('void Driver%s::InitializeBindings() {\n' % | 1438 file.write('void Driver%s::InitializeStaticBindings() {\n' % |
1395 set_name.upper()) | 1439 set_name.upper()) |
1440 | |
1441 def WriteFuncBinding(file, known_as, version_name): | |
1442 file.write( | |
1443 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % | |
1444 (known_as, known_as, version_name)) | |
1445 | |
1396 for func in functions: | 1446 for func in functions: |
1397 first_name = func['names'][0] | 1447 if len(func['names']) == 1: |
1398 for i, name in enumerate(func['names']): | 1448 WriteFuncBinding(file, func['known_as'], func['known_as']) |
1399 if i: | 1449 |
1400 file.write(' if (!fn.%sFn)\n ' % first_name) | |
1401 file.write( | |
1402 ' fn.%sFn = reinterpret_cast<%sProc>(' | |
1403 'GetGLCoreProcAddress("%s"));\n' % | |
1404 (first_name, first_name, name)) | |
1405 file.write('}\n') | 1450 file.write('}\n') |
1406 file.write('\n') | 1451 file.write('\n') |
1407 | 1452 |
1408 # Write function to initialize the extension function pointers. This function | 1453 # Write function to initialize bindings where choice of the function depends |
1409 # uses a current context to query which extensions are actually supported. | 1454 # on the extension string or the GL version. |
1410 file.write("""void Driver%s::InitializeExtensionBindings( | 1455 file.write("""void Driver%s::InitializeDynamicBindings(GLContext* context) { |
1411 GLContext* context) { | 1456 DCHECK(context && context->IsCurrent(NULL)); |
1457 const GLVersionInfo* ver ALLOW_UNUSED = context->GetVersionInfo(); | |
1458 std::string extensions ALLOW_UNUSED = context->GetExtensions(); | |
1459 extensions += " "; | |
1460 | |
1412 """ % set_name.upper()) | 1461 """ % set_name.upper()) |
1413 file.write(' DCHECK(context && context->IsCurrent(NULL));\n') | 1462 for extension in used_extensions: |
1414 for extension, ext_functions in used_extension_functions: | 1463 # Extra space at the end of the extension name is intentional, it is used |
1415 file.write(' ext.b_%s = context->HasExtension("%s");\n' % | 1464 # as a separator |
1465 file.write(' ext.b_%s = extensions.find("%s ") != std::string::npos;\n' % | |
1416 (extension, extension)) | 1466 (extension, extension)) |
1417 file.write(' if (ext.b_%s) {\n' % | 1467 |
1418 (extension)) | 1468 def VersionCondition(version): |
1419 queried_entry_points = set() | 1469 conditions = [] |
1420 for entry_point_name, function_name in ext_functions: | 1470 if 'gl_versions' in version: |
1421 # Replace the pointer unconditionally unless this extension has several | 1471 gl_versions = version['gl_versions'] |
1422 # alternatives for the same entry point (e.g., | 1472 version_cond = ' || '.join(['ver->is_%s' % gl for gl in gl_versions]) |
1423 # GL_ARB_blend_func_extended). | 1473 conditions.append(version_cond) |
1424 if entry_point_name in queried_entry_points: | 1474 ext = [] |
1425 file.write(' if (!fn.%sFn)\n ' % entry_point_name) | 1475 if 'extension' in version: |
1426 file.write( | 1476 ext.append(version['extension']) |
1427 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % | 1477 if 'extensions' in version: |
1428 (entry_point_name, entry_point_name, function_name)) | 1478 ext.extend([e for e in version['extensions'] if e not in ext]) |
1429 queried_entry_points.add(entry_point_name) | 1479 if ext: |
1430 file.write(' }\n') | 1480 ext_cond = ' || '.join(['ext.b_%s' % e for e in ext]) |
1481 conditions.append(ext_cond) | |
1482 def Wrap(cond): | |
1483 if ' || ' in cond: | |
1484 return '(%s)' % cond | |
1485 return cond | |
1486 return ' && '.join([Wrap(cond) for cond in conditions]) | |
1487 | |
1488 def WriteConditionalFuncBinding(file, func): | |
1489 assert len(func['versions']) > 1 | |
1490 known_as = func['known_as'] | |
1491 i = 0 | |
1492 first_version = True | |
1493 while i < len(func['versions']): | |
1494 version = func['versions'][i] | |
1495 cond = VersionCondition(version) | |
1496 combined_conditions = [cond] | |
1497 while i + 1 < len(func['versions']) and \ | |
1498 func['versions'][i + 1]['name'] == version['name']: | |
1499 i += 1 | |
1500 combined_conditions.append(VersionCondition(func['versions'][i])) | |
1501 if len(combined_conditions) > 1: | |
1502 if [1 for cond in combined_conditions if cond == '']: | |
1503 cond = '' | |
1504 else: | |
1505 def Wrap(cond): | |
1506 if ' && ' in cond: | |
1507 return '(%s)' % cond | |
1508 return cond | |
1509 cond = ' || '.join([Wrap(cond) for cond in combined_conditions]) | |
1510 # Don't make the last possible binding conditional on anything else but | |
1511 # that the function isn't already bound to avoid verbose specification | |
1512 # of functions which have both ARB and core versions with the same name, | |
1513 # and to be able to bind to mock extension functions in unit tests which | |
1514 # call InitializeDynamicGLBindings with a stub context that doesn't have | |
1515 # extensions in its extension string. | |
1516 # TODO(oetuaho@nvidia.com): Get rid of the fallback. | |
1517 # http://crbug.com/325668 | |
1518 if cond != '' and i + 1 < len(func['versions']): | |
1519 if not first_version: | |
1520 file.write(' if (!fn.%sFn && (%s))\n ' % (known_as, cond)) | |
piman
2013/12/04 22:45:12
How about ' else if (%s)\n ' % cond ?
Presumably
oetuaho
2013/12/05 09:47:14
That should be correct, and would result in cleane
piman
2013/12/05 19:47:04
I see, you want to protect against buggy drivers t
| |
1521 else: | |
1522 file.write(' if (%s)\n ' % cond) | |
1523 elif not first_version: | |
1524 file.write(' if (!fn.%sFn)\n ' % known_as) | |
1525 WriteFuncBinding(file, known_as, version['name']) | |
1526 i += 1 | |
1527 first_version = False | |
1528 | |
1529 for func in functions: | |
1530 if len(func['names']) > 1: | |
1531 file.write('\n') | |
1532 WriteConditionalFuncBinding(file, func) | |
1533 | |
1534 # Some new function pointers have been added, so update them in debug bindings | |
1535 file.write('\n') | |
1431 file.write(' if (g_debugBindingsInitialized)\n') | 1536 file.write(' if (g_debugBindingsInitialized)\n') |
1432 file.write(' UpdateDebugExtensionBindings();\n') | 1537 file.write(' InitializeDebugBindings();\n') |
1433 file.write('}\n') | 1538 file.write('}\n') |
1434 file.write('\n') | 1539 file.write('\n') |
1435 | 1540 |
1436 # Write logging wrappers for each function. | 1541 # Write logging wrappers for each function. |
1437 file.write('extern "C" {\n') | 1542 file.write('extern "C" {\n') |
1438 for func in functions: | 1543 for func in functions: |
1439 names = func['names'] | |
1440 return_type = func['return_type'] | 1544 return_type = func['return_type'] |
1441 arguments = func['arguments'] | 1545 arguments = func['arguments'] |
1442 file.write('\n') | 1546 file.write('\n') |
1443 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % | 1547 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % |
1444 (return_type, names[0], arguments)) | 1548 (return_type, func['known_as'], arguments)) |
1445 argument_names = re.sub( | 1549 argument_names = re.sub( |
1446 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | 1550 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) |
1447 argument_names = re.sub( | 1551 argument_names = re.sub( |
1448 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | 1552 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) |
1449 log_argument_names = re.sub( | 1553 log_argument_names = re.sub( |
1450 r'const char\* ([a-zA-Z0-9_]+)', r'CONSTCHAR_\1', arguments) | 1554 r'const char\* ([a-zA-Z0-9_]+)', r'CONSTCHAR_\1', arguments) |
1451 log_argument_names = re.sub( | 1555 log_argument_names = re.sub( |
1452 r'(const )?[a-zA-Z0-9_]+\* ([a-zA-Z0-9_]+)', | 1556 r'(const )?[a-zA-Z0-9_]+\* ([a-zA-Z0-9_]+)', |
1453 r'CONSTVOID_\2', log_argument_names) | 1557 r'CONSTVOID_\2', log_argument_names) |
1454 log_argument_names = re.sub( | 1558 log_argument_names = re.sub( |
1455 r'(?<!E)GLenum ([a-zA-Z0-9_]+)', r'GLenum_\1', log_argument_names) | 1559 r'(?<!E)GLenum ([a-zA-Z0-9_]+)', r'GLenum_\1', log_argument_names) |
1456 log_argument_names = re.sub( | 1560 log_argument_names = re.sub( |
1457 r'(?<!E)GLboolean ([a-zA-Z0-9_]+)', r'GLboolean_\1', log_argument_names) | 1561 r'(?<!E)GLboolean ([a-zA-Z0-9_]+)', r'GLboolean_\1', log_argument_names) |
1458 log_argument_names = re.sub( | 1562 log_argument_names = re.sub( |
1459 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', | 1563 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', |
1460 log_argument_names) | 1564 log_argument_names) |
1461 log_argument_names = re.sub( | 1565 log_argument_names = re.sub( |
1462 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', | 1566 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', |
1463 log_argument_names) | 1567 log_argument_names) |
1464 log_argument_names = re.sub( | 1568 log_argument_names = re.sub( |
1465 r'CONSTVOID_([a-zA-Z0-9_]+)', | 1569 r'CONSTVOID_([a-zA-Z0-9_]+)', |
1466 r'static_cast<const void*>(\1)', log_argument_names); | 1570 r'static_cast<const void*>(\1)', log_argument_names) |
1467 log_argument_names = re.sub( | 1571 log_argument_names = re.sub( |
1468 r'CONSTCHAR_([a-zA-Z0-9_]+)', r'\1', log_argument_names); | 1572 r'CONSTCHAR_([a-zA-Z0-9_]+)', r'\1', log_argument_names) |
1469 log_argument_names = re.sub( | 1573 log_argument_names = re.sub( |
1470 r'GLenum_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringEnum(\1)', | 1574 r'GLenum_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringEnum(\1)', |
1471 log_argument_names) | 1575 log_argument_names) |
1472 log_argument_names = re.sub( | 1576 log_argument_names = re.sub( |
1473 r'GLboolean_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringBool(\1)', | 1577 r'GLboolean_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringBool(\1)', |
1474 log_argument_names) | 1578 log_argument_names) |
1475 log_argument_names = log_argument_names.replace(',', ' << ", " <<') | 1579 log_argument_names = log_argument_names.replace(',', ' << ", " <<') |
1476 if argument_names == 'void' or argument_names == '': | 1580 if argument_names == 'void' or argument_names == '': |
1477 argument_names = '' | 1581 argument_names = '' |
1478 log_argument_names = '' | 1582 log_argument_names = '' |
1479 else: | 1583 else: |
1480 log_argument_names = " << " + log_argument_names | 1584 log_argument_names = " << " + log_argument_names |
1481 function_name = names[0] | 1585 function_name = func['known_as'] |
1482 if return_type == 'void': | 1586 if return_type == 'void': |
1483 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % | 1587 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % |
1484 (function_name, log_argument_names)) | 1588 (function_name, log_argument_names)) |
1485 file.write(' g_driver_%s.debug_fn.%sFn(%s);\n' % | 1589 file.write(' g_driver_%s.debug_fn.%sFn(%s);\n' % |
1486 (set_name.lower(), function_name, argument_names)) | 1590 (set_name.lower(), function_name, argument_names)) |
1487 if 'logging_code' in func: | 1591 if 'logging_code' in func: |
1488 file.write("%s\n" % func['logging_code']) | 1592 file.write("%s\n" % func['logging_code']) |
1489 else: | 1593 else: |
1490 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % | 1594 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % |
1491 (function_name, log_argument_names)) | 1595 (function_name, log_argument_names)) |
1492 file.write(' %s result = g_driver_%s.debug_fn.%sFn(%s);\n' % | 1596 file.write(' %s result = g_driver_%s.debug_fn.%sFn(%s);\n' % |
1493 (return_type, set_name.lower(), function_name, argument_names)) | 1597 (return_type, set_name.lower(), function_name, argument_names)) |
1494 if 'logging_code' in func: | 1598 if 'logging_code' in func: |
1495 file.write("%s\n" % func['logging_code']) | 1599 file.write("%s\n" % func['logging_code']) |
1496 else: | 1600 else: |
1497 file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n'); | 1601 file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n') |
1498 file.write(' return result;\n') | 1602 file.write(' return result;\n') |
1499 file.write('}\n') | 1603 file.write('}\n') |
1500 file.write('} // extern "C"\n') | 1604 file.write('} // extern "C"\n') |
1501 | 1605 |
1502 # Write function to initialize the debug function pointers. | 1606 # Write function to initialize the debug function pointers. |
1503 file.write('\n') | 1607 file.write('\n') |
1504 file.write('void Driver%s::InitializeDebugBindings() {\n' % | 1608 file.write('void Driver%s::InitializeDebugBindings() {\n' % |
1505 set_name.upper()) | 1609 set_name.upper()) |
1506 for func in functions: | 1610 for func in functions: |
1507 first_name = func['names'][0] | 1611 first_name = func['known_as'] |
1508 file.write(' if (!debug_fn.%sFn) {\n' % first_name) | 1612 file.write(' if (!debug_fn.%sFn) {\n' % first_name) |
1509 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) | 1613 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name)) |
1510 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) | 1614 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name)) |
1511 file.write(' }\n') | 1615 file.write(' }\n') |
1512 file.write(' g_debugBindingsInitialized = true;\n') | 1616 file.write(' g_debugBindingsInitialized = true;\n') |
1513 file.write('}\n') | 1617 file.write('}\n') |
1514 | 1618 |
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. | 1619 # Write function to clear all function pointers. |
1530 file.write('\n') | 1620 file.write('\n') |
1531 file.write("""void Driver%s::ClearBindings() { | 1621 file.write("""void Driver%s::ClearBindings() { |
1532 memset(this, 0, sizeof(*this)); | 1622 memset(this, 0, sizeof(*this)); |
1533 } | 1623 } |
1534 """ % set_name.upper()) | 1624 """ % set_name.upper()) |
1535 | 1625 |
1536 # Write GLApiBase functions | 1626 # Write GLApiBase functions |
1537 for func in functions: | 1627 for func in functions: |
1538 names = func['names'] | |
1539 return_type = func['return_type'] | 1628 return_type = func['return_type'] |
1540 arguments = func['arguments'] | 1629 arguments = func['arguments'] |
1541 file.write('\n') | 1630 file.write('\n') |
1542 file.write('%s %sApiBase::%sFn(%s) {\n' % | 1631 file.write('%s %sApiBase::%sFn(%s) {\n' % |
1543 (return_type, set_name.upper(), names[0], arguments)) | 1632 (return_type, set_name.upper(), func['known_as'], arguments)) |
1544 argument_names = re.sub( | 1633 argument_names = re.sub( |
1545 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | 1634 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) |
1546 argument_names = re.sub( | 1635 argument_names = re.sub( |
1547 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | 1636 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) |
1548 if argument_names == 'void' or argument_names == '': | 1637 if argument_names == 'void' or argument_names == '': |
1549 argument_names = '' | 1638 argument_names = '' |
1550 function_name = names[0] | 1639 function_name = func['known_as'] |
1551 if return_type == 'void': | 1640 if return_type == 'void': |
1552 file.write(' driver_->fn.%sFn(%s);\n' % | 1641 file.write(' driver_->fn.%sFn(%s);\n' % |
1553 (function_name, argument_names)) | 1642 (function_name, argument_names)) |
1554 else: | 1643 else: |
1555 file.write(' return driver_->fn.%sFn(%s);\n' % | 1644 file.write(' return driver_->fn.%sFn(%s);\n' % |
1556 (function_name, argument_names)) | 1645 (function_name, argument_names)) |
1557 file.write('}\n') | 1646 file.write('}\n') |
1558 | 1647 |
1559 # Write TraceGLApi functions | 1648 # Write TraceGLApi functions |
1560 for func in functions: | 1649 for func in functions: |
1561 names = func['names'] | |
1562 return_type = func['return_type'] | 1650 return_type = func['return_type'] |
1563 arguments = func['arguments'] | 1651 arguments = func['arguments'] |
1564 file.write('\n') | 1652 file.write('\n') |
1565 file.write('%s Trace%sApi::%sFn(%s) {\n' % | 1653 file.write('%s Trace%sApi::%sFn(%s) {\n' % |
1566 (return_type, set_name.upper(), names[0], arguments)) | 1654 (return_type, set_name.upper(), func['known_as'], arguments)) |
1567 argument_names = re.sub( | 1655 argument_names = re.sub( |
1568 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | 1656 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) |
1569 argument_names = re.sub( | 1657 argument_names = re.sub( |
1570 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | 1658 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) |
1571 if argument_names == 'void' or argument_names == '': | 1659 if argument_names == 'void' or argument_names == '': |
1572 argument_names = '' | 1660 argument_names = '' |
1573 function_name = names[0] | 1661 function_name = func['known_as'] |
1574 file.write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "TraceGLAPI::%s")\n' % | 1662 file.write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "TraceGLAPI::%s")\n' % |
1575 function_name) | 1663 function_name) |
1576 if return_type == 'void': | 1664 if return_type == 'void': |
1577 file.write(' %s_api_->%sFn(%s);\n' % | 1665 file.write(' %s_api_->%sFn(%s);\n' % |
1578 (set_name.lower(), function_name, argument_names)) | 1666 (set_name.lower(), function_name, argument_names)) |
1579 else: | 1667 else: |
1580 file.write(' return %s_api_->%sFn(%s);\n' % | 1668 file.write(' return %s_api_->%sFn(%s);\n' % |
1581 (set_name.lower(), function_name, argument_names)) | 1669 (set_name.lower(), function_name, argument_names)) |
1582 file.write('}\n') | 1670 file.write('}\n') |
1583 | 1671 |
(...skipping 14 matching lines...) Expand all Loading... | |
1598 #include <string.h> | 1686 #include <string.h> |
1599 | 1687 |
1600 #include "ui/gl/gl_interface.h" | 1688 #include "ui/gl/gl_interface.h" |
1601 | 1689 |
1602 namespace gfx { | 1690 namespace gfx { |
1603 """) | 1691 """) |
1604 # Write function that trampoline into the GLInterface. | 1692 # Write function that trampoline into the GLInterface. |
1605 for func in functions: | 1693 for func in functions: |
1606 file.write('\n') | 1694 file.write('\n') |
1607 file.write('%s GL_BINDING_CALL Mock_%s(%s) {\n' % | 1695 file.write('%s GL_BINDING_CALL Mock_%s(%s) {\n' % |
1608 (func['return_type'], func['names'][0], func['arguments'])) | 1696 (func['return_type'], func['known_as'], func['arguments'])) |
1609 argument_names = re.sub(r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0 -9]+)', r'\4', | 1697 argRe = r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0-9]+)' |
piman
2013/12/04 22:45:12
nit: style (arg_re)
oetuaho
2013/12/05 09:47:14
Done.
| |
1610 func['arguments']) | 1698 argument_names = re.sub(argRe, r'\4', func['arguments']) |
1611 if argument_names == 'void': | 1699 if argument_names == 'void': |
1612 argument_names = '' | 1700 argument_names = '' |
1613 function_name = func['names'][0][2:] | 1701 function_name = func['known_as'][2:] |
1614 if func['return_type'] == 'void': | 1702 if func['return_type'] == 'void': |
1615 file.write(' GLInterface::GetGLInterface()->%s(%s);\n' % | 1703 file.write(' GLInterface::GetGLInterface()->%s(%s);\n' % |
1616 (function_name, argument_names)) | 1704 (function_name, argument_names)) |
1617 else: | 1705 else: |
1618 file.write(' return GLInterface::GetGLInterface()->%s(%s);\n' % | 1706 file.write(' return GLInterface::GetGLInterface()->%s(%s);\n' % |
1619 (function_name, argument_names)) | 1707 (function_name, argument_names)) |
1620 file.write('}\n') | 1708 file.write('}\n') |
1621 | 1709 |
1622 # Write an 'invalid' function to catch code calling through uninitialized | 1710 # Write an 'invalid' function to catch code calling through uninitialized |
1623 # function pointers or trying to interpret the return value of | 1711 # function pointers or trying to interpret the return value of |
1624 # GLProcAddress(). | 1712 # GLProcAddress(). |
1625 file.write('\n') | 1713 file.write('\n') |
1626 file.write('static void MockInvalidFunction() {\n') | 1714 file.write('static void MockInvalidFunction() {\n') |
1627 file.write(' NOTREACHED();\n') | 1715 file.write(' NOTREACHED();\n') |
1628 file.write('}\n') | 1716 file.write('}\n') |
1629 | 1717 |
1630 # Write a function to lookup a mock GL function based on its name. | 1718 # Write a function to lookup a mock GL function based on its name. |
1631 file.write('\n') | 1719 file.write('\n') |
1632 file.write('void* GL_BINDING_CALL GetMockGLProcAddress(const char* name) {\n') | 1720 file.write('void* GL_BINDING_CALL GetMockGLProcAddress(const char* name) {\n') |
1633 for func in functions: | 1721 for func in functions: |
1634 first_name = func['names'][0] | 1722 for name in func['names']: |
1635 file.write(' if (strcmp(name, "%s") == 0)\n' % first_name) | 1723 file.write(' if (strcmp(name, "%s") == 0)\n' % name) |
1636 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % first_name) | 1724 file.write( |
1725 ' return reinterpret_cast<void*>(Mock_%s);\n' % func['known_as']) | |
1637 # Always return a non-NULL pointer like some EGL implementations do. | 1726 # Always return a non-NULL pointer like some EGL implementations do. |
1638 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n') | 1727 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n') |
1639 file.write('}\n'); | 1728 file.write('}\n') |
1640 | 1729 |
1641 file.write('\n') | 1730 file.write('\n') |
1642 file.write('} // namespace gfx\n') | 1731 file.write('} // namespace gfx\n') |
1643 | 1732 |
1644 | 1733 |
1645 def ParseExtensionFunctionsFromHeader(header_file): | 1734 def ParseExtensionFunctionsFromHeader(header_file): |
1646 """Parse a C extension header file and return a map from extension names to | 1735 """Parse a C extension header file and return a map from extension names to |
1647 a list of functions. | 1736 a list of functions. |
1648 | 1737 |
1649 Args: | 1738 Args: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1712 return function_to_extensions | 1801 return function_to_extensions |
1713 | 1802 |
1714 | 1803 |
1715 def LooksLikeExtensionFunction(function): | 1804 def LooksLikeExtensionFunction(function): |
1716 """Heuristic to see if a function name is consistent with extension function | 1805 """Heuristic to see if a function name is consistent with extension function |
1717 naming.""" | 1806 naming.""" |
1718 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) | 1807 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) |
1719 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] | 1808 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] |
1720 | 1809 |
1721 | 1810 |
1722 def GetUsedExtensionFunctions(functions, extension_headers, extra_extensions): | 1811 def FillExtensionsFromHeaders(functions, extension_headers, extra_extensions): |
1723 """Determine which functions belong to extensions. | 1812 """Determine which functions belong to extensions based on extension headers, |
1813 and fill in this information to the functions table for functions that don't | |
1814 already have the information. | |
1724 | 1815 |
1725 Args: | 1816 Args: |
1726 functions: List of (return type, function names, arguments). | 1817 functions: List of (return type, function versions, arguments). |
1727 extension_headers: List of header file names. | 1818 extension_headers: List of header file names. |
1819 extra_extensions: Extensions to add to the list. | |
1728 Returns: | 1820 Returns: |
1729 List of (extension name, [function name alternatives]) sorted with least | 1821 List of used extensions. |
1730 preferred extensions first. | |
1731 """ | 1822 """ |
1732 # Parse known extensions. | 1823 # Parse known extensions. |
1733 extensions = GetExtensionFunctions(extension_headers) | 1824 extensions = GetExtensionFunctions(extension_headers) |
1734 functions_to_extensions = GetFunctionToExtensionMap(extensions) | 1825 functions_to_extensions = GetFunctionToExtensionMap(extensions) |
1735 | 1826 |
1736 # Collect all used extension functions. | 1827 # Fill in the extension information. |
1737 used_extension_functions = collections.defaultdict(lambda: []) | 1828 used_extensions = [] |
1738 for func in functions: | 1829 for func in functions: |
1739 for name in func['names']: | 1830 for version in func['versions']: |
1740 # Make sure we know about all extension functions. | 1831 name = version['name'] |
1741 if (LooksLikeExtensionFunction(name) and | 1832 # Make sure we know about all extensions and extension functions. |
1742 not name in functions_to_extensions): | 1833 if 'extension' in version: |
1834 if version['extension'] not in used_extensions: | |
1835 used_extensions.append(version['extension']) | |
1836 elif 'extensions' in version: | |
1837 used_extensions.extend( | |
1838 [e for e in version['extensions'] if e not in used_extensions]) | |
1839 elif name in functions_to_extensions: | |
1840 # If there are multiple versions with the same name, assume that they | |
1841 # already have all the correct conditions, we can't just blindly add | |
1842 # the same extension conditions to all of them | |
1843 if len([v for v in func['versions'] if v['name'] == name]) == 1: | |
1844 version['extensions'] = functions_to_extensions[name] | |
1845 used_extensions.extend( | |
1846 [e for e in version['extensions'] if e not in used_extensions]) | |
1847 elif LooksLikeExtensionFunction(name): | |
1743 raise RuntimeError('%s looks like an extension function but does not ' | 1848 raise RuntimeError('%s looks like an extension function but does not ' |
1744 'belong to any of the known extensions.' % name) | 1849 'belong to any of the known extensions.' % name) |
1745 if name in functions_to_extensions: | |
1746 extensions = functions_to_extensions[name][:] | |
1747 if 'other_extensions' in func: | |
1748 extensions.extend(func['other_extensions']) | |
1749 for extension in extensions: | |
1750 used_extension_functions[extension].append((func['names'][0], name)) | |
1751 | 1850 |
1752 # Add extensions that do not have any functions. | 1851 # Add extensions that do not have any functions. |
1753 used_extension_functions.update(dict( | 1852 used_extensions.extend( |
1754 [(e, []) for e in extra_extensions if e not in used_extension_functions])) | 1853 [e for e in extra_extensions if e not in used_extensions]) |
1755 | 1854 |
1756 def ExtensionSortKey(name): | 1855 return used_extensions |
1757 # Prefer ratified extensions and EXTs. | |
1758 preferences = ['_ARB_', '_OES_', '_EXT_', ''] | |
1759 for i, category in enumerate(preferences): | |
1760 if category in name: | |
1761 return -i | |
1762 used_extension_functions = sorted(used_extension_functions.items(), | |
1763 key = lambda item: ExtensionSortKey(item[0])) | |
1764 return used_extension_functions | |
1765 | 1856 |
1766 | 1857 |
1767 def ResolveHeader(header, header_paths): | 1858 def ResolveHeader(header, header_paths): |
1768 paths = header_paths.split(':') | 1859 paths = header_paths.split(':') |
1769 | 1860 |
1770 # Always use a path for Chromium-specific extensions. They are extracted | 1861 # Always use a path for Chromium-specific extensions. They are extracted |
1771 # to separate files. | 1862 # to separate files. |
1772 paths.append('.') | 1863 paths.append('.') |
1773 paths.append('../../gpu') | 1864 paths.append('../../gpu') |
1774 | 1865 |
(...skipping 19 matching lines...) Expand all Loading... | |
1794 parser.add_option('--header-paths') | 1885 parser.add_option('--header-paths') |
1795 | 1886 |
1796 options, args = parser.parse_args(argv) | 1887 options, args = parser.parse_args(argv) |
1797 | 1888 |
1798 if options.inputs: | 1889 if options.inputs: |
1799 for [_, _, headers, _] in FUNCTION_SETS: | 1890 for [_, _, headers, _] in FUNCTION_SETS: |
1800 for header in headers: | 1891 for header in headers: |
1801 print ResolveHeader(header, options.header_paths) | 1892 print ResolveHeader(header, options.header_paths) |
1802 return 0 | 1893 return 0 |
1803 | 1894 |
1895 directory = '.' | |
1804 if len(args) >= 1: | 1896 if len(args) >= 1: |
1805 dir = args[0] | 1897 directory = args[0] |
1806 else: | |
1807 dir = '.' | |
1808 | 1898 |
1809 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: | 1899 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: |
1900 # Function names can be specified in two ways (list of unique names or list | |
1901 # of versions with different binding conditions), fill in the data both | |
1902 # ways: | |
1903 for func in functions: | |
1904 assert 'versions' in func or 'names' in func, 'Function with no names' | |
1905 if 'versions' not in func: | |
1906 func['versions'] = [{'name': n} for n in func['names']] | |
1907 if 'names' not in func: | |
1908 func['names'] = [] | |
1909 for version in func['versions']: | |
1910 if version['name'] not in func['names']: | |
1911 func['names'].append(version['name']) | |
1912 # Use the first version's name unless otherwise specified | |
1913 if 'known_as' not in func: | |
1914 func['known_as'] = func['names'][0] | |
1915 | |
1810 extension_headers = [ResolveHeader(h, options.header_paths) | 1916 extension_headers = [ResolveHeader(h, options.header_paths) |
1811 for h in extension_headers] | 1917 for h in extension_headers] |
1812 used_extension_functions = GetUsedExtensionFunctions( | 1918 used_extensions = FillExtensionsFromHeaders( |
1813 functions, extension_headers, extensions) | 1919 functions, extension_headers, extensions) |
1814 | 1920 |
1815 header_file = open( | 1921 header_file = open( |
1816 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | 1922 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb') |
1817 GenerateHeader(header_file, functions, set_name, used_extension_functions) | 1923 GenerateHeader(header_file, functions, set_name, used_extensions) |
1818 header_file.close() | 1924 header_file.close() |
1819 | 1925 |
1820 header_file = open( | 1926 header_file = open( |
1821 os.path.join(dir, 'gl_bindings_api_autogen_%s.h' % set_name), 'wb') | 1927 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name), |
1822 GenerateAPIHeader( | 1928 'wb') |
1823 header_file, functions, set_name, used_extension_functions) | 1929 GenerateAPIHeader(header_file, functions, set_name) |
1824 header_file.close() | 1930 header_file.close() |
1825 | 1931 |
1826 source_file = open( | 1932 source_file = open( |
1827 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | 1933 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') |
1828 GenerateSource(source_file, functions, set_name, used_extension_functions) | 1934 GenerateSource(source_file, functions, set_name, used_extensions) |
1829 source_file.close() | 1935 source_file.close() |
1830 | 1936 |
1831 header_file = open( | 1937 header_file = open( |
1832 os.path.join(dir, 'gl_interface_autogen_%s.h' % set_name), 'wb') | 1938 os.path.join(directory, 'gl_interface_autogen_%s.h' % set_name), 'wb') |
1833 GenerateInterfaceHeader( | 1939 GenerateInterfaceHeader(header_file, functions, set_name) |
1834 header_file, functions, set_name, used_extension_functions) | |
1835 header_file.close() | 1940 header_file.close() |
1836 | 1941 |
1837 header_file = open( | 1942 header_file = open( |
1838 os.path.join(dir, 'gl_mock_autogen_%s.h' % set_name), 'wb') | 1943 os.path.join(directory, 'gl_mock_autogen_%s.h' % set_name), 'wb') |
1839 GenerateMockHeader( | 1944 GenerateMockHeader(header_file, functions, set_name) |
1840 header_file, functions, set_name, used_extension_functions) | |
1841 header_file.close() | 1945 header_file.close() |
1842 | 1946 |
1843 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 1947 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'), |
1948 'wb') | |
1844 GenerateMockSource(source_file, GL_FUNCTIONS) | 1949 GenerateMockSource(source_file, GL_FUNCTIONS) |
1845 source_file.close() | 1950 source_file.close() |
1846 return 0 | 1951 return 0 |
1847 | 1952 |
1848 | 1953 |
1849 if __name__ == '__main__': | 1954 if __name__ == '__main__': |
1850 sys.exit(main(sys.argv[1:])) | 1955 sys.exit(main(sys.argv[1:])) |
OLD | NEW |