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

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

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

Powered by Google App Engine
This is Rietveld 408576698