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 itertools | 8 import itertools |
9 import os | 9 import os |
10 import os.path | 10 import os.path |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 {'name': '', 'dev': False}, | 1206 {'name': '', 'dev': False}, |
1207 {'name': 'InstancedArrays', 'dev': False}, | 1207 {'name': 'InstancedArrays', 'dev': False}, |
1208 {'name': 'FramebufferBlit', 'dev': False}, | 1208 {'name': 'FramebufferBlit', 'dev': False}, |
1209 {'name': 'FramebufferMultisample', 'dev': False}, | 1209 {'name': 'FramebufferMultisample', 'dev': False}, |
1210 {'name': 'ChromiumEnableFeature', 'dev': False}, | 1210 {'name': 'ChromiumEnableFeature', 'dev': False}, |
1211 {'name': 'ChromiumMapSub', 'dev': False}, | 1211 {'name': 'ChromiumMapSub', 'dev': False}, |
1212 {'name': 'Query', 'dev': False}, | 1212 {'name': 'Query', 'dev': False}, |
1213 {'name': 'DrawBuffers', 'dev': True}, | 1213 {'name': 'DrawBuffers', 'dev': True}, |
1214 ] | 1214 ] |
1215 | 1215 |
1216 # This table specifies types and other special data for the commands that | 1216 # A function info object specifies the type and other special data for the |
1217 # will be generated. | 1217 # command that will be generated. A base function info object is generated by |
| 1218 # parsing the "cmd_buffer_functions.txt", one for each function in the |
| 1219 # file. These function info objects can be augmented and their values can be |
| 1220 # overridden by adding an object to the table below. |
1218 # | 1221 # |
1219 # Must match function names specified in "cmd_buffer_functions.txt". | 1222 # Must match function names specified in "cmd_buffer_functions.txt". |
1220 # | 1223 # |
1221 # cmd_comment: A comment added to the cmd format. | 1224 # cmd_comment: A comment added to the cmd format. |
1222 # type: defines which handler will be used to generate code. | 1225 # type: defines which handler will be used to generate code. |
1223 # decoder_func: defines which function to call in the decoder to execute the | 1226 # decoder_func: defines which function to call in the decoder to execute the |
1224 # corresponding GL command. If not specified the GL command will | 1227 # corresponding GL command. If not specified the GL command will |
1225 # be called directly. | 1228 # be called directly. |
1226 # gl_test_func: GL function that is expected to be called when testing. | 1229 # gl_test_func: GL function that is expected to be called when testing. |
1227 # cmd_args: The arguments to use for the command. This overrides generating | 1230 # cmd_args: The arguments to use for the command. This overrides generating |
(...skipping 3596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4824 self.WriteInvalidUnitTest(func, file, invalid_test, extra) | 4827 self.WriteInvalidUnitTest(func, file, invalid_test, extra) |
4825 | 4828 |
4826 def WriteGetDataSizeCode(self, func, file): | 4829 def WriteGetDataSizeCode(self, func, file): |
4827 """Overrriden from TypeHandler.""" | 4830 """Overrriden from TypeHandler.""" |
4828 code = """ uint32_t data_size; | 4831 code = """ uint32_t data_size; |
4829 if (!ComputeDataSize(1, sizeof(%s), %d, &data_size)) { | 4832 if (!ComputeDataSize(1, sizeof(%s), %d, &data_size)) { |
4830 return error::kOutOfBounds; | 4833 return error::kOutOfBounds; |
4831 } | 4834 } |
4832 """ | 4835 """ |
4833 file.Write(code % (self.GetArrayType(func), self.GetArrayCount(func))) | 4836 file.Write(code % (self.GetArrayType(func), self.GetArrayCount(func))) |
4834 if func.is_immediate: | 4837 if func.IsImmediate(): |
4835 file.Write(" if (data_size > immediate_data_size) {\n") | 4838 file.Write(" if (data_size > immediate_data_size) {\n") |
4836 file.Write(" return error::kOutOfBounds;\n") | 4839 file.Write(" return error::kOutOfBounds;\n") |
4837 file.Write(" }\n") | 4840 file.Write(" }\n") |
4838 | 4841 |
4839 def WriteGLES2Implementation(self, func, file): | 4842 def WriteGLES2Implementation(self, func, file): |
4840 """Overrriden from TypeHandler.""" | 4843 """Overrriden from TypeHandler.""" |
4841 impl_func = func.GetInfo('impl_func') | 4844 impl_func = func.GetInfo('impl_func') |
4842 if (impl_func != None and impl_func != True): | 4845 if (impl_func != None and impl_func != True): |
4843 return; | 4846 return; |
4844 file.Write("%s GLES2Implementation::%s(%s) {\n" % | 4847 file.Write("%s GLES2Implementation::%s(%s) {\n" % |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5092 self.WriteInvalidUnitTest(func, file, invalid_test, extra) | 5095 self.WriteInvalidUnitTest(func, file, invalid_test, extra) |
5093 | 5096 |
5094 def WriteGetDataSizeCode(self, func, file): | 5097 def WriteGetDataSizeCode(self, func, file): |
5095 """Overrriden from TypeHandler.""" | 5098 """Overrriden from TypeHandler.""" |
5096 code = """ uint32_t data_size; | 5099 code = """ uint32_t data_size; |
5097 if (!ComputeDataSize(count, sizeof(%s), %d, &data_size)) { | 5100 if (!ComputeDataSize(count, sizeof(%s), %d, &data_size)) { |
5098 return error::kOutOfBounds; | 5101 return error::kOutOfBounds; |
5099 } | 5102 } |
5100 """ | 5103 """ |
5101 file.Write(code % (self.GetArrayType(func), self.GetArrayCount(func))) | 5104 file.Write(code % (self.GetArrayType(func), self.GetArrayCount(func))) |
5102 if func.is_immediate: | 5105 if func.IsImmediate(): |
5103 file.Write(" if (data_size > immediate_data_size) {\n") | 5106 file.Write(" if (data_size > immediate_data_size) {\n") |
5104 file.Write(" return error::kOutOfBounds;\n") | 5107 file.Write(" return error::kOutOfBounds;\n") |
5105 file.Write(" }\n") | 5108 file.Write(" }\n") |
5106 | 5109 |
5107 def WriteGLES2Implementation(self, func, file): | 5110 def WriteGLES2Implementation(self, func, file): |
5108 """Overrriden from TypeHandler.""" | 5111 """Overrriden from TypeHandler.""" |
5109 file.Write("%s GLES2Implementation::%s(%s) {\n" % | 5112 file.Write("%s GLES2Implementation::%s(%s) {\n" % |
5110 (func.return_type, func.original_name, | 5113 (func.return_type, func.original_name, |
5111 func.MakeTypedOriginalArgString(""))) | 5114 func.MakeTypedOriginalArgString(""))) |
5112 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") | 5115 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5766 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 5769 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
5767 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); | 5770 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); |
5768 } | 5771 } |
5769 """ | 5772 """ |
5770 self.WriteValidUnitTest(func, file, invalid_test) | 5773 self.WriteValidUnitTest(func, file, invalid_test) |
5771 | 5774 |
5772 def WriteServiceImplementation(self, func, file): | 5775 def WriteServiceImplementation(self, func, file): |
5773 """Overrriden from TypeHandler.""" | 5776 """Overrriden from TypeHandler.""" |
5774 pass | 5777 pass |
5775 | 5778 |
5776 | |
5777 class FunctionInfo(object): | |
5778 """Holds info about a function.""" | |
5779 | |
5780 def __init__(self, info, type_handler): | |
5781 for key in info: | |
5782 setattr(self, key, info[key]) | |
5783 self.type_handler = type_handler | |
5784 if not 'type' in info: | |
5785 self.type = '' | |
5786 | |
5787 | |
5788 class Argument(object): | 5779 class Argument(object): |
5789 """A class that represents a function argument.""" | 5780 """A class that represents a function argument.""" |
5790 | 5781 |
5791 cmd_type_map_ = { | 5782 cmd_type_map_ = { |
5792 'GLenum': 'uint32_t', | 5783 'GLenum': 'uint32_t', |
5793 'GLint': 'int32_t', | 5784 'GLint': 'int32_t', |
5794 'GLintptr': 'int32_t', | 5785 'GLintptr': 'int32_t', |
5795 'GLsizei': 'int32_t', | 5786 'GLsizei': 'int32_t', |
5796 'GLsizeiptr': 'int32_t', | 5787 'GLsizeiptr': 'int32_t', |
5797 'GLfloat': 'float', | 5788 'GLfloat': 'float', |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5953 | 5944 |
5954 | 5945 |
5955 class SizeArgument(Argument): | 5946 class SizeArgument(Argument): |
5956 """class for GLsizei and GLsizeiptr.""" | 5947 """class for GLsizei and GLsizeiptr.""" |
5957 | 5948 |
5958 def __init__(self, name, type): | 5949 def __init__(self, name, type): |
5959 Argument.__init__(self, name, type) | 5950 Argument.__init__(self, name, type) |
5960 | 5951 |
5961 def GetNumInvalidValues(self, func): | 5952 def GetNumInvalidValues(self, func): |
5962 """overridden from Argument.""" | 5953 """overridden from Argument.""" |
5963 if func.is_immediate: | 5954 if func.IsImmediate(): |
5964 return 0 | 5955 return 0 |
5965 return 1 | 5956 return 1 |
5966 | 5957 |
5967 def GetInvalidArg(self, offset, index): | 5958 def GetInvalidArg(self, offset, index): |
5968 """overridden from Argument.""" | 5959 """overridden from Argument.""" |
5969 return ("-1", "kNoError", "GL_INVALID_VALUE") | 5960 return ("-1", "kNoError", "GL_INVALID_VALUE") |
5970 | 5961 |
5971 def WriteValidationCode(self, file, func): | 5962 def WriteValidationCode(self, file, func): |
5972 """overridden from Argument.""" | 5963 """overridden from Argument.""" |
5973 file.Write(" if (%s < 0) {\n" % self.name) | 5964 file.Write(" if (%s < 0) {\n" % self.name) |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6382 return 1 | 6373 return 1 |
6383 | 6374 |
6384 def GetInvalidArg(self, offset, index): | 6375 def GetInvalidArg(self, offset, index): |
6385 """returns an invalid value by index.""" | 6376 """returns an invalid value by index.""" |
6386 return ("kInvalidClientId", "kNoError", "GL_INVALID_VALUE") | 6377 return ("kInvalidClientId", "kNoError", "GL_INVALID_VALUE") |
6387 | 6378 |
6388 | 6379 |
6389 class Function(object): | 6380 class Function(object): |
6390 """A class that represents a function.""" | 6381 """A class that represents a function.""" |
6391 | 6382 |
6392 def __init__(self, original_name, name, info, return_type, original_args, | 6383 type_handlers = { |
6393 args_for_cmds, cmd_args, init_args, num_pointer_args): | 6384 '': TypeHandler(), |
| 6385 'Bind': BindHandler(), |
| 6386 'Create': CreateHandler(), |
| 6387 'Custom': CustomHandler(), |
| 6388 'Data': DataHandler(), |
| 6389 'Delete': DeleteHandler(), |
| 6390 'DELn': DELnHandler(), |
| 6391 'GENn': GENnHandler(), |
| 6392 'GETn': GETnHandler(), |
| 6393 'GLchar': GLcharHandler(), |
| 6394 'GLcharN': GLcharNHandler(), |
| 6395 'HandWritten': HandWrittenHandler(), |
| 6396 'Is': IsHandler(), |
| 6397 'Manual': ManualHandler(), |
| 6398 'PUT': PUTHandler(), |
| 6399 'PUTn': PUTnHandler(), |
| 6400 'PUTXn': PUTXnHandler(), |
| 6401 'StateSet': StateSetHandler(), |
| 6402 'StateSetRGBAlpha': StateSetRGBAlphaHandler(), |
| 6403 'StateSetFrontBack': StateSetFrontBackHandler(), |
| 6404 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(), |
| 6405 'StateSetNamedParameter': StateSetNamedParameter(), |
| 6406 'STRn': STRnHandler(), |
| 6407 'Todo': TodoHandler(), |
| 6408 } |
| 6409 |
| 6410 def __init__(self, name, info): |
6394 self.name = name | 6411 self.name = name |
6395 self.original_name = original_name | 6412 self.original_name = info['original_name'] |
| 6413 |
| 6414 self.original_args = self.ParseArgs(info['original_args']) |
| 6415 |
| 6416 if 'cmd_args' in info: |
| 6417 self.args_for_cmds = self.ParseArgs(info['cmd_args']) |
| 6418 else: |
| 6419 self.args_for_cmds = self.original_args[:] |
| 6420 |
| 6421 self.return_type = info['return_type'] |
| 6422 if self.return_type != 'void': |
| 6423 self.return_arg = CreateArg(info['return_type'] + " result") |
| 6424 else: |
| 6425 self.return_arg = None |
| 6426 |
| 6427 self.num_pointer_args = sum( |
| 6428 [1 for arg in self.args_for_cmds if arg.IsPointer()]) |
6396 self.info = info | 6429 self.info = info |
6397 self.type_handler = info.type_handler | 6430 self.type_handler = self.type_handlers[info['type']] |
6398 self.return_type = return_type | 6431 self.can_auto_generate = (self.num_pointer_args == 0 and |
6399 self.original_args = original_args | 6432 info['return_type'] == "void") |
6400 self.num_pointer_args = num_pointer_args | |
6401 self.can_auto_generate = num_pointer_args == 0 and return_type == "void" | |
6402 self.cmd_args = cmd_args | |
6403 self.init_args = init_args | |
6404 self.InitFunction() | 6433 self.InitFunction() |
6405 self.args_for_cmds = args_for_cmds | 6434 |
6406 self.is_immediate = False | 6435 def ParseArgs(self, arg_string): |
| 6436 """Parses a function arg string.""" |
| 6437 args = [] |
| 6438 parts = arg_string.split(',') |
| 6439 for arg_string in parts: |
| 6440 arg = CreateArg(arg_string) |
| 6441 if arg: |
| 6442 args.append(arg) |
| 6443 return args |
6407 | 6444 |
6408 def IsType(self, type_name): | 6445 def IsType(self, type_name): |
6409 """Returns true if function is a certain type.""" | 6446 """Returns true if function is a certain type.""" |
6410 return self.info.type == type_name | 6447 return self.info['type'] == type_name |
6411 | 6448 |
6412 def InitFunction(self): | 6449 def InitFunction(self): |
6413 """Calls the init function for the type handler.""" | 6450 """Creates command args and calls the init function for the type handler. |
| 6451 |
| 6452 Creates argument lists for command buffer commands, eg. self.cmd_args and |
| 6453 self.init_args. |
| 6454 Calls the type function initialization. |
| 6455 Override to create different kind of command buffer command argument lists. |
| 6456 """ |
| 6457 self.cmd_args = [] |
| 6458 for arg in self.args_for_cmds: |
| 6459 arg.AddCmdArgs(self.cmd_args) |
| 6460 |
| 6461 self.init_args = [] |
| 6462 for arg in self.args_for_cmds: |
| 6463 arg.AddInitArgs(self.init_args) |
| 6464 |
| 6465 if self.return_arg: |
| 6466 self.init_args.append(self.return_arg) |
| 6467 |
6414 self.type_handler.InitFunction(self) | 6468 self.type_handler.InitFunction(self) |
6415 | 6469 |
6416 def GetInfo(self, name): | 6470 def IsImmediate(self): |
| 6471 """Returns whether the function is immediate data function or not.""" |
| 6472 return False |
| 6473 |
| 6474 def GetInfo(self, name, default = None): |
6417 """Returns a value from the function info for this function.""" | 6475 """Returns a value from the function info for this function.""" |
6418 if hasattr(self.info, name): | 6476 if name in self.info: |
6419 return getattr(self.info, name) | 6477 return self.info[name] |
6420 return None | 6478 return default |
6421 | 6479 |
6422 def GetValidArg(self, index): | 6480 def GetValidArg(self, index): |
6423 """Gets a valid arg from the function info if one exists.""" | 6481 """Gets a valid arg from the function info if one exists.""" |
6424 valid_args = self.GetInfo('valid_args') | 6482 valid_args = self.GetInfo('valid_args') |
6425 if valid_args and str(index) in valid_args: | 6483 if valid_args and str(index) in valid_args: |
6426 return valid_args[str(index)] | 6484 return valid_args[str(index)] |
6427 return None | 6485 return None |
6428 | 6486 |
6429 def AddInfo(self, name, value): | 6487 def AddInfo(self, name, value): |
6430 """Adds an info.""" | 6488 """Adds an info.""" |
6431 setattr(self.info, name, value) | 6489 self.info[name] = value |
6432 | 6490 |
6433 def IsCoreGLFunction(self): | 6491 def IsCoreGLFunction(self): |
6434 return (not self.GetInfo('extension') and | 6492 return (not self.GetInfo('extension') and |
6435 not self.GetInfo('pepper_interface')) | 6493 not self.GetInfo('pepper_interface')) |
6436 | 6494 |
6437 def InPepperInterface(self, interface): | 6495 def InPepperInterface(self, interface): |
6438 ext = self.GetInfo('pepper_interface') | 6496 ext = self.GetInfo('pepper_interface') |
6439 if not interface.GetName(): | 6497 if not interface.GetName(): |
6440 return self.IsCoreGLFunction() | 6498 return self.IsCoreGLFunction() |
6441 return ext == interface.GetName() | 6499 return ext == interface.GetName() |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6563 """Writes the handler implementation for this command.""" | 6621 """Writes the handler implementation for this command.""" |
6564 self.type_handler.WriteHandlerImplementation(self, file) | 6622 self.type_handler.WriteHandlerImplementation(self, file) |
6565 | 6623 |
6566 def WriteValidationCode(self, file): | 6624 def WriteValidationCode(self, file): |
6567 """Writes the validation code for a command.""" | 6625 """Writes the validation code for a command.""" |
6568 pass | 6626 pass |
6569 | 6627 |
6570 def WriteCmdFlag(self, file): | 6628 def WriteCmdFlag(self, file): |
6571 """Writes the cmd cmd_flags constant.""" | 6629 """Writes the cmd cmd_flags constant.""" |
6572 flags = [] | 6630 flags = [] |
6573 trace_level = 3 # By default trace only at the highest level | 6631 # By default trace only at the highest level 3. |
6574 if hasattr(self.info, 'trace_level'): | 6632 trace_level = int(self.GetInfo('trace_level', default = 3)) |
6575 if (self.info.trace_level < 0) or (self.info.trace_level > 3): | 6633 if trace_level not in xrange(0, 4): |
6576 raise KeyError("Unhandled trace_level: %d" % self.info.trace_level) | 6634 raise KeyError("Unhandled trace_level: %d" % trace_level) |
6577 trace_level = self.info.trace_level | |
6578 | 6635 |
6579 flags.append('CMD_FLAG_SET_TRACE_LEVEL(%d)' % trace_level) | 6636 flags.append('CMD_FLAG_SET_TRACE_LEVEL(%d)' % trace_level) |
6580 | 6637 |
6581 if len(flags) > 0: | 6638 if len(flags) > 0: |
6582 cmd_flags = ' | '.join(flags) | 6639 cmd_flags = ' | '.join(flags) |
6583 else: | 6640 else: |
6584 cmd_flags = 0 | 6641 cmd_flags = 0 |
6585 | 6642 |
6586 file.Write(" static const uint8 cmd_flags = %s;\n" % cmd_flags) | 6643 file.Write(" static const uint8 cmd_flags = %s;\n" % cmd_flags) |
6587 | 6644 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6721 dev = "" | 6778 dev = "" |
6722 if self.dev: | 6779 if self.dev: |
6723 dev = "_Dev" | 6780 dev = "_Dev" |
6724 return "PPB_OpenGLES2%s%s" % (self.name, dev) | 6781 return "PPB_OpenGLES2%s%s" % (self.name, dev) |
6725 | 6782 |
6726 | 6783 |
6727 class ImmediateFunction(Function): | 6784 class ImmediateFunction(Function): |
6728 """A class that represnets an immediate function command.""" | 6785 """A class that represnets an immediate function command.""" |
6729 | 6786 |
6730 def __init__(self, func): | 6787 def __init__(self, func): |
6731 new_args = [] | 6788 Function.__init__( |
6732 for arg in func.GetOriginalArgs(): | 6789 self, |
| 6790 "%sImmediate" % func.name, |
| 6791 func.info) |
| 6792 |
| 6793 def InitFunction(self): |
| 6794 # Override args in original_args and args_for_cmds with immediate versions |
| 6795 # of the args. |
| 6796 |
| 6797 new_original_args = [] |
| 6798 for arg in self.original_args: |
6733 new_arg = arg.GetImmediateVersion() | 6799 new_arg = arg.GetImmediateVersion() |
6734 if new_arg: | 6800 if new_arg: |
6735 new_args.append(new_arg) | 6801 new_original_args.append(new_arg) |
| 6802 self.original_args = new_original_args |
6736 | 6803 |
6737 cmd_args = [] | |
6738 new_args_for_cmds = [] | 6804 new_args_for_cmds = [] |
6739 for arg in func.args_for_cmds: | 6805 for arg in self.args_for_cmds: |
6740 new_arg = arg.GetImmediateVersion() | 6806 new_arg = arg.GetImmediateVersion() |
6741 if new_arg: | 6807 if new_arg: |
6742 new_args_for_cmds.append(new_arg) | 6808 new_args_for_cmds.append(new_arg) |
6743 new_arg.AddCmdArgs(cmd_args) | |
6744 | 6809 |
6745 new_init_args = [] | 6810 self.args_for_cmds = new_args_for_cmds |
6746 for arg in new_args_for_cmds: | |
6747 arg.AddInitArgs(new_init_args) | |
6748 | 6811 |
6749 Function.__init__( | 6812 Function.InitFunction(self) |
6750 self, | 6813 |
6751 func.original_name, | 6814 def IsImmediate(self): |
6752 "%sImmediate" % func.name, | 6815 return True |
6753 func.info, | |
6754 func.return_type, | |
6755 new_args, | |
6756 new_args_for_cmds, | |
6757 cmd_args, | |
6758 new_init_args, | |
6759 0) | |
6760 self.is_immediate = True | |
6761 | 6816 |
6762 def WriteCommandDescription(self, file): | 6817 def WriteCommandDescription(self, file): |
6763 """Overridden from Function""" | 6818 """Overridden from Function""" |
6764 file.Write("//! Immediate version of command that corresponds to gl%s.\n" % | 6819 file.Write("//! Immediate version of command that corresponds to gl%s.\n" % |
6765 self.original_name) | 6820 self.original_name) |
6766 | 6821 |
6767 def WriteServiceImplementation(self, file): | 6822 def WriteServiceImplementation(self, file): |
6768 """Overridden from Function""" | 6823 """Overridden from Function""" |
6769 self.type_handler.WriteImmediateServiceImplementation(self, file) | 6824 self.type_handler.WriteImmediateServiceImplementation(self, file) |
6770 | 6825 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6806 | 6861 |
6807 def WriteFormatTest(self, file): | 6862 def WriteFormatTest(self, file): |
6808 """Overridden from Function""" | 6863 """Overridden from Function""" |
6809 self.type_handler.WriteImmediateFormatTest(self, file) | 6864 self.type_handler.WriteImmediateFormatTest(self, file) |
6810 | 6865 |
6811 | 6866 |
6812 class BucketFunction(Function): | 6867 class BucketFunction(Function): |
6813 """A class that represnets a bucket version of a function command.""" | 6868 """A class that represnets a bucket version of a function command.""" |
6814 | 6869 |
6815 def __init__(self, func): | 6870 def __init__(self, func): |
6816 new_args = [] | 6871 Function.__init__( |
6817 for arg in func.GetOriginalArgs(): | 6872 self, |
| 6873 "%sBucket" % func.name, |
| 6874 func.info) |
| 6875 |
| 6876 def InitFunction(self): |
| 6877 # Override args in original_args and args_for_cmds with bucket versions |
| 6878 # of the args. |
| 6879 |
| 6880 new_original_args = [] |
| 6881 for arg in self.original_args: |
6818 new_arg = arg.GetBucketVersion() | 6882 new_arg = arg.GetBucketVersion() |
6819 if new_arg: | 6883 if new_arg: |
6820 new_args.append(new_arg) | 6884 new_original_args.append(new_arg) |
| 6885 self.original_args = new_original_args |
6821 | 6886 |
6822 cmd_args = [] | |
6823 new_args_for_cmds = [] | 6887 new_args_for_cmds = [] |
6824 for arg in func.args_for_cmds: | 6888 for arg in self.args_for_cmds: |
6825 new_arg = arg.GetBucketVersion() | 6889 new_arg = arg.GetBucketVersion() |
6826 if new_arg: | 6890 if new_arg: |
6827 new_args_for_cmds.append(new_arg) | 6891 new_args_for_cmds.append(new_arg) |
6828 new_arg.AddCmdArgs(cmd_args) | |
6829 | 6892 |
6830 new_init_args = [] | 6893 self.args_for_cmds = new_args_for_cmds |
6831 for arg in new_args_for_cmds: | |
6832 arg.AddInitArgs(new_init_args) | |
6833 | 6894 |
6834 Function.__init__( | 6895 Function.InitFunction(self) |
6835 self, | |
6836 func.original_name, | |
6837 "%sBucket" % func.name, | |
6838 func.info, | |
6839 func.return_type, | |
6840 new_args, | |
6841 new_args_for_cmds, | |
6842 cmd_args, | |
6843 new_init_args, | |
6844 0) | |
6845 | |
6846 # def InitFunction(self): | |
6847 # """Overridden from Function""" | |
6848 # pass | |
6849 | 6896 |
6850 def WriteCommandDescription(self, file): | 6897 def WriteCommandDescription(self, file): |
6851 """Overridden from Function""" | 6898 """Overridden from Function""" |
6852 file.Write("//! Bucket version of command that corresponds to gl%s.\n" % | 6899 file.Write("//! Bucket version of command that corresponds to gl%s.\n" % |
6853 self.original_name) | 6900 self.original_name) |
6854 | 6901 |
6855 def WriteServiceImplementation(self, file): | 6902 def WriteServiceImplementation(self, file): |
6856 """Overridden from Function""" | 6903 """Overridden from Function""" |
6857 self.type_handler.WriteBucketServiceImplementation(self, file) | 6904 self.type_handler.WriteBucketServiceImplementation(self, file) |
6858 | 6905 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6912 class GLGenerator(object): | 6959 class GLGenerator(object): |
6913 """A class to generate GL command buffers.""" | 6960 """A class to generate GL command buffers.""" |
6914 | 6961 |
6915 _function_re = re.compile(r'GL_APICALL(.*?)GL_APIENTRY (.*?) \((.*?)\);') | 6962 _function_re = re.compile(r'GL_APICALL(.*?)GL_APIENTRY (.*?) \((.*?)\);') |
6916 | 6963 |
6917 def __init__(self, verbose): | 6964 def __init__(self, verbose): |
6918 self.original_functions = [] | 6965 self.original_functions = [] |
6919 self.functions = [] | 6966 self.functions = [] |
6920 self.verbose = verbose | 6967 self.verbose = verbose |
6921 self.errors = 0 | 6968 self.errors = 0 |
6922 self._function_info = {} | |
6923 self._empty_type_handler = TypeHandler() | |
6924 self._empty_function_info = FunctionInfo({}, self._empty_type_handler) | |
6925 self.pepper_interfaces = [] | 6969 self.pepper_interfaces = [] |
6926 self.interface_info = {} | 6970 self.interface_info = {} |
6927 | 6971 |
6928 self._type_handlers = { | |
6929 'Bind': BindHandler(), | |
6930 'Create': CreateHandler(), | |
6931 'Custom': CustomHandler(), | |
6932 'Data': DataHandler(), | |
6933 'Delete': DeleteHandler(), | |
6934 'DELn': DELnHandler(), | |
6935 'GENn': GENnHandler(), | |
6936 'GETn': GETnHandler(), | |
6937 'GLchar': GLcharHandler(), | |
6938 'GLcharN': GLcharNHandler(), | |
6939 'HandWritten': HandWrittenHandler(), | |
6940 'Is': IsHandler(), | |
6941 'Manual': ManualHandler(), | |
6942 'PUT': PUTHandler(), | |
6943 'PUTn': PUTnHandler(), | |
6944 'PUTXn': PUTXnHandler(), | |
6945 'StateSet': StateSetHandler(), | |
6946 'StateSetRGBAlpha': StateSetRGBAlphaHandler(), | |
6947 'StateSetFrontBack': StateSetFrontBackHandler(), | |
6948 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(), | |
6949 'StateSetNamedParameter': StateSetNamedParameter(), | |
6950 'STRn': STRnHandler(), | |
6951 'Todo': TodoHandler(), | |
6952 } | |
6953 | |
6954 for func_name in _FUNCTION_INFO: | |
6955 info = _FUNCTION_INFO[func_name] | |
6956 type = '' | |
6957 if 'type' in info: | |
6958 type = info['type'] | |
6959 self._function_info[func_name] = FunctionInfo(info, | |
6960 self.GetTypeHandler(type)) | |
6961 for interface in _PEPPER_INTERFACES: | 6972 for interface in _PEPPER_INTERFACES: |
6962 interface = PepperInterface(interface) | 6973 interface = PepperInterface(interface) |
6963 self.pepper_interfaces.append(interface) | 6974 self.pepper_interfaces.append(interface) |
6964 self.interface_info[interface.GetName()] = interface | 6975 self.interface_info[interface.GetName()] = interface |
6965 | 6976 |
6966 def AddFunction(self, func): | 6977 def AddFunction(self, func): |
6967 """Adds a function.""" | 6978 """Adds a function.""" |
6968 self.functions.append(func) | 6979 self.functions.append(func) |
6969 | 6980 |
6970 def GetTypeHandler(self, name): | |
6971 """Gets a type info for the given type.""" | |
6972 if len(name): | |
6973 if name in self._type_handlers: | |
6974 return self._type_handlers[name] | |
6975 else: | |
6976 raise KeyError("no such type handler: %s" % name) | |
6977 return self._empty_type_handler | |
6978 | |
6979 def GetFunctionInfo(self, name): | 6981 def GetFunctionInfo(self, name): |
6980 """Gets a type info for the given function name.""" | 6982 """Gets a type info for the given function name.""" |
6981 if name in self._function_info: | 6983 if name in _FUNCTION_INFO: |
6982 return self._function_info[name] | 6984 func_info = _FUNCTION_INFO[name].copy() |
6983 return self._empty_function_info | 6985 else: |
| 6986 func_info = {} |
| 6987 |
| 6988 if not 'type' in func_info: |
| 6989 func_info['type'] = '' |
| 6990 |
| 6991 return func_info |
6984 | 6992 |
6985 def Log(self, msg): | 6993 def Log(self, msg): |
6986 """Prints something if verbose is true.""" | 6994 """Prints something if verbose is true.""" |
6987 if self.verbose: | 6995 if self.verbose: |
6988 print msg | 6996 print msg |
6989 | 6997 |
6990 def Error(self, msg): | 6998 def Error(self, msg): |
6991 """Prints an error.""" | 6999 """Prints an error.""" |
6992 print "Error: %s" % msg | 7000 print "Error: %s" % msg |
6993 self.errors += 1 | 7001 self.errors += 1 |
6994 | 7002 |
6995 def WriteLicense(self, file): | 7003 def WriteLicense(self, file): |
6996 """Writes the license.""" | 7004 """Writes the license.""" |
6997 file.Write(_LICENSE) | 7005 file.Write(_LICENSE) |
6998 | 7006 |
6999 def WriteNamespaceOpen(self, file): | 7007 def WriteNamespaceOpen(self, file): |
7000 """Writes the code for the namespace.""" | 7008 """Writes the code for the namespace.""" |
7001 file.Write("namespace gpu {\n") | 7009 file.Write("namespace gpu {\n") |
7002 file.Write("namespace gles2 {\n") | 7010 file.Write("namespace gles2 {\n") |
7003 file.Write("\n") | 7011 file.Write("\n") |
7004 | 7012 |
7005 def WriteNamespaceClose(self, file): | 7013 def WriteNamespaceClose(self, file): |
7006 """Writes the code to close the namespace.""" | 7014 """Writes the code to close the namespace.""" |
7007 file.Write("} // namespace gles2\n") | 7015 file.Write("} // namespace gles2\n") |
7008 file.Write("} // namespace gpu\n") | 7016 file.Write("} // namespace gpu\n") |
7009 file.Write("\n") | 7017 file.Write("\n") |
7010 | 7018 |
7011 def ParseArgs(self, arg_string): | |
7012 """Parses a function arg string.""" | |
7013 args = [] | |
7014 num_pointer_args = 0 | |
7015 parts = arg_string.split(',') | |
7016 is_gl_enum = False | |
7017 for arg_string in parts: | |
7018 if arg_string.startswith('GLenum '): | |
7019 is_gl_enum = True | |
7020 arg = CreateArg(arg_string) | |
7021 if arg: | |
7022 args.append(arg) | |
7023 if arg.IsPointer(): | |
7024 num_pointer_args += 1 | |
7025 return (args, num_pointer_args, is_gl_enum) | |
7026 | |
7027 def ParseGLH(self, filename): | 7019 def ParseGLH(self, filename): |
7028 """Parses the cmd_buffer_functions.txt file and extracts the functions""" | 7020 """Parses the cmd_buffer_functions.txt file and extracts the functions""" |
7029 f = open(filename, "r") | 7021 f = open(filename, "r") |
7030 functions = f.read() | 7022 functions = f.read() |
7031 f.close() | 7023 f.close() |
7032 for line in functions.splitlines(): | 7024 for line in functions.splitlines(): |
7033 match = self._function_re.match(line) | 7025 match = self._function_re.match(line) |
7034 if match: | 7026 if match: |
7035 func_name = match.group(2)[2:] | 7027 func_name = match.group(2)[2:] |
7036 func_info = self.GetFunctionInfo(func_name) | 7028 func_info = self.GetFunctionInfo(func_name) |
7037 if func_info.type != 'Noop': | 7029 if func_info['type'] == 'Noop': |
7038 return_type = match.group(1).strip() | 7030 continue |
7039 arg_string = match.group(3) | 7031 |
7040 (args, num_pointer_args, is_gl_enum) = self.ParseArgs(arg_string) | 7032 parsed_func_info = { |
7041 # comment in to find out which functions use bare enums. | 7033 'original_name': func_name, |
7042 # if is_gl_enum: | 7034 'original_args': match.group(3), |
7043 # self.Log("%s uses bare GLenum" % func_name) | 7035 'return_type': match.group(1).strip(), |
7044 args_for_cmds = args | 7036 } |
7045 if hasattr(func_info, 'cmd_args'): | 7037 |
7046 (args_for_cmds, num_pointer_args, is_gl_enum) = ( | 7038 for k in parsed_func_info.keys(): |
7047 self.ParseArgs(getattr(func_info, 'cmd_args'))) | 7039 if not k in func_info: |
7048 cmd_args = [] | 7040 func_info[k] = parsed_func_info[k] |
7049 for arg in args_for_cmds: | 7041 |
7050 arg.AddCmdArgs(cmd_args) | 7042 f = Function(func_name, func_info) |
7051 init_args = [] | 7043 self.original_functions.append(f) |
7052 for arg in args_for_cmds: | 7044 |
7053 arg.AddInitArgs(init_args) | 7045 #for arg in f.GetOriginalArgs(): |
7054 return_arg = CreateArg(return_type + " result") | 7046 # if not isinstance(arg, EnumArgument) and arg.type == 'GLenum': |
7055 if return_arg: | 7047 # self.Log("%s uses bare GLenum %s." % (func_name, arg.name)) |
7056 init_args.append(return_arg) | 7048 |
7057 f = Function(func_name, func_name, func_info, return_type, args, | 7049 gen_cmd = f.GetInfo('gen_cmd') |
7058 args_for_cmds, cmd_args, init_args, num_pointer_args) | 7050 if gen_cmd == True or gen_cmd == None: |
7059 self.original_functions.append(f) | 7051 self.AddFunction(f) |
7060 gen_cmd = f.GetInfo('gen_cmd') | 7052 f.type_handler.AddImmediateFunction(self, f) |
7061 if gen_cmd == True or gen_cmd == None: | 7053 f.type_handler.AddBucketFunction(self, f) |
7062 self.AddFunction(f) | |
7063 f.type_handler.AddImmediateFunction(self, f) | |
7064 f.type_handler.AddBucketFunction(self, f) | |
7065 | 7054 |
7066 self.Log("Auto Generated Functions : %d" % | 7055 self.Log("Auto Generated Functions : %d" % |
7067 len([f for f in self.functions if f.can_auto_generate or | 7056 len([f for f in self.functions if f.can_auto_generate or |
7068 (not f.IsType('') and not f.IsType('Custom') and | 7057 (not f.IsType('') and not f.IsType('Custom') and |
7069 not f.IsType('Todo'))])) | 7058 not f.IsType('Todo'))])) |
7070 | 7059 |
7071 funcs = [f for f in self.functions if not f.can_auto_generate and | 7060 funcs = [f for f in self.functions if not f.can_auto_generate and |
7072 (f.IsType('') or f.IsType('Custom') or f.IsType('Todo'))] | 7061 (f.IsType('') or f.IsType('Custom') or f.IsType('Todo'))] |
7073 self.Log("Non Auto Generated Functions: %d" % len(funcs)) | 7062 self.Log("Non Auto Generated Functions: %d" % len(funcs)) |
7074 | 7063 |
7075 for f in funcs: | 7064 for f in funcs: |
7076 self.Log(" %-10s %-20s gl%s" % (f.info.type, f.return_type, f.name)) | 7065 self.Log(" %-10s %-20s gl%s" % (f.info['type'], f.return_type, f.name)) |
7077 | 7066 |
7078 def WriteCommandIds(self, filename): | 7067 def WriteCommandIds(self, filename): |
7079 """Writes the command buffer format""" | 7068 """Writes the command buffer format""" |
7080 file = CHeaderWriter(filename) | 7069 file = CHeaderWriter(filename) |
7081 file.Write("#define GLES2_COMMAND_LIST(OP) \\\n") | 7070 file.Write("#define GLES2_COMMAND_LIST(OP) \\\n") |
7082 id = 256 | 7071 id = 256 |
7083 for func in self.functions: | 7072 for func in self.functions: |
7084 file.Write(" %-60s /* %d */ \\\n" % | 7073 file.Write(" %-60s /* %d */ \\\n" % |
7085 ("OP(%s)" % func.name, id)) | 7074 ("OP(%s)" % func.name, id)) |
7086 id += 1 | 7075 id += 1 |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8081 "ppapi/shared_impl/ppb_opengles2_shared.cc"]) | 8070 "ppapi/shared_impl/ppb_opengles2_shared.cc"]) |
8082 | 8071 |
8083 if gen.errors > 0: | 8072 if gen.errors > 0: |
8084 print "%d errors" % gen.errors | 8073 print "%d errors" % gen.errors |
8085 return 1 | 8074 return 1 |
8086 return 0 | 8075 return 0 |
8087 | 8076 |
8088 | 8077 |
8089 if __name__ == '__main__': | 8078 if __name__ == '__main__': |
8090 sys.exit(main(sys.argv[1:])) | 8079 sys.exit(main(sys.argv[1:])) |
OLD | NEW |