| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """code generator for GLES2 command buffers.""" | 7 """code generator for GLES2 command buffers.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2118 func.MakeTypedOriginalArgString(""))) | 2118 func.MakeTypedOriginalArgString(""))) |
| 2119 for arg in func.GetOriginalArgs(): | 2119 for arg in func.GetOriginalArgs(): |
| 2120 arg.WriteClientSideValidationCode(file, func) | 2120 arg.WriteClientSideValidationCode(file, func) |
| 2121 file.Write(" helper_->%s(%s);\n" % | 2121 file.Write(" helper_->%s(%s);\n" % |
| 2122 (func.name, func.MakeOriginalArgString(""))) | 2122 (func.name, func.MakeOriginalArgString(""))) |
| 2123 file.Write("}\n") | 2123 file.Write("}\n") |
| 2124 file.Write("\n") | 2124 file.Write("\n") |
| 2125 else: | 2125 else: |
| 2126 self.WriteGLES2ImplementationDeclaration(func, file) | 2126 self.WriteGLES2ImplementationDeclaration(func, file) |
| 2127 | 2127 |
| 2128 def WriteDestinationInitalizationValidation(self, func, file): |
| 2129 """Writes the client side destintion initialization validation.""" |
| 2130 for arg in func.GetOriginalArgs(): |
| 2131 arg.WriteDestinationInitalizationValidation(file, func) |
| 2132 |
| 2128 def WriteImmediateCmdComputeSize(self, func, file): | 2133 def WriteImmediateCmdComputeSize(self, func, file): |
| 2129 """Writes the size computation code for the immediate version of a cmd.""" | 2134 """Writes the size computation code for the immediate version of a cmd.""" |
| 2130 file.Write(" static uint32 ComputeSize(uint32 size_in_bytes) {\n") | 2135 file.Write(" static uint32 ComputeSize(uint32 size_in_bytes) {\n") |
| 2131 file.Write(" return static_cast<uint32>(\n") | 2136 file.Write(" return static_cast<uint32>(\n") |
| 2132 file.Write(" sizeof(ValueType) + // NOLINT\n") | 2137 file.Write(" sizeof(ValueType) + // NOLINT\n") |
| 2133 file.Write(" RoundSizeToMultipleOfEntries(size_in_bytes));\n") | 2138 file.Write(" RoundSizeToMultipleOfEntries(size_in_bytes));\n") |
| 2134 file.Write(" }\n") | 2139 file.Write(" }\n") |
| 2135 file.Write("\n") | 2140 file.Write("\n") |
| 2136 | 2141 |
| 2137 def WriteImmediateCmdSetHeader(self, func, file): | 2142 def WriteImmediateCmdSetHeader(self, func, file): |
| (...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3973 | 3978 |
| 3974 cmd_type_map_ = { | 3979 cmd_type_map_ = { |
| 3975 'GLenum': 'uint32', | 3980 'GLenum': 'uint32', |
| 3976 'GLint': 'int32', | 3981 'GLint': 'int32', |
| 3977 'GLintptr': 'int32', | 3982 'GLintptr': 'int32', |
| 3978 'GLsizei': 'int32', | 3983 'GLsizei': 'int32', |
| 3979 'GLsizeiptr': 'int32', | 3984 'GLsizeiptr': 'int32', |
| 3980 'GLfloat': 'float', | 3985 'GLfloat': 'float', |
| 3981 'GLclampf': 'float', | 3986 'GLclampf': 'float', |
| 3982 } | 3987 } |
| 3988 need_validation_ = ['GLsizei*', 'GLboolean*', 'GLenum*', 'GLint*'] |
| 3983 | 3989 |
| 3984 def __init__(self, name, type): | 3990 def __init__(self, name, type): |
| 3985 self.name = name | 3991 self.name = name |
| 3986 self.type = type | 3992 self.type = type |
| 3987 | 3993 |
| 3988 if type in self.cmd_type_map_: | 3994 if type in self.cmd_type_map_: |
| 3989 self.cmd_type = self.cmd_type_map_[type] | 3995 self.cmd_type = self.cmd_type_map_[type] |
| 3990 else: | 3996 else: |
| 3991 self.cmd_type = 'uint32' | 3997 self.cmd_type = 'uint32' |
| 3992 | 3998 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4022 (self.type, self.name, self.type, self.name)) | 4028 (self.type, self.name, self.type, self.name)) |
| 4023 | 4029 |
| 4024 def WriteValidationCode(self, file, func): | 4030 def WriteValidationCode(self, file, func): |
| 4025 """Writes the validation code for an argument.""" | 4031 """Writes the validation code for an argument.""" |
| 4026 pass | 4032 pass |
| 4027 | 4033 |
| 4028 def WriteClientSideValidationCode(self, file, func): | 4034 def WriteClientSideValidationCode(self, file, func): |
| 4029 """Writes the validation code for an argument.""" | 4035 """Writes the validation code for an argument.""" |
| 4030 pass | 4036 pass |
| 4031 | 4037 |
| 4038 def WriteDestinationInitalizationValidation(self, file, func): |
| 4039 """Writes the client side destintion initialization validation.""" |
| 4040 pass |
| 4041 |
| 4042 def WriteDestinationInitalizationValidatationIfNeeded(self, file, func): |
| 4043 """Writes the client side destintion initialization validation if needed.""" |
| 4044 parts = self.type.split(" ") |
| 4045 if len(parts) > 1: |
| 4046 return |
| 4047 if parts[0] in self.need_validation_: |
| 4048 file.Write(" GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(%s, %s);\n" % |
| 4049 (self.type[:-1], self.name)) |
| 4050 |
| 4051 |
| 4032 def WriteGetAddress(self, file): | 4052 def WriteGetAddress(self, file): |
| 4033 """Writes the code to get the address this argument refers to.""" | 4053 """Writes the code to get the address this argument refers to.""" |
| 4034 pass | 4054 pass |
| 4035 | 4055 |
| 4036 def GetImmediateVersion(self): | 4056 def GetImmediateVersion(self): |
| 4037 """Gets the immediate version of this argument.""" | 4057 """Gets the immediate version of this argument.""" |
| 4038 return self | 4058 return self |
| 4039 | 4059 |
| 4040 def GetBucketVersion(self): | 4060 def GetBucketVersion(self): |
| 4041 """Gets the bucket version of this argument.""" | 4061 """Gets the bucket version of this argument.""" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4206 def WriteValidationCode(self, file, func): | 4226 def WriteValidationCode(self, file, func): |
| 4207 """Overridden from Argument.""" | 4227 """Overridden from Argument.""" |
| 4208 file.Write(" if (%s == NULL) {\n" % self.name) | 4228 file.Write(" if (%s == NULL) {\n" % self.name) |
| 4209 file.Write(" return error::kOutOfBounds;\n") | 4229 file.Write(" return error::kOutOfBounds;\n") |
| 4210 file.Write(" }\n") | 4230 file.Write(" }\n") |
| 4211 | 4231 |
| 4212 def GetImmediateVersion(self): | 4232 def GetImmediateVersion(self): |
| 4213 """Overridden from Argument.""" | 4233 """Overridden from Argument.""" |
| 4214 return None | 4234 return None |
| 4215 | 4235 |
| 4236 def WriteDestinationInitalizationValidation(self, file, func): |
| 4237 """Overridden from Argument.""" |
| 4238 self.WriteDestinationInitalizationValidatationIfNeeded(file, func) |
| 4239 |
| 4216 | 4240 |
| 4217 class BucketPointerArgument(Argument): | 4241 class BucketPointerArgument(Argument): |
| 4218 """A class that represents an bucket argument to a function.""" | 4242 """A class that represents an bucket argument to a function.""" |
| 4219 | 4243 |
| 4220 def __init__(self, name, type): | 4244 def __init__(self, name, type): |
| 4221 Argument.__init__(self, name, type) | 4245 Argument.__init__(self, name, type) |
| 4222 | 4246 |
| 4223 def AddCmdArgs(self, args): | 4247 def AddCmdArgs(self, args): |
| 4224 """Overridden from Argument.""" | 4248 """Overridden from Argument.""" |
| 4225 pass | 4249 pass |
| 4226 | 4250 |
| 4227 def WriteGetCode(self, file): | 4251 def WriteGetCode(self, file): |
| 4228 """Overridden from Argument.""" | 4252 """Overridden from Argument.""" |
| 4229 file.Write( | 4253 file.Write( |
| 4230 " %s %s = bucket->GetData(0, data_size);\n" % | 4254 " %s %s = bucket->GetData(0, data_size);\n" % |
| 4231 (self.type, self.name)) | 4255 (self.type, self.name)) |
| 4232 | 4256 |
| 4233 def WriteValidationCode(self, file, func): | 4257 def WriteValidationCode(self, file, func): |
| 4234 """Overridden from Argument.""" | 4258 """Overridden from Argument.""" |
| 4235 pass | 4259 pass |
| 4236 | 4260 |
| 4237 def GetImmediateVersion(self): | 4261 def GetImmediateVersion(self): |
| 4238 """Overridden from Argument.""" | 4262 """Overridden from Argument.""" |
| 4239 return None | 4263 return None |
| 4240 | 4264 |
| 4265 def WriteDestinationInitalizationValidation(self, file, func): |
| 4266 """Overridden from Argument.""" |
| 4267 self.WriteDestinationInitalizationValidatationIfNeeded(file, func) |
| 4268 |
| 4241 | 4269 |
| 4242 class PointerArgument(Argument): | 4270 class PointerArgument(Argument): |
| 4243 """A class that represents a pointer argument to a function.""" | 4271 """A class that represents a pointer argument to a function.""" |
| 4244 | 4272 |
| 4245 def __init__(self, name, type): | 4273 def __init__(self, name, type): |
| 4246 Argument.__init__(self, name, type) | 4274 Argument.__init__(self, name, type) |
| 4247 | 4275 |
| 4248 def IsPointer(self): | 4276 def IsPointer(self): |
| 4249 """Returns true if argument is a pointer.""" | 4277 """Returns true if argument is a pointer.""" |
| 4250 return True | 4278 return True |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4301 def GetImmediateVersion(self): | 4329 def GetImmediateVersion(self): |
| 4302 """Overridden from Argument.""" | 4330 """Overridden from Argument.""" |
| 4303 return ImmediatePointerArgument(self.name, self.type) | 4331 return ImmediatePointerArgument(self.name, self.type) |
| 4304 | 4332 |
| 4305 def GetBucketVersion(self): | 4333 def GetBucketVersion(self): |
| 4306 """Overridden from Argument.""" | 4334 """Overridden from Argument.""" |
| 4307 if self.type == "const char*": | 4335 if self.type == "const char*": |
| 4308 return InputStringBucketArgument(self.name, self.type) | 4336 return InputStringBucketArgument(self.name, self.type) |
| 4309 return BucketPointerArgument(self.name, self.type) | 4337 return BucketPointerArgument(self.name, self.type) |
| 4310 | 4338 |
| 4339 def WriteDestinationInitalizationValidation(self, file, func): |
| 4340 """Overridden from Argument.""" |
| 4341 self.WriteDestinationInitalizationValidatationIfNeeded(file, func) |
| 4342 |
| 4311 | 4343 |
| 4312 class InputStringBucketArgument(Argument): | 4344 class InputStringBucketArgument(Argument): |
| 4313 """An string input argument where the string is passed in a bucket.""" | 4345 """An string input argument where the string is passed in a bucket.""" |
| 4314 | 4346 |
| 4315 def __init__(self, name, type): | 4347 def __init__(self, name, type): |
| 4316 Argument.__init__(self, name + "_bucket_id", "uint32") | 4348 Argument.__init__(self, name + "_bucket_id", "uint32") |
| 4317 | 4349 |
| 4318 def WriteGetCode(self, file): | 4350 def WriteGetCode(self, file): |
| 4319 """Overridden from Argument.""" | 4351 """Overridden from Argument.""" |
| 4320 code = """ | 4352 code = """ |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4622 self.type_handler.WriteServiceImplementation(self, file) | 4654 self.type_handler.WriteServiceImplementation(self, file) |
| 4623 | 4655 |
| 4624 def WriteServiceUnitTest(self, file): | 4656 def WriteServiceUnitTest(self, file): |
| 4625 """Writes the service implementation for a command.""" | 4657 """Writes the service implementation for a command.""" |
| 4626 self.type_handler.WriteServiceUnitTest(self, file) | 4658 self.type_handler.WriteServiceUnitTest(self, file) |
| 4627 | 4659 |
| 4628 def WriteGLES2ImplementationHeader(self, file): | 4660 def WriteGLES2ImplementationHeader(self, file): |
| 4629 """Writes the GLES2 Implemention declaration.""" | 4661 """Writes the GLES2 Implemention declaration.""" |
| 4630 self.type_handler.WriteGLES2ImplementationHeader(self, file) | 4662 self.type_handler.WriteGLES2ImplementationHeader(self, file) |
| 4631 | 4663 |
| 4664 def WriteDestinationInitalizationValidation(self, file): |
| 4665 """Writes the client side destintion initialization validation.""" |
| 4666 self.type_handler.WriteDestinationInitalizationValidation(self, file) |
| 4667 |
| 4632 def WriteFormatTest(self, file): | 4668 def WriteFormatTest(self, file): |
| 4633 """Writes the cmd's format test.""" | 4669 """Writes the cmd's format test.""" |
| 4634 self.type_handler.WriteFormatTest(self, file) | 4670 self.type_handler.WriteFormatTest(self, file) |
| 4635 | 4671 |
| 4636 | 4672 |
| 4637 class ImmediateFunction(Function): | 4673 class ImmediateFunction(Function): |
| 4638 """A class that represnets an immediate function command.""" | 4674 """A class that represnets an immediate function command.""" |
| 4639 | 4675 |
| 4640 def __init__(self, func): | 4676 def __init__(self, func): |
| 4641 new_args = [] | 4677 new_args = [] |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5106 def WriteGLES2CLibImplementation(self, filename): | 5142 def WriteGLES2CLibImplementation(self, filename): |
| 5107 """Writes the GLES2 c lib implementation.""" | 5143 """Writes the GLES2 c lib implementation.""" |
| 5108 file = CHeaderWriter( | 5144 file = CHeaderWriter( |
| 5109 filename, | 5145 filename, |
| 5110 "// These functions emluate GLES2 over command buffers.\n") | 5146 "// These functions emluate GLES2 over command buffers.\n") |
| 5111 | 5147 |
| 5112 for func in self.original_functions: | 5148 for func in self.original_functions: |
| 5113 file.Write("%s GLES2%s(%s) {\n" % | 5149 file.Write("%s GLES2%s(%s) {\n" % |
| 5114 (func.return_type, func.name, | 5150 (func.return_type, func.name, |
| 5115 func.MakeTypedOriginalArgString(""))) | 5151 func.MakeTypedOriginalArgString(""))) |
| 5152 func.WriteDestinationInitalizationValidation(file) |
| 5116 comma = "" | 5153 comma = "" |
| 5117 if len(func.GetOriginalArgs()): | 5154 if len(func.GetOriginalArgs()): |
| 5118 comma = " << " | 5155 comma = " << " |
| 5119 file.Write( | 5156 file.Write( |
| 5120 ' GPU_CLIENT_LOG("%s" << "("%s%s << ")");\n' % | 5157 ' GPU_CLIENT_LOG("%s" << "("%s%s << ")");\n' % |
| 5121 (func.original_name, comma, func.MakeOriginalArgString( | 5158 (func.original_name, comma, func.MakeOriginalArgString( |
| 5122 "", separator=' << ", " << '))) | 5159 "", separator=' << ", " << '))) |
| 5123 result_string = "%s result = " % func.return_type | 5160 result_string = "%s result = " % func.return_type |
| 5124 return_string = ( | 5161 return_string = ( |
| 5125 ' GPU_CLIENT_LOG("return:" << result)\n return result;\n') | 5162 ' GPU_CLIENT_LOG("return:" << result)\n return result;\n') |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5319 | 5356 |
| 5320 if options.generate_docs: | 5357 if options.generate_docs: |
| 5321 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") | 5358 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") |
| 5322 | 5359 |
| 5323 if gen.errors > 0: | 5360 if gen.errors > 0: |
| 5324 print "%d errors" % gen.errors | 5361 print "%d errors" % gen.errors |
| 5325 sys.exit(1) | 5362 sys.exit(1) |
| 5326 | 5363 |
| 5327 if __name__ == '__main__': | 5364 if __name__ == '__main__': |
| 5328 main(sys.argv[1:]) | 5365 main(sys.argv[1:]) |
| OLD | NEW |