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