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 GLES2 command buffers.""" | 6 """code generator for GLES2 command buffers.""" |
7 | 7 |
8 import os | 8 import os |
9 import os.path | 9 import os.path |
10 import sys | 10 import sys |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 'type': 'GLboolean', | 724 'type': 'GLboolean', |
725 'valid': [ | 725 'valid': [ |
726 'false', | 726 'false', |
727 ], | 727 ], |
728 'invalid': [ | 728 'invalid': [ |
729 'true', | 729 'true', |
730 ], | 730 ], |
731 }, | 731 }, |
732 } | 732 } |
733 | 733 |
| 734 _PEPPER_INTERFACES = [ |
| 735 '', |
| 736 'InstancedArrays', |
| 737 'FramebufferBlit', |
| 738 'FramebufferMultisample', |
| 739 'ChromiumEnableFeature', |
| 740 'ChromiumMapSub', |
| 741 ] |
| 742 |
734 # This table specifies types and other special data for the commands that | 743 # This table specifies types and other special data for the commands that |
735 # will be generated. | 744 # will be generated. |
736 # | 745 # |
737 # cmd_comment: A comment added to the cmd format. | 746 # cmd_comment: A comment added to the cmd format. |
738 # type: defines which handler will be used to generate code. | 747 # type: defines which handler will be used to generate code. |
739 # decoder_func: defines which function to call in the decoder to execute the | 748 # decoder_func: defines which function to call in the decoder to execute the |
740 # corresponding GL command. If not specified the GL command will | 749 # corresponding GL command. If not specified the GL command will |
741 # be called directly. | 750 # be called directly. |
742 # gl_test_func: GL function that is expected to be called when testing. | 751 # gl_test_func: GL function that is expected to be called when testing. |
743 # cmd_args: The arguments to use for the command. This overrides generating | 752 # cmd_args: The arguments to use for the command. This overrides generating |
(...skipping 12 matching lines...) Expand all Loading... |
756 # needs_size: If true a data_size field is added to the command. | 765 # needs_size: If true a data_size field is added to the command. |
757 # data_type: The type of data the command uses. For PUTn or PUT types. | 766 # data_type: The type of data the command uses. For PUTn or PUT types. |
758 # count: The number of units per element. For PUTn or PUT types. | 767 # count: The number of units per element. For PUTn or PUT types. |
759 # unit_test: If False no service side unit test will be generated. | 768 # unit_test: If False no service side unit test will be generated. |
760 # client_test: If False no client side unit test will be generated. | 769 # client_test: If False no client side unit test will be generated. |
761 # expectation: If False the unit test will have no expected calls. | 770 # expectation: If False the unit test will have no expected calls. |
762 # gen_func: Name of function that generates GL resource for corresponding | 771 # gen_func: Name of function that generates GL resource for corresponding |
763 # bind function. | 772 # bind function. |
764 # valid_args: A dictionary of argument indices to args to use in unit tests | 773 # valid_args: A dictionary of argument indices to args to use in unit tests |
765 # when they can not be automatically determined. | 774 # when they can not be automatically determined. |
| 775 # pepper_interface: The pepper interface that is used for this extension |
766 | 776 |
767 _FUNCTION_INFO = { | 777 _FUNCTION_INFO = { |
768 'ActiveTexture': { | 778 'ActiveTexture': { |
769 'decoder_func': 'DoActiveTexture', | 779 'decoder_func': 'DoActiveTexture', |
770 'unit_test': False, | 780 'unit_test': False, |
771 'impl_func': False, | 781 'impl_func': False, |
772 'client_test': False, | 782 'client_test': False, |
773 }, | 783 }, |
774 'AttachShader': {'decoder_func': 'DoAttachShader'}, | 784 'AttachShader': {'decoder_func': 'DoAttachShader'}, |
775 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, | 785 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, |
(...skipping 16 matching lines...) Expand all Loading... |
792 }, | 802 }, |
793 'BindTexture': { | 803 'BindTexture': { |
794 'type': 'Bind', | 804 'type': 'Bind', |
795 'decoder_func': 'DoBindTexture', | 805 'decoder_func': 'DoBindTexture', |
796 'gen_func': 'GenTextures', | 806 'gen_func': 'GenTextures', |
797 }, | 807 }, |
798 'BlitFramebufferEXT': { | 808 'BlitFramebufferEXT': { |
799 'decoder_func': 'DoBlitFramebufferEXT', | 809 'decoder_func': 'DoBlitFramebufferEXT', |
800 'unit_test': False, | 810 'unit_test': False, |
801 'extension': True, | 811 'extension': True, |
| 812 'pepper_interface': 'FramebufferBlit', |
802 }, | 813 }, |
803 'BufferData': { | 814 'BufferData': { |
804 'type': 'Manual', | 815 'type': 'Manual', |
805 'immediate': True, | 816 'immediate': True, |
806 'client_test': False, | 817 'client_test': False, |
807 }, | 818 }, |
808 'BufferSubData': { | 819 'BufferSubData': { |
809 'type': 'Data', | 820 'type': 'Data', |
810 'client_test': False, | 821 'client_test': False, |
811 'decoder_func': 'DoBufferSubData', | 822 'decoder_func': 'DoBufferSubData', |
(...skipping 15 matching lines...) Expand all Loading... |
827 'ClearStencil': {'decoder_func': 'DoClearStencil'}, | 838 'ClearStencil': {'decoder_func': 'DoClearStencil'}, |
828 'EnableFeatureCHROMIUM': { | 839 'EnableFeatureCHROMIUM': { |
829 'type': 'Custom', | 840 'type': 'Custom', |
830 'immediate': False, | 841 'immediate': False, |
831 'decoder_func': 'DoEnableFeatureCHROMIUM', | 842 'decoder_func': 'DoEnableFeatureCHROMIUM', |
832 'expectation': False, | 843 'expectation': False, |
833 'cmd_args': 'GLuint bucket_id, GLint* result', | 844 'cmd_args': 'GLuint bucket_id, GLint* result', |
834 'result': ['GLint'], | 845 'result': ['GLint'], |
835 'extension': True, | 846 'extension': True, |
836 'chromium': True, | 847 'chromium': True, |
| 848 'pepper_interface': 'ChromiumEnableFeature', |
837 }, | 849 }, |
838 'CompileShader': {'decoder_func': 'DoCompileShader', 'unit_test': False}, | 850 'CompileShader': {'decoder_func': 'DoCompileShader', 'unit_test': False}, |
839 'CompressedTexImage2D': { | 851 'CompressedTexImage2D': { |
840 'type': 'Manual', | 852 'type': 'Manual', |
841 'immediate': True, | 853 'immediate': True, |
842 'bucket': True, | 854 'bucket': True, |
843 }, | 855 }, |
844 'CompressedTexSubImage2D': { | 856 'CompressedTexSubImage2D': { |
845 'type': 'Data', | 857 'type': 'Data', |
846 'bucket': True, | 858 'bucket': True, |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 }, | 1192 }, |
1181 'LinkProgram': { | 1193 'LinkProgram': { |
1182 'decoder_func': 'DoLinkProgram', | 1194 'decoder_func': 'DoLinkProgram', |
1183 'impl_func': False, | 1195 'impl_func': False, |
1184 }, | 1196 }, |
1185 'MapBufferSubDataCHROMIUM': { | 1197 'MapBufferSubDataCHROMIUM': { |
1186 'gen_cmd': False, | 1198 'gen_cmd': False, |
1187 'extension': True, | 1199 'extension': True, |
1188 'chromium': True, | 1200 'chromium': True, |
1189 'client_test': False, | 1201 'client_test': False, |
| 1202 'pepper_interface': 'ChromiumMapSub', |
1190 }, | 1203 }, |
1191 'MapTexSubImage2DCHROMIUM': { | 1204 'MapTexSubImage2DCHROMIUM': { |
1192 'gen_cmd': False, | 1205 'gen_cmd': False, |
1193 'extension': True, | 1206 'extension': True, |
1194 'chromium': True, | 1207 'chromium': True, |
1195 'client_test': False, | 1208 'client_test': False, |
| 1209 'pepper_interface': 'ChromiumMapSub', |
1196 }, | 1210 }, |
1197 'PixelStorei': {'type': 'Manual'}, | 1211 'PixelStorei': {'type': 'Manual'}, |
1198 'PostSubBufferCHROMIUM': { | 1212 'PostSubBufferCHROMIUM': { |
1199 'type': 'Custom', | 1213 'type': 'Custom', |
1200 'impl_func': False, | 1214 'impl_func': False, |
1201 'unit_test': False, | 1215 'unit_test': False, |
1202 'client_test': False, | 1216 'client_test': False, |
1203 'extension': True, | 1217 'extension': True, |
1204 'chromium': True, | 1218 'chromium': True, |
1205 }, | 1219 }, |
1206 'RenderbufferStorage': { | 1220 'RenderbufferStorage': { |
1207 'decoder_func': 'DoRenderbufferStorage', | 1221 'decoder_func': 'DoRenderbufferStorage', |
1208 'gl_test_func': 'glRenderbufferStorageEXT', | 1222 'gl_test_func': 'glRenderbufferStorageEXT', |
1209 'expectation': False, | 1223 'expectation': False, |
1210 }, | 1224 }, |
1211 'RenderbufferStorageMultisampleEXT': { | 1225 'RenderbufferStorageMultisampleEXT': { |
1212 'decoder_func': 'DoRenderbufferStorageMultisample', | 1226 'decoder_func': 'DoRenderbufferStorageMultisample', |
1213 'gl_test_func': 'glRenderbufferStorageMultisampleEXT', | 1227 'gl_test_func': 'glRenderbufferStorageMultisampleEXT', |
1214 'expectation': False, | 1228 'expectation': False, |
1215 'unit_test': False, | 1229 'unit_test': False, |
1216 'extension': True, | 1230 'extension': True, |
| 1231 'pepper_interface': 'FramebufferMultisample', |
1217 }, | 1232 }, |
1218 'ReadPixels': { | 1233 'ReadPixels': { |
1219 'cmd_comment': | 1234 'cmd_comment': |
1220 '// ReadPixels has the result separated from the pixel buffer so that\n' | 1235 '// ReadPixels has the result separated from the pixel buffer so that\n' |
1221 '// it is easier to specify the result going to some specific place\n' | 1236 '// it is easier to specify the result going to some specific place\n' |
1222 '// that exactly fits the rectangle of pixels.\n', | 1237 '// that exactly fits the rectangle of pixels.\n', |
1223 'type': 'Custom', | 1238 'type': 'Custom', |
1224 'immediate': False, | 1239 'immediate': False, |
1225 'impl_func': False, | 1240 'impl_func': False, |
1226 'client_test': False, | 1241 'client_test': False, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 'type': 'PUTn', | 1397 'type': 'PUTn', |
1383 'data_type': 'GLfloat', | 1398 'data_type': 'GLfloat', |
1384 'count': 16, | 1399 'count': 16, |
1385 'decoder_func': 'DoUniformMatrix4fv', | 1400 'decoder_func': 'DoUniformMatrix4fv', |
1386 }, | 1401 }, |
1387 'UnmapBufferSubDataCHROMIUM': { | 1402 'UnmapBufferSubDataCHROMIUM': { |
1388 'gen_cmd': False, | 1403 'gen_cmd': False, |
1389 'extension': True, | 1404 'extension': True, |
1390 'chromium': True, | 1405 'chromium': True, |
1391 'client_test': False, | 1406 'client_test': False, |
1392 }, | 1407 'pepper_interface': 'ChromiumMapSub', |
| 1408 }, |
1393 'UnmapTexSubImage2DCHROMIUM': { | 1409 'UnmapTexSubImage2DCHROMIUM': { |
1394 'gen_cmd': False, | 1410 'gen_cmd': False, |
1395 'extension': True, | 1411 'extension': True, |
1396 'chromium': True, | 1412 'chromium': True, |
1397 'client_test': False, | 1413 'client_test': False, |
| 1414 'pepper_interface': 'ChromiumMapSub', |
1398 }, | 1415 }, |
1399 'UseProgram': {'decoder_func': 'DoUseProgram', 'unit_test': False}, | 1416 'UseProgram': {'decoder_func': 'DoUseProgram', 'unit_test': False}, |
1400 'ValidateProgram': {'decoder_func': 'DoValidateProgram'}, | 1417 'ValidateProgram': {'decoder_func': 'DoValidateProgram'}, |
1401 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'}, | 1418 'VertexAttrib1f': {'decoder_func': 'DoVertexAttrib1f'}, |
1402 'VertexAttrib1fv': { | 1419 'VertexAttrib1fv': { |
1403 'type': 'PUT', | 1420 'type': 'PUT', |
1404 'data_type': 'GLfloat', | 1421 'data_type': 'GLfloat', |
1405 'count': 1, | 1422 'count': 1, |
1406 'decoder_func': 'DoVertexAttrib1fv', | 1423 'decoder_func': 'DoVertexAttrib1fv', |
1407 }, | 1424 }, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 'unit_test': False, | 1508 'unit_test': False, |
1492 'extension': True, | 1509 'extension': True, |
1493 'decoder_func': 'DoTexStorage2DEXT', | 1510 'decoder_func': 'DoTexStorage2DEXT', |
1494 }, | 1511 }, |
1495 'DrawArraysInstancedANGLE': { | 1512 'DrawArraysInstancedANGLE': { |
1496 'type': 'Manual', | 1513 'type': 'Manual', |
1497 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count, ' | 1514 'cmd_args': 'GLenumDrawMode mode, GLint first, GLsizei count, ' |
1498 'GLsizei primcount', | 1515 'GLsizei primcount', |
1499 'extension': True, | 1516 'extension': True, |
1500 'unit_test': False, | 1517 'unit_test': False, |
| 1518 'pepper_interface': 'InstancedArrays', |
1501 }, | 1519 }, |
1502 'DrawElementsInstancedANGLE': { | 1520 'DrawElementsInstancedANGLE': { |
1503 'type': 'Manual', | 1521 'type': 'Manual', |
1504 'cmd_args': 'GLenumDrawMode mode, GLsizei count, ' | 1522 'cmd_args': 'GLenumDrawMode mode, GLsizei count, ' |
1505 'GLenumIndexType type, GLuint index_offset, GLsizei primcount', | 1523 'GLenumIndexType type, GLuint index_offset, GLsizei primcount', |
1506 'extension': True, | 1524 'extension': True, |
1507 'unit_test': False, | 1525 'unit_test': False, |
1508 'client_test': False, | 1526 'client_test': False, |
| 1527 'pepper_interface': 'InstancedArrays', |
1509 }, | 1528 }, |
1510 'VertexAttribDivisorANGLE': { | 1529 'VertexAttribDivisorANGLE': { |
1511 'type': 'Manual', | 1530 'type': 'Manual', |
1512 'cmd_args': 'GLuint index, GLuint divisor', | 1531 'cmd_args': 'GLuint index, GLuint divisor', |
1513 'extension': True, | 1532 'extension': True, |
1514 'unit_test': False, | 1533 'unit_test': False, |
| 1534 'pepper_interface': 'InstancedArrays', |
1515 }, | 1535 }, |
1516 | 1536 |
1517 } | 1537 } |
1518 | 1538 |
1519 | 1539 |
1520 def SplitWords(input_string): | 1540 def SplitWords(input_string): |
1521 """Transforms a input_string into a list of lower-case components. | 1541 """Transforms a input_string into a list of lower-case components. |
1522 | 1542 |
1523 Args: | 1543 Args: |
1524 input_string: the input string. | 1544 input_string: the input string. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 not parts[ii][0] == ")" and not fptr.match(parts[ii])) | 1615 not parts[ii][0] == ")" and not fptr.match(parts[ii])) |
1596 and splitter < 80): | 1616 and splitter < 80): |
1597 return splitter | 1617 return splitter |
1598 splitter += len(parts[ii]) + 1 | 1618 splitter += len(parts[ii]) + 1 |
1599 done = False | 1619 done = False |
1600 end = len(string) | 1620 end = len(string) |
1601 last_splitter = -1 | 1621 last_splitter = -1 |
1602 while not done: | 1622 while not done: |
1603 splitter = string[0:end].rfind(',') | 1623 splitter = string[0:end].rfind(',') |
1604 if splitter < 0 or (splitter > 0 and string[splitter - 1] == '"'): | 1624 if splitter < 0 or (splitter > 0 and string[splitter - 1] == '"'): |
| 1625 if last_splitter == -1 and string[0] != '#': |
| 1626 break |
| 1627 return last_splitter |
| 1628 elif splitter >= 80: |
| 1629 end = splitter |
| 1630 else: |
| 1631 return splitter |
| 1632 end = len(string) |
| 1633 last_splitter = -1 |
| 1634 while not done: |
| 1635 splitter = string[0:end].rfind(' ') |
| 1636 if splitter < 0 or (splitter > 0 and string[splitter - 1] == '"'): |
1605 return last_splitter | 1637 return last_splitter |
1606 elif splitter >= 80: | 1638 elif splitter >= 80: |
1607 end = splitter | 1639 end = splitter |
1608 else: | 1640 else: |
1609 return splitter | 1641 return splitter |
1610 | 1642 |
1611 def __WriteLine(self, line, ends_with_eol): | 1643 def __WriteLine(self, line, ends_with_eol): |
1612 """Given a signle line, writes it to a file, splitting if it's > 80 chars""" | 1644 """Given a signle line, writes it to a file, splitting if it's > 80 chars""" |
1613 if len(line) >= 80: | 1645 if len(line) >= 80: |
1614 i = self.__FindSplit(line) | 1646 i = self.__FindSplit(line) |
1615 if i > 0: | 1647 if i > 0: |
1616 line1 = line[0:i + 1] | 1648 line1 = line[0:i + 1] |
| 1649 if line1[-1] == ' ': |
| 1650 line1 = line1[:-1] |
1617 nolint = '' | 1651 nolint = '' |
1618 if len(line1) > 80: | 1652 if len(line1) > 80: |
1619 nolint = ' // NOLINT' | 1653 nolint = ' // NOLINT' |
1620 self.__AddLine(line1 + nolint + '\n') | 1654 self.__AddLine(line1 + nolint + '\n') |
1621 match = re.match("( +)", line1) | 1655 match = re.match("( +)", line1) |
1622 indent = "" | 1656 indent = "" |
1623 if match: | 1657 if match: |
1624 indent = match.group(1) | 1658 indent = match.group(1) |
1625 splitter = line[i] | 1659 splitter = line[i] |
1626 if not splitter == ',': | 1660 if not splitter == ',': |
(...skipping 3306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4933 return valid_args[str(index)] | 4967 return valid_args[str(index)] |
4934 return None | 4968 return None |
4935 | 4969 |
4936 def AddInfo(self, name, value): | 4970 def AddInfo(self, name, value): |
4937 """Adds an info.""" | 4971 """Adds an info.""" |
4938 setattr(self.info, name, value) | 4972 setattr(self.info, name, value) |
4939 | 4973 |
4940 def IsCoreGLFunction(self): | 4974 def IsCoreGLFunction(self): |
4941 return not self.GetInfo('extension') | 4975 return not self.GetInfo('extension') |
4942 | 4976 |
| 4977 def InPepperInterface(self, interface): |
| 4978 ext = self.GetInfo('pepper_interface') |
| 4979 if not interface: |
| 4980 return self.IsCoreGLFunction() |
| 4981 return ext == interface |
| 4982 |
| 4983 def InAnyPepperExtension(self): |
| 4984 return self.IsCoreGLFunction() or self.GetInfo('pepper_interface') |
| 4985 |
4943 def GetGLFunctionName(self): | 4986 def GetGLFunctionName(self): |
4944 """Gets the function to call to execute GL for this command.""" | 4987 """Gets the function to call to execute GL for this command.""" |
4945 if self.GetInfo('decoder_func'): | 4988 if self.GetInfo('decoder_func'): |
4946 return self.GetInfo('decoder_func') | 4989 return self.GetInfo('decoder_func') |
4947 return "gl%s" % self.original_name | 4990 return "gl%s" % self.original_name |
4948 | 4991 |
4949 def GetGLTestFunctionName(self): | 4992 def GetGLTestFunctionName(self): |
4950 gl_func_name = self.GetInfo('gl_test_func') | 4993 gl_func_name = self.GetInfo('gl_test_func') |
4951 if gl_func_name == None: | 4994 if gl_func_name == None: |
4952 gl_func_name = self.GetGLFunctionName() | 4995 gl_func_name = self.GetGLFunctionName() |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5716 } | 5759 } |
5717 | 5760 |
5718 """) | 5761 """) |
5719 file.Close() | 5762 file.Close() |
5720 | 5763 |
5721 def WritePepperGLES2Interface(self, filename): | 5764 def WritePepperGLES2Interface(self, filename): |
5722 """Writes the Pepper OpenGLES interface definition.""" | 5765 """Writes the Pepper OpenGLES interface definition.""" |
5723 file = CHeaderWriter( | 5766 file = CHeaderWriter( |
5724 filename, | 5767 filename, |
5725 "// OpenGL ES interface.\n", | 5768 "// OpenGL ES interface.\n", |
5726 3) | 5769 2) |
5727 | 5770 |
5728 file.Write("#include \"ppapi/c/pp_resource.h\"\n\n") | 5771 file.Write("#include \"ppapi/c/pp_resource.h\"\n\n") |
5729 | 5772 |
5730 file.Write("#ifndef __gl2_h_\n") | 5773 file.Write("#ifndef __gl2_h_\n") |
5731 for (k, v) in _GL_TYPES.iteritems(): | 5774 for (k, v) in _GL_TYPES.iteritems(): |
5732 file.Write("typedef %s %s;\n" % (v, k)) | 5775 file.Write("typedef %s %s;\n" % (v, k)) |
5733 file.Write("#endif // __gl2_h_\n\n") | 5776 file.Write("#endif // __gl2_h_\n\n") |
5734 | 5777 |
5735 file.Write("#define PPB_OPENGLES2_INTERFACE_1_0 \"PPB_OpenGLES2;1.0\"\n") | 5778 for interface in _PEPPER_INTERFACES: |
5736 file.Write("#define PPB_OPENGLES2_INTERFACE PPB_OPENGLES2_INTERFACE_1_0\n") | 5779 if interface: |
| 5780 upperint = "_" + interface.upper() |
| 5781 else: |
| 5782 upperint = "" |
5737 | 5783 |
5738 file.Write("\nstruct PPB_OpenGLES2 {\n") | 5784 file.Write("#define PPB_OPENGLES2%s_INTERFACE_1_0 " |
5739 for func in self.original_functions: | 5785 "\"PPB_OpenGLES2%s;1.0\"\n" % (upperint, interface)) |
5740 if not func.IsCoreGLFunction(): | 5786 file.Write("#define PPB_OPENGLES2%s_INTERFACE " |
5741 continue | 5787 "PPB_OPENGLES2%s_INTERFACE_1_0\n" % (upperint, upperint)) |
5742 | 5788 |
5743 original_arg = func.MakeTypedOriginalArgString("") | 5789 file.Write("\nstruct PPB_OpenGLES2%s {\n" % interface) |
5744 context_arg = "PP_Resource context" | 5790 for func in self.original_functions: |
5745 if len(original_arg): | 5791 if not func.InPepperInterface(interface): |
5746 arg = context_arg + ", " + original_arg | 5792 continue |
5747 else: | 5793 |
5748 arg = context_arg | 5794 original_arg = func.MakeTypedOriginalArgString("") |
5749 file.Write(" %s (*%s)(%s);\n" % (func.return_type, func.name, arg)) | 5795 context_arg = "PP_Resource context" |
5750 file.Write("};\n\n") | 5796 if len(original_arg): |
| 5797 arg = context_arg + ", " + original_arg |
| 5798 else: |
| 5799 arg = context_arg |
| 5800 file.Write(" %s (*%s)(%s);\n" % (func.return_type, func.name, arg)) |
| 5801 file.Write("};\n\n") |
| 5802 |
5751 | 5803 |
5752 file.Close() | 5804 file.Close() |
5753 | 5805 |
5754 def WritePepperGLES2Implementation(self, filename): | 5806 def WritePepperGLES2Implementation(self, filename): |
5755 """Writes the Pepper OpenGLES interface implementation.""" | 5807 """Writes the Pepper OpenGLES interface implementation.""" |
5756 | 5808 |
5757 file = CWriter(filename) | 5809 file = CWriter(filename) |
5758 file.Write(_LICENSE) | 5810 file.Write(_LICENSE) |
5759 file.Write(_DO_NOT_EDIT_WARNING) | 5811 file.Write(_DO_NOT_EDIT_WARNING) |
5760 | 5812 |
5761 file.Write("#include \"ppapi/shared_impl/ppb_opengles2_shared.h\"\n\n") | 5813 file.Write("#include \"ppapi/shared_impl/ppb_opengles2_shared.h\"\n\n") |
5762 file.Write("#include \"base/logging.h\"\n") | 5814 file.Write("#include \"base/logging.h\"\n") |
5763 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) | 5815 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) |
5764 file.Write("#include \"ppapi/shared_impl/ppb_graphics_3d_shared.h\"\n") | 5816 file.Write("#include \"ppapi/shared_impl/ppb_graphics_3d_shared.h\"\n") |
5765 file.Write("#include \"ppapi/thunk/enter.h\"\n\n") | 5817 file.Write("#include \"ppapi/thunk/enter.h\"\n\n") |
5766 | 5818 |
5767 file.Write("namespace ppapi {\n\n") | 5819 file.Write("namespace ppapi {\n\n") |
5768 file.Write("namespace {\n\n") | 5820 file.Write("namespace {\n\n") |
5769 | 5821 |
5770 file.Write("gpu::gles2::GLES2Implementation*" | 5822 file.Write("gpu::gles2::GLES2Implementation*" |
5771 " GetGLES(PP_Resource context) {\n") | 5823 " GetGLES(PP_Resource context) {\n") |
5772 file.Write(" thunk::EnterResource<thunk::PPB_Graphics3D_API>" | 5824 file.Write(" thunk::EnterResource<thunk::PPB_Graphics3D_API>" |
5773 " enter_g3d(context, false);\n") | 5825 " enter_g3d(context, false);\n") |
5774 file.Write(" DCHECK(enter_g3d.succeeded());\n") | 5826 file.Write(" DCHECK(enter_g3d.succeeded());\n") |
5775 file.Write(" return static_cast<PPB_Graphics3D_Shared*>" | 5827 file.Write(" return static_cast<PPB_Graphics3D_Shared*>" |
5776 "(enter_g3d.object())->gles2_impl();\n") | 5828 "(enter_g3d.object())->gles2_impl();\n") |
5777 file.Write("}\n\n") | 5829 file.Write("}\n\n") |
5778 | 5830 |
5779 for func in self.original_functions: | 5831 for func in self.original_functions: |
5780 if not func.IsCoreGLFunction(): | 5832 if not func.InAnyPepperExtension(): |
5781 continue | 5833 continue |
5782 | 5834 |
5783 original_arg = func.MakeTypedOriginalArgString("") | 5835 original_arg = func.MakeTypedOriginalArgString("") |
5784 context_arg = "PP_Resource context_id" | 5836 context_arg = "PP_Resource context_id" |
5785 if len(original_arg): | 5837 if len(original_arg): |
5786 arg = context_arg + ", " + original_arg | 5838 arg = context_arg + ", " + original_arg |
5787 else: | 5839 else: |
5788 arg = context_arg | 5840 arg = context_arg |
5789 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) | 5841 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) |
5790 | 5842 |
5791 return_str = "" if func.return_type == "void" else "return " | 5843 return_str = "" if func.return_type == "void" else "return " |
5792 file.Write(" %sGetGLES(context_id)->%s(%s);\n" % | 5844 file.Write(" %sGetGLES(context_id)->%s(%s);\n" % |
5793 (return_str, func.original_name, | 5845 (return_str, func.original_name, |
5794 func.MakeOriginalArgString(""))) | 5846 func.MakeOriginalArgString(""))) |
5795 file.Write("}\n\n") | 5847 file.Write("}\n\n") |
5796 | 5848 |
5797 file.Write("\nconst struct PPB_OpenGLES2 ppb_opengles2 = {\n") | 5849 for interface in _PEPPER_INTERFACES: |
5798 file.Write(" &") | 5850 file.Write("\nconst struct PPB_OpenGLES2%s " |
5799 file.Write(",\n &".join( | 5851 "ppb_opengles2_%s = {\n" % (interface, interface.lower())) |
5800 f.name for f in self.original_functions if f.IsCoreGLFunction())) | 5852 file.Write(" &") |
5801 file.Write("\n") | 5853 file.Write(",\n &".join( |
5802 file.Write("};\n\n") | 5854 f.name for f in self.original_functions |
| 5855 if f.InPepperInterface(interface))) |
| 5856 file.Write("\n") |
| 5857 file.Write("};\n\n") |
5803 | 5858 |
5804 file.Write("} // namespace\n") | 5859 file.Write("} // namespace\n") |
5805 | 5860 |
5806 file.Write(""" | 5861 for interface in _PEPPER_INTERFACES: |
5807 const PPB_OpenGLES2* PPB_OpenGLES2_Shared::GetInterface() { | 5862 file.Write(""" |
5808 return &ppb_opengles2; | 5863 const PPB_OpenGLES2%s* PPB_OpenGLES2_Shared::Get%sInterface() { |
| 5864 return &ppb_opengles2_%s; |
5809 } | 5865 } |
5810 | 5866 |
5811 """) | 5867 """ % (interface, interface, interface.lower())) |
5812 file.Write("} // namespace ppapi\n") | 5868 file.Write("} // namespace ppapi\n") |
5813 file.Close() | 5869 file.Close() |
5814 | 5870 |
5815 def WriteGLES2ToPPAPIBridge(self, filename): | 5871 def WriteGLES2ToPPAPIBridge(self, filename): |
5816 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" | 5872 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" |
5817 | 5873 |
5818 file = CWriter(filename) | 5874 file = CWriter(filename) |
5819 file.Write(_LICENSE) | 5875 file.Write(_LICENSE) |
5820 file.Write(_DO_NOT_EDIT_WARNING) | 5876 file.Write(_DO_NOT_EDIT_WARNING) |
5821 | 5877 |
5822 file.Write("#include <GLES2/gl2.h>\n") | 5878 file.Write("#include <GLES2/gl2.h>\n") |
5823 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") | 5879 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") |
5824 | 5880 |
5825 for func in self.original_functions: | 5881 for func in self.original_functions: |
5826 if not func.IsCoreGLFunction(): | 5882 if not func.InAnyPepperExtension(): |
5827 continue | 5883 continue |
5828 | 5884 |
| 5885 interface = func.GetInfo('pepper_interface') or '' |
| 5886 |
5829 file.Write("%s GL_APIENTRY gl%s(%s) {\n" % | 5887 file.Write("%s GL_APIENTRY gl%s(%s) {\n" % |
5830 (func.return_type, func.name, | 5888 (func.return_type, func.name, |
5831 func.MakeTypedOriginalArgString(""))) | 5889 func.MakeTypedOriginalArgString(""))) |
5832 return_str = "" if func.return_type == "void" else "return " | 5890 return_str = "" if func.return_type == "void" else "return " |
5833 interface_str = "glGetInterfacePPAPI()" | 5891 interface_str = "glGet%sInterfacePPAPI()" % interface |
5834 original_arg = func.MakeOriginalArgString("") | 5892 original_arg = func.MakeOriginalArgString("") |
5835 context_arg = "glGetCurrentContextPPAPI()" | 5893 context_arg = "glGetCurrentContextPPAPI()" |
5836 if len(original_arg): | 5894 if len(original_arg): |
5837 arg = context_arg + ", " + original_arg | 5895 arg = context_arg + ", " + original_arg |
5838 else: | 5896 else: |
5839 arg = context_arg | 5897 arg = context_arg |
5840 file.Write(" %s%s->%s(%s);\n" % | 5898 if interface: |
5841 (return_str, interface_str, func.name, arg)) | 5899 file.Write(" const struct PPB_OpenGLES2%s* ext = %s;" % |
| 5900 (interface, interface_str)) |
| 5901 file.Write(" if (ext)\n") |
| 5902 file.Write(" %sext->%s(%s);\n" % |
| 5903 (return_str, func.name, arg)) |
| 5904 if return_str: |
| 5905 file.Write(" %s0;\n" % return_str) |
| 5906 else: |
| 5907 file.Write(" %s%s->%s(%s);\n" % |
| 5908 (return_str, interface_str, func.name, arg)) |
5842 file.Write("}\n\n") | 5909 file.Write("}\n\n") |
| 5910 file.Close() |
5843 | 5911 |
5844 def WritePepperGLES2NaClProxy(self, filename): | 5912 def WritePepperGLES2NaClProxy(self, filename): |
5845 """Writes the Pepper OpenGLES interface implementation for NaCl.""" | 5913 """Writes the Pepper OpenGLES interface implementation for NaCl.""" |
5846 file = CWriter(filename) | 5914 file = CWriter(filename) |
5847 file.Write(_LICENSE) | 5915 file.Write(_LICENSE) |
5848 file.Write(_DO_NOT_EDIT_WARNING) | 5916 file.Write(_DO_NOT_EDIT_WARNING) |
5849 | 5917 |
5850 file.Write("#include \"native_client/src/shared/ppapi_proxy" | 5918 file.Write("#include \"native_client/src/shared/ppapi_proxy" |
5851 "/plugin_ppb_graphics_3d.h\"\n\n") | 5919 "/plugin_ppb_graphics_3d.h\"\n\n") |
5852 | 5920 |
5853 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") | 5921 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") |
5854 file.Write("\n#include \"native_client/src/third_party" | 5922 file.Write("\n#include \"ppapi/c/ppb_opengles2.h\"\n\n") |
5855 "/ppapi/c/dev/ppb_opengles_dev.h\"\n\n") | |
5856 | 5923 |
5857 file.Write("using ppapi_proxy::PluginGraphics3D;\n") | 5924 file.Write("using ppapi_proxy::PluginGraphics3D;\n") |
5858 file.Write("using ppapi_proxy::PluginResource;\n\n") | 5925 file.Write("using ppapi_proxy::PluginResource;\n\n") |
5859 file.Write("namespace {\n\n") | 5926 file.Write("namespace {\n\n") |
5860 | 5927 |
5861 for func in self.original_functions: | 5928 for func in self.original_functions: |
5862 if not func.IsCoreGLFunction(): | 5929 if not func.InAnyPepperExtension(): |
5863 continue | 5930 continue |
5864 args = func.MakeTypedOriginalArgString("") | 5931 args = func.MakeTypedOriginalArgString("") |
5865 if len(args) != 0: | 5932 if len(args) != 0: |
5866 args = ", " + args | 5933 args = ", " + args |
5867 file.Write("%s %s(PP_Resource context%s) {\n" % | 5934 file.Write("%s %s(PP_Resource context%s) {\n" % |
5868 (func.return_type, func.name, args)) | 5935 (func.return_type, func.name, args)) |
5869 return_string = "return " | 5936 return_string = "return " |
5870 if func.return_type == "void": | 5937 if func.return_type == "void": |
5871 return_string = "" | 5938 return_string = "" |
5872 file.Write(" %sPluginGraphics3D::implFromResource(context)->" | 5939 file.Write(" %sPluginGraphics3D::implFromResource(context)->" |
5873 "%s(%s);\n" % | 5940 "%s(%s);\n" % |
5874 (return_string, | 5941 (return_string, |
5875 func.original_name, | 5942 func.original_name, |
5876 func.MakeOriginalArgString(""))) | 5943 func.MakeOriginalArgString(""))) |
5877 file.Write("}\n") | 5944 file.Write("}\n") |
5878 | 5945 |
5879 file.Write("\n} // namespace\n\n") | 5946 file.Write("\n} // namespace\n\n") |
5880 | 5947 |
5881 file.Write("const PPB_OpenGLES2* " | 5948 for interface in _PEPPER_INTERFACES: |
5882 "PluginGraphics3D::GetOpenGLESInterface() {\n") | 5949 file.Write("const PPB_OpenGLES2%s* " |
| 5950 "PluginGraphics3D::GetOpenGLES%sInterface() {\n" % |
| 5951 (interface, interface)) |
5883 | 5952 |
5884 file.Write(" const static struct PPB_OpenGLES2 ppb_opengles = {\n") | 5953 file.Write(" const static struct PPB_OpenGLES2%s ppb_opengles = {\n" % |
5885 file.Write(" &") | 5954 interface) |
5886 file.Write(",\n &".join( | 5955 file.Write(" &") |
5887 f.name for f in self.original_functions if f.IsCoreGLFunction())) | 5956 file.Write(",\n &".join( |
5888 file.Write("\n") | 5957 f.name for f in self.original_functions |
5889 file.Write(" };\n") | 5958 if f.InPepperInterface(interface))) |
5890 file.Write(" return &ppb_opengles;\n") | 5959 file.Write("\n") |
5891 file.Write("}\n") | 5960 file.Write(" };\n") |
| 5961 file.Write(" return &ppb_opengles;\n") |
| 5962 file.Write("}\n") |
5892 file.Close() | 5963 file.Close() |
5893 | 5964 |
5894 | 5965 |
5895 def main(argv): | 5966 def main(argv): |
5896 """This is the main function.""" | 5967 """This is the main function.""" |
5897 parser = OptionParser() | 5968 parser = OptionParser() |
5898 parser.add_option( | 5969 parser.add_option( |
5899 "-g", "--generate-implementation-templates", action="store_true", | 5970 "-g", "--generate-implementation-templates", action="store_true", |
5900 help="generates files that are generally hand edited..") | 5971 help="generates files that are generally hand edited..") |
5901 parser.add_option( | 5972 parser.add_option( |
(...skipping 28 matching lines...) Expand all Loading... |
5930 os.chdir("ppapi"); | 6001 os.chdir("ppapi"); |
5931 gen.WritePepperGLES2Interface("c/ppb_opengles2.h") | 6002 gen.WritePepperGLES2Interface("c/ppb_opengles2.h") |
5932 gen.WriteGLES2ToPPAPIBridge("lib/gl/gles2/gles2.c") | 6003 gen.WriteGLES2ToPPAPIBridge("lib/gl/gles2/gles2.c") |
5933 | 6004 |
5934 elif options.alternate_mode == "chrome_ppapi": | 6005 elif options.alternate_mode == "chrome_ppapi": |
5935 # To trigger this action, do "make ppapi_gles_implementation" | 6006 # To trigger this action, do "make ppapi_gles_implementation" |
5936 gen.WritePepperGLES2Implementation( | 6007 gen.WritePepperGLES2Implementation( |
5937 "ppapi/shared_impl/ppb_opengles2_shared.cc") | 6008 "ppapi/shared_impl/ppb_opengles2_shared.cc") |
5938 | 6009 |
5939 elif options.alternate_mode == "nacl_ppapi": | 6010 elif options.alternate_mode == "nacl_ppapi": |
| 6011 os.chdir("ppapi") |
5940 gen.WritePepperGLES2NaClProxy( | 6012 gen.WritePepperGLES2NaClProxy( |
5941 "native_client/src/shared/ppapi_proxy/plugin_opengles.cc") | 6013 "native_client/src/shared/ppapi_proxy/plugin_opengles.cc") |
5942 | 6014 |
5943 else: | 6015 else: |
5944 os.chdir("gpu/command_buffer") | 6016 os.chdir("gpu/command_buffer") |
5945 gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") | 6017 gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") |
5946 gen.WriteFormat("common/gles2_cmd_format_autogen.h") | 6018 gen.WriteFormat("common/gles2_cmd_format_autogen.h") |
5947 gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") | 6019 gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") |
5948 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") | 6020 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") |
5949 gen.WriteGLES2ImplementationUnitTests( | 6021 gen.WriteGLES2ImplementationUnitTests( |
5950 "client/gles2_implementation_unittest_autogen.h") | 6022 "client/gles2_implementation_unittest_autogen.h") |
5951 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") | 6023 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") |
5952 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") | 6024 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") |
5953 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") | 6025 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") |
5954 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") | 6026 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") |
5955 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") | 6027 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") |
5956 gen.WriteServiceUtilsImplementation( | 6028 gen.WriteServiceUtilsImplementation( |
5957 "service/gles2_cmd_validation_implementation_autogen.h") | 6029 "service/gles2_cmd_validation_implementation_autogen.h") |
5958 gen.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h") | 6030 gen.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h") |
5959 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") | 6031 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") |
5960 | 6032 |
5961 if gen.errors > 0: | 6033 if gen.errors > 0: |
5962 print "%d errors" % gen.errors | 6034 print "%d errors" % gen.errors |
5963 return 1 | 6035 return 1 |
5964 return 0 | 6036 return 0 |
5965 | 6037 |
5966 | 6038 |
5967 if __name__ == '__main__': | 6039 if __name__ == '__main__': |
5968 sys.exit(main(sys.argv[1:])) | 6040 sys.exit(main(sys.argv[1:])) |
OLD | NEW |