| 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 3563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3574 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3574 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 3575 } | 3575 } |
| 3576 """ | 3576 """ |
| 3577 gl_arg_strings = [] | 3577 gl_arg_strings = [] |
| 3578 arg_strings = [] | 3578 arg_strings = [] |
| 3579 count = 0 | 3579 count = 0 |
| 3580 for arg in func.GetOriginalArgs(): | 3580 for arg in func.GetOriginalArgs(): |
| 3581 # hardcoded to match unit tests. | 3581 # hardcoded to match unit tests. |
| 3582 if count == 0: | 3582 if count == 0: |
| 3583 # the location of the second element of the first uniform. | 3583 # the location of the second element of the first uniform. |
| 3584 gl_arg_strings.append("3") | 3584 gl_arg_strings.append(arg.GetValidGLArg(func, 2, 2)) |
| 3585 arg_strings.append("3") | 3585 arg_strings.append(arg.GetValidArg(func, 2, 2)) |
| 3586 elif count == 1: | 3586 elif count == 1: |
| 3587 # the number of elements that gl will be called with. | 3587 # the number of elements that gl will be called with. |
| 3588 gl_arg_strings.append("2") | 3588 gl_arg_strings.append("2") |
| 3589 # the number of elements requested in the command. | 3589 # the number of elements requested in the command. |
| 3590 arg_strings.append("5") | 3590 arg_strings.append("5") |
| 3591 else: | 3591 else: |
| 3592 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) | 3592 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) |
| 3593 arg_strings.append(arg.GetValidArg(func, count, 0)) | 3593 arg_strings.append(arg.GetValidArg(func, count, 0)) |
| 3594 count += 1 | 3594 count += 1 |
| 3595 extra = { | 3595 extra = { |
| 3596 'gl_args': ", ".join(gl_arg_strings), | 3596 'gl_args': ", ".join(gl_arg_strings), |
| 3597 'args': ", ".join(arg_strings), | 3597 'args': ", ".join(arg_strings), |
| 3598 } | 3598 } |
| 3599 self.WriteValidUnitTest(func, file, valid_test, extra) | 3599 self.WriteValidUnitTest(func, file, valid_test, extra) |
| 3600 | 3600 |
| 3601 def WriteImmediateServiceUnitTest(self, func, file): | 3601 def WriteImmediateServiceUnitTest(self, func, file): |
| 3602 """Overridden from TypeHandler.""" | 3602 """Overridden from TypeHandler.""" |
| 3603 valid_test = """ | 3603 valid_test = """ |
| 3604 TEST_F(%(test_name)s, %(name)sValidArgs) { | 3604 TEST_F(%(test_name)s, %(name)sValidArgs) { |
| 3605 %(name)s& cmd = *GetImmediateAs<%(name)s>(); | 3605 %(name)s& cmd = *GetImmediateAs<%(name)s>(); |
| 3606 EXPECT_CALL( | 3606 EXPECT_CALL( |
| 3607 *gl_, | 3607 *gl_, |
| 3608 %(gl_func_name)s(%(gl_args)s, | 3608 %(gl_func_name)s(%(gl_args)s, |
| 3609 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd)))); | 3609 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd)))); |
| 3610 SpecializedSetup<%(name)s, 0>(true); | 3610 SpecializedSetup<%(name)s, 0>(true); |
| 3611 %(data_type)s temp[%(data_count)s * 2] = { 0, }; | 3611 %(data_type)s temp[%(data_count)s * 2] = { 0, }; |
| 3612 cmd.Init(%(gl_args)s, &temp[0]); | 3612 cmd.Init(%(args)s, &temp[0]); |
| 3613 EXPECT_EQ(error::kNoError, | 3613 EXPECT_EQ(error::kNoError, |
| 3614 ExecuteImmediateCmd(cmd, sizeof(temp))); | 3614 ExecuteImmediateCmd(cmd, sizeof(temp))); |
| 3615 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3615 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 3616 } | 3616 } |
| 3617 """ | 3617 """ |
| 3618 gl_arg_strings = [] | 3618 gl_arg_strings = [] |
| 3619 gl_any_strings = [] | 3619 gl_any_strings = [] |
| 3620 arg_strings = [] |
| 3620 count = 0 | 3621 count = 0 |
| 3621 for arg in func.GetOriginalArgs()[0:-1]: | 3622 for arg in func.GetOriginalArgs()[0:-1]: |
| 3622 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) | 3623 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) |
| 3623 gl_any_strings.append("_") | 3624 gl_any_strings.append("_") |
| 3625 arg_strings.append(arg.GetValidArg(func, count, 0)) |
| 3624 count += 1 | 3626 count += 1 |
| 3625 extra = { | 3627 extra = { |
| 3626 'data_type': func.GetInfo('data_type'), | 3628 'data_type': func.GetInfo('data_type'), |
| 3627 'data_count': func.GetInfo('count'), | 3629 'data_count': func.GetInfo('count'), |
| 3630 'args': ", ".join(arg_strings), |
| 3628 'gl_args': ", ".join(gl_arg_strings), | 3631 'gl_args': ", ".join(gl_arg_strings), |
| 3629 'gl_any_args': ", ".join(gl_any_strings), | 3632 'gl_any_args': ", ".join(gl_any_strings), |
| 3630 } | 3633 } |
| 3631 self.WriteValidUnitTest(func, file, valid_test, extra) | 3634 self.WriteValidUnitTest(func, file, valid_test, extra) |
| 3632 | 3635 |
| 3633 invalid_test = """ | 3636 invalid_test = """ |
| 3634 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 3637 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
| 3635 %(name)s& cmd = *GetImmediateAs<%(name)s>(); | 3638 %(name)s& cmd = *GetImmediateAs<%(name)s>(); |
| 3636 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0); | 3639 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0); |
| 3637 SpecializedSetup<%(name)s, 0>(false); | 3640 SpecializedSetup<%(name)s, 0>(false); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3859 TEST_F(%(test_name)s, %(name)sValidArgs) { | 3862 TEST_F(%(test_name)s, %(name)sValidArgs) { |
| 3860 EXPECT_CALL(*gl_, Uniform%(count)sfv(%(local_args)s)); | 3863 EXPECT_CALL(*gl_, Uniform%(count)sfv(%(local_args)s)); |
| 3861 SpecializedSetup<%(name)s, 0>(true); | 3864 SpecializedSetup<%(name)s, 0>(true); |
| 3862 %(name)s cmd; | 3865 %(name)s cmd; |
| 3863 cmd.Init(%(args)s); | 3866 cmd.Init(%(args)s); |
| 3864 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 3867 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 3865 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3868 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 3866 } | 3869 } |
| 3867 """ | 3870 """ |
| 3868 args = func.GetOriginalArgs() | 3871 args = func.GetOriginalArgs() |
| 3869 local_args = "%s, 1, _" % args[0].GetValidArg(func, 0, 0) | 3872 local_args = "%s, 1, _" % args[0].GetValidGLArg(func, 0, 0) |
| 3870 self.WriteValidUnitTest(func, file, valid_test, { | 3873 self.WriteValidUnitTest(func, file, valid_test, { |
| 3871 'count': func.GetInfo('count'), | 3874 'count': func.GetInfo('count'), |
| 3872 'local_args': local_args, | 3875 'local_args': local_args, |
| 3873 }) | 3876 }) |
| 3874 | 3877 |
| 3875 invalid_test = """ | 3878 invalid_test = """ |
| 3876 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 3879 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
| 3877 EXPECT_CALL(*gl_, Uniform%(count)s(_, _, _).Times(0); | 3880 EXPECT_CALL(*gl_, Uniform%(count)s(_, _, _).Times(0); |
| 3878 SpecializedSetup<%(name)s, 0>(false); | 3881 SpecializedSetup<%(name)s, 0>(false); |
| 3879 %(name)s cmd; | 3882 %(name)s cmd; |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4416 | 4419 |
| 4417 def GetValidClientSideCmdArg(self, func, offset, index): | 4420 def GetValidClientSideCmdArg(self, func, offset, index): |
| 4418 """Gets a valid value for this argument.""" | 4421 """Gets a valid value for this argument.""" |
| 4419 return 'true' | 4422 return 'true' |
| 4420 | 4423 |
| 4421 def GetValidGLArg(self, func, offset, index): | 4424 def GetValidGLArg(self, func, offset, index): |
| 4422 """Gets a valid GL value for this argument.""" | 4425 """Gets a valid GL value for this argument.""" |
| 4423 return 'true' | 4426 return 'true' |
| 4424 | 4427 |
| 4425 | 4428 |
| 4429 class UniformLocationArgument(Argument): |
| 4430 """class for uniform locations.""" |
| 4431 |
| 4432 def __init__(self, name): |
| 4433 Argument.__init__(self, name, "GLint") |
| 4434 |
| 4435 def WriteGetCode(self, file): |
| 4436 """Writes the code to get an argument from a command structure.""" |
| 4437 code = """ %s %s = program_manager()->UnswizzleLocation( |
| 4438 static_cast<%s>(c.%s)); |
| 4439 """ |
| 4440 file.Write(code % (self.type, self.name, self.type, self.name)) |
| 4441 |
| 4442 def GetValidArg(self, func, offset, index): |
| 4443 """Gets a valid value for this argument.""" |
| 4444 return "program_manager()->SwizzleLocation(%d)" % (offset + 1) |
| 4445 |
| 4446 |
| 4426 class DataSizeArgument(Argument): | 4447 class DataSizeArgument(Argument): |
| 4427 """class for data_size which Bucket commands do not need.""" | 4448 """class for data_size which Bucket commands do not need.""" |
| 4428 | 4449 |
| 4429 def __init__(self, name): | 4450 def __init__(self, name): |
| 4430 Argument.__init__(self, name, "uint32") | 4451 Argument.__init__(self, name, "uint32") |
| 4431 | 4452 |
| 4432 def GetBucketVersion(self): | 4453 def GetBucketVersion(self): |
| 4433 return None | 4454 return None |
| 4434 | 4455 |
| 4435 | 4456 |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5250 elif arg_parts[0].startswith('GLidZero'): | 5271 elif arg_parts[0].startswith('GLidZero'): |
| 5251 return ResourceIdZeroArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5272 return ResourceIdZeroArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| 5252 elif arg_parts[0].startswith('GLid'): | 5273 elif arg_parts[0].startswith('GLid'): |
| 5253 return ResourceIdArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5274 return ResourceIdArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| 5254 elif arg_parts[0].startswith('GLenum') and len(arg_parts[0]) > 6: | 5275 elif arg_parts[0].startswith('GLenum') and len(arg_parts[0]) > 6: |
| 5255 return EnumArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5276 return EnumArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| 5256 elif arg_parts[0].startswith('GLboolean') and len(arg_parts[0]) > 9: | 5277 elif arg_parts[0].startswith('GLboolean') and len(arg_parts[0]) > 9: |
| 5257 return ValidatedBoolArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5278 return ValidatedBoolArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| 5258 elif arg_parts[0].startswith('GLboolean'): | 5279 elif arg_parts[0].startswith('GLboolean'): |
| 5259 return BoolArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5280 return BoolArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| 5281 elif arg_parts[0].startswith('GLintUniformLocation'): |
| 5282 return UniformLocationArgument(arg_parts[-1]) |
| 5260 elif (arg_parts[0].startswith('GLint') and len(arg_parts[0]) > 5 and | 5283 elif (arg_parts[0].startswith('GLint') and len(arg_parts[0]) > 5 and |
| 5261 not arg_parts[0].startswith('GLintptr')): | 5284 not arg_parts[0].startswith('GLintptr')): |
| 5262 return IntArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5285 return IntArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| 5263 elif (arg_parts[0].startswith('GLsizeiNotNegative') or | 5286 elif (arg_parts[0].startswith('GLsizeiNotNegative') or |
| 5264 arg_parts[0].startswith('GLintptrNotNegative')): | 5287 arg_parts[0].startswith('GLintptrNotNegative')): |
| 5265 return SizeNotNegativeArgument(arg_parts[-1], | 5288 return SizeNotNegativeArgument(arg_parts[-1], |
| 5266 " ".join(arg_parts[0:-1]), | 5289 " ".join(arg_parts[0:-1]), |
| 5267 arg_parts[0][0:-11]) | 5290 arg_parts[0][0:-11]) |
| 5268 elif arg_parts[0].startswith('GLsize'): | 5291 elif arg_parts[0].startswith('GLsize'): |
| 5269 return SizeArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) | 5292 return SizeArgument(arg_parts[-1], " ".join(arg_parts[0:-1])) |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5915 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") | 5938 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") |
| 5916 | 5939 |
| 5917 if gen.errors > 0: | 5940 if gen.errors > 0: |
| 5918 print "%d errors" % gen.errors | 5941 print "%d errors" % gen.errors |
| 5919 return 1 | 5942 return 1 |
| 5920 return 0 | 5943 return 0 |
| 5921 | 5944 |
| 5922 | 5945 |
| 5923 if __name__ == '__main__': | 5946 if __name__ == '__main__': |
| 5924 sys.exit(main(sys.argv[1:])) | 5947 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |