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 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2010 'decoder_func': 'DoGetVertexAttribiv', | 2010 'decoder_func': 'DoGetVertexAttribiv', |
2011 'expectation': False, | 2011 'expectation': False, |
2012 'client_test': False, | 2012 'client_test': False, |
2013 }, | 2013 }, |
2014 'GetVertexAttribPointerv': { | 2014 'GetVertexAttribPointerv': { |
2015 'type': 'Custom', | 2015 'type': 'Custom', |
2016 'data_transfer_methods': ['shm'], | 2016 'data_transfer_methods': ['shm'], |
2017 'result': ['SizedResult<GLuint>'], | 2017 'result': ['SizedResult<GLuint>'], |
2018 'client_test': False, | 2018 'client_test': False, |
2019 }, | 2019 }, |
2020 'InvalidateFramebuffer': { | |
2021 'type': 'PUTn', | |
2022 'count': 1, | |
2023 'client_test': False, | |
2024 'unit_test': False, | |
2025 'unsafe': True, | |
2026 }, | |
2027 'InvalidateSubFramebuffer': { | |
2028 'type': 'PUTn', | |
2029 'count': 1, | |
2030 'client_test': False, | |
2031 'unit_test': False, | |
2032 'unsafe': True, | |
2033 }, | |
2020 'IsBuffer': { | 2034 'IsBuffer': { |
2021 'type': 'Is', | 2035 'type': 'Is', |
2022 'decoder_func': 'DoIsBuffer', | 2036 'decoder_func': 'DoIsBuffer', |
2023 'expectation': False, | 2037 'expectation': False, |
2024 }, | 2038 }, |
2025 'IsEnabled': { | 2039 'IsEnabled': { |
2026 'type': 'Is', | 2040 'type': 'Is', |
2027 'decoder_func': 'DoIsEnabled', | 2041 'decoder_func': 'DoIsEnabled', |
2028 'impl_func': False, | 2042 'impl_func': False, |
2029 'expectation': False, | 2043 'expectation': False, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2126 }, | 2140 }, |
2127 'RenderbufferStorageMultisampleEXT': { | 2141 'RenderbufferStorageMultisampleEXT': { |
2128 'cmd_comment': | 2142 'cmd_comment': |
2129 '// GL_EXT_multisampled_render_to_texture\n', | 2143 '// GL_EXT_multisampled_render_to_texture\n', |
2130 'decoder_func': 'DoRenderbufferStorageMultisampleEXT', | 2144 'decoder_func': 'DoRenderbufferStorageMultisampleEXT', |
2131 'gl_test_func': 'glRenderbufferStorageMultisampleEXT', | 2145 'gl_test_func': 'glRenderbufferStorageMultisampleEXT', |
2132 'expectation': False, | 2146 'expectation': False, |
2133 'unit_test': False, | 2147 'unit_test': False, |
2134 'extension_flag': 'multisampled_render_to_texture', | 2148 'extension_flag': 'multisampled_render_to_texture', |
2135 }, | 2149 }, |
2150 'ReadBuffer': { | |
2151 'unsafe': True, | |
2152 }, | |
2136 'ReadPixels': { | 2153 'ReadPixels': { |
2137 'cmd_comment': | 2154 'cmd_comment': |
2138 '// ReadPixels has the result separated from the pixel buffer so that\n' | 2155 '// ReadPixels has the result separated from the pixel buffer so that\n' |
2139 '// it is easier to specify the result going to some specific place\n' | 2156 '// it is easier to specify the result going to some specific place\n' |
2140 '// that exactly fits the rectangle of pixels.\n', | 2157 '// that exactly fits the rectangle of pixels.\n', |
2141 'type': 'Custom', | 2158 'type': 'Custom', |
2142 'data_transfer_methods': ['shm'], | 2159 'data_transfer_methods': ['shm'], |
2143 'impl_func': False, | 2160 'impl_func': False, |
2144 'client_test': False, | 2161 'client_test': False, |
2145 'cmd_args': | 2162 'cmd_args': |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2735 }, | 2752 }, |
2736 'WaitAllAsyncTexImage2DCHROMIUM': { | 2753 'WaitAllAsyncTexImage2DCHROMIUM': { |
2737 'type': 'Manual', | 2754 'type': 'Manual', |
2738 'client_test': False, | 2755 'client_test': False, |
2739 'extension': True, | 2756 'extension': True, |
2740 'chromium': True, | 2757 'chromium': True, |
2741 }, | 2758 }, |
2742 'DiscardFramebufferEXT': { | 2759 'DiscardFramebufferEXT': { |
2743 'type': 'PUTn', | 2760 'type': 'PUTn', |
2744 'count': 1, | 2761 'count': 1, |
2745 'cmd_args': 'GLenum target, GLsizei count, ' | |
2746 'const GLenum* attachments', | |
2747 'decoder_func': 'DoDiscardFramebufferEXT', | 2762 'decoder_func': 'DoDiscardFramebufferEXT', |
2748 'unit_test': False, | 2763 'unit_test': False, |
2749 'client_test': False, | 2764 'client_test': False, |
2750 'extension_flag': 'ext_discard_framebuffer', | 2765 'extension_flag': 'ext_discard_framebuffer', |
2751 }, | 2766 }, |
2752 'LoseContextCHROMIUM': { | 2767 'LoseContextCHROMIUM': { |
2753 'decoder_func': 'DoLoseContextCHROMIUM', | 2768 'decoder_func': 'DoLoseContextCHROMIUM', |
2754 'unit_test': False, | 2769 'unit_test': False, |
2755 'extension': True, | 2770 'extension': True, |
2756 'chromium': True, | 2771 'chromium': True, |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3125 func.WriteHandlerImplementation(file) | 3140 func.WriteHandlerImplementation(file) |
3126 file.Write(" return error::kNoError;\n") | 3141 file.Write(" return error::kNoError;\n") |
3127 file.Write("}\n") | 3142 file.Write("}\n") |
3128 file.Write("\n") | 3143 file.Write("\n") |
3129 | 3144 |
3130 def WriteImmediateServiceImplementation(self, func, file): | 3145 def WriteImmediateServiceImplementation(self, func, file): |
3131 """Writes the service implementation for an immediate version of command.""" | 3146 """Writes the service implementation for an immediate version of command.""" |
3132 self.WriteServiceHandlerFunctionHeader(func, file) | 3147 self.WriteServiceHandlerFunctionHeader(func, file) |
3133 self.WriteHandlerExtensionCheck(func, file) | 3148 self.WriteHandlerExtensionCheck(func, file) |
3134 self.WriteHandlerDeferReadWrite(func, file); | 3149 self.WriteHandlerDeferReadWrite(func, file); |
3135 last_arg = func.GetLastOriginalArg() | 3150 for arg in func.GetOriginalArgs(): |
3136 all_but_last_arg = func.GetOriginalArgs()[:-1] | 3151 if arg.IsPointer(): |
3137 for arg in all_but_last_arg: | 3152 self.WriteGetDataSizeCode(func, file) |
3138 arg.WriteGetCode(file) | 3153 arg.WriteGetCode(file) |
3139 self.WriteGetDataSizeCode(func, file) | |
3140 last_arg.WriteGetCode(file) | |
3141 func.WriteHandlerValidation(file) | 3154 func.WriteHandlerValidation(file) |
3142 func.WriteHandlerImplementation(file) | 3155 func.WriteHandlerImplementation(file) |
3143 file.Write(" return error::kNoError;\n") | 3156 file.Write(" return error::kNoError;\n") |
3144 file.Write("}\n") | 3157 file.Write("}\n") |
3145 file.Write("\n") | 3158 file.Write("\n") |
3146 | 3159 |
3147 def WriteBucketServiceImplementation(self, func, file): | 3160 def WriteBucketServiceImplementation(self, func, file): |
3148 """Writes the service implementation for a bucket version of command.""" | 3161 """Writes the service implementation for a bucket version of command.""" |
3149 self.WriteServiceHandlerFunctionHeader(func, file) | 3162 self.WriteServiceHandlerFunctionHeader(func, file) |
3150 self.WriteHandlerExtensionCheck(func, file) | 3163 self.WriteHandlerExtensionCheck(func, file) |
3151 self.WriteHandlerDeferReadWrite(func, file); | 3164 self.WriteHandlerDeferReadWrite(func, file); |
3152 last_arg = func.GetLastOriginalArg() | 3165 for arg in func.GetOriginalArgs(): |
3153 all_but_last_arg = func.GetOriginalArgs()[:-1] | 3166 if arg.IsPointer(): |
3154 for arg in all_but_last_arg: | 3167 self.WriteGetDataSizeCode(func, file) |
3155 arg.WriteGetCode(file) | 3168 arg.WriteGetCode(file) |
3156 self.WriteGetDataSizeCode(func, file) | |
3157 last_arg.WriteGetCode(file) | |
3158 func.WriteHandlerValidation(file) | 3169 func.WriteHandlerValidation(file) |
3159 func.WriteHandlerImplementation(file) | 3170 func.WriteHandlerImplementation(file) |
3160 file.Write(" return error::kNoError;\n") | 3171 file.Write(" return error::kNoError;\n") |
3161 file.Write("}\n") | 3172 file.Write("}\n") |
3162 file.Write("\n") | 3173 file.Write("\n") |
3163 | 3174 |
3164 def WriteHandlerExtensionCheck(self, func, file): | 3175 def WriteHandlerExtensionCheck(self, func, file): |
3165 if func.GetInfo('extension_flag'): | 3176 if func.GetInfo('extension_flag'): |
3166 file.Write(" if (!features().%s) {\n" % func.GetInfo('extension_flag')) | 3177 file.Write(" if (!features().%s) {\n" % func.GetInfo('extension_flag')) |
3167 file.Write(" LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, \"gl%s\"," | 3178 file.Write(" LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, \"gl%s\"," |
(...skipping 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5519 file.Write(" }\n") | 5530 file.Write(" }\n") |
5520 | 5531 |
5521 def WriteGLES2Implementation(self, func, file): | 5532 def WriteGLES2Implementation(self, func, file): |
5522 """Overrriden from TypeHandler.""" | 5533 """Overrriden from TypeHandler.""" |
5523 file.Write("%s GLES2Implementation::%s(%s) {\n" % | 5534 file.Write("%s GLES2Implementation::%s(%s) {\n" % |
5524 (func.return_type, func.original_name, | 5535 (func.return_type, func.original_name, |
5525 func.MakeTypedOriginalArgString(""))) | 5536 func.MakeTypedOriginalArgString(""))) |
5526 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") | 5537 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") |
5527 func.WriteDestinationInitalizationValidation(file) | 5538 func.WriteDestinationInitalizationValidation(file) |
5528 self.WriteClientGLCallLog(func, file) | 5539 self.WriteClientGLCallLog(func, file) |
5529 last_arg_name = func.GetLastOriginalArg().name | 5540 last_pointer_name = func.GetLastOriginalPointerArg().name |
5530 file.Write(""" GPU_CLIENT_LOG_CODE_BLOCK({ | 5541 file.Write(""" GPU_CLIENT_LOG_CODE_BLOCK({ |
5531 for (GLsizei i = 0; i < count; ++i) { | 5542 for (GLsizei i = 0; i < count; ++i) { |
5532 """) | 5543 """) |
5533 values_str = ' << ", " << '.join( | 5544 values_str = ' << ", " << '.join( |
5534 ["%s[%d + i * %d]" % ( | 5545 ["%s[%d + i * %d]" % ( |
5535 last_arg_name, ndx, self.GetArrayCount(func)) for ndx in range( | 5546 last_pointer_name, ndx, self.GetArrayCount(func)) for ndx in range( |
5536 0, self.GetArrayCount(func))]) | 5547 0, self.GetArrayCount(func))]) |
5537 file.Write(' GPU_CLIENT_LOG(" " << i << ": " << %s);\n' % values_str) | 5548 file.Write(' GPU_CLIENT_LOG(" " << i << ": " << %s);\n' % values_str) |
5538 file.Write(" }\n });\n") | 5549 file.Write(" }\n });\n") |
5539 for arg in func.GetOriginalArgs(): | 5550 for arg in func.GetOriginalArgs(): |
5540 arg.WriteClientSideValidationCode(file, func) | 5551 arg.WriteClientSideValidationCode(file, func) |
5541 file.Write(" helper_->%sImmediate(%s);\n" % | 5552 file.Write(" helper_->%sImmediate(%s);\n" % |
5542 (func.name, func.MakeInitString(""))) | 5553 (func.name, func.MakeInitString(""))) |
5543 file.Write(" CheckGLError();\n") | 5554 file.Write(" CheckGLError();\n") |
5544 file.Write("}\n") | 5555 file.Write("}\n") |
5545 file.Write("\n") | 5556 file.Write("\n") |
5546 | 5557 |
5547 def WriteGLES2ImplementationUnitTest(self, func, file): | 5558 def WriteGLES2ImplementationUnitTest(self, func, file): |
5548 """Writes the GLES2 Implemention unit test.""" | 5559 """Writes the GLES2 Implemention unit test.""" |
5549 code = """ | 5560 code = """ |
5550 TEST_F(GLES2ImplementationTest, %(name)s) { | 5561 TEST_F(GLES2ImplementationTest, %(name)s) { |
5551 %(type)s data[%(count_param)d][%(count)d] = {{0}}; | 5562 %(type)s data[%(count_param)d][%(count)d] = {{0}}; |
5552 struct Cmds { | 5563 struct Cmds { |
5553 cmds::%(name)sImmediate cmd; | 5564 cmds::%(name)sImmediate cmd; |
5554 %(type)s data[%(count_param)d][%(count)d]; | 5565 %(type)s data[%(count_param)d][%(count)d]; |
5555 }; | 5566 }; |
5556 | 5567 |
5557 Cmds expected; | 5568 Cmds expected; |
5558 for (int ii = 0; ii < %(count_param)d; ++ii) { | 5569 for (int ii = 0; ii < %(count_param)d; ++ii) { |
5559 for (int jj = 0; jj < %(count)d; ++jj) { | 5570 for (int jj = 0; jj < %(count)d; ++jj) { |
5560 data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj); | 5571 data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj); |
5561 } | 5572 } |
5562 } | 5573 } |
5563 expected.cmd.Init(%(cmd_args)s, &data[0][0]); | 5574 expected.cmd.Init(%(cmd_args)s); |
5564 gl_->%(name)s(%(args)s, &data[0][0]); | 5575 gl_->%(name)s(%(args)s); |
5565 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | 5576 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
5566 } | 5577 } |
5567 """ | 5578 """ |
5568 cmd_arg_strings = [ | 5579 cmd_arg_strings = [] |
5569 arg.GetValidClientSideCmdArg(func) for arg in func.GetCmdArgs()[0:-2] | 5580 for arg in func.GetCmdArgs(): |
5570 ] | 5581 if arg.name.endswith("_shm_id"): |
5582 cmd_arg_strings.append("&data[0][0]") | |
5583 elif arg.name.endswith("_shm_offset"): | |
5584 continue | |
5585 else: | |
5586 cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func)) | |
5571 gl_arg_strings = [] | 5587 gl_arg_strings = [] |
5572 count_param = 0 | 5588 count_param = 0 |
5573 for arg in func.GetOriginalArgs()[0:-1]: | 5589 for arg in func.GetOriginalArgs(): |
5574 valid_value = arg.GetValidClientSideArg(func) | 5590 if arg.IsPointer(): |
5591 valid_value = "&data[0][0]" | |
5592 else: | |
5593 valid_value = arg.GetValidClientSideArg(func) | |
5575 gl_arg_strings.append(valid_value) | 5594 gl_arg_strings.append(valid_value) |
5576 if arg.name == "count": | 5595 if arg.name == "count": |
5577 count_param = int(valid_value) | 5596 count_param = int(valid_value) |
5578 file.Write(code % { | 5597 file.Write(code % { |
5579 'name': func.name, | 5598 'name': func.name, |
5580 'type': self.GetArrayType(func), | 5599 'type': self.GetArrayType(func), |
5581 'count': self.GetArrayCount(func), | 5600 'count': self.GetArrayCount(func), |
5582 'args': ", ".join(gl_arg_strings), | 5601 'args': ", ".join(gl_arg_strings), |
5583 'cmd_args': ", ".join(cmd_arg_strings), | 5602 'cmd_args': ", ".join(cmd_arg_strings), |
5584 'count_param': count_param, | 5603 'count_param': count_param, |
5585 }) | 5604 }) |
5586 | 5605 |
5587 # Test constants for invalid values, as they are not tested by the | 5606 # Test constants for invalid values, as they are not tested by the |
5588 # service. | 5607 # service. |
5589 constants = [ | 5608 constants = [ |
5590 arg for arg in func.GetOriginalArgs()[0:-1] if arg.IsConstant() | 5609 arg for arg in func.GetOriginalArgs()[0:-1] if arg.IsConstant() |
5591 ] | 5610 ] |
5592 if not constants: | 5611 if not constants: |
5593 return | 5612 return |
5594 | 5613 |
5595 code = """ | 5614 code = """ |
5596 TEST_F(GLES2ImplementationTest, %(name)sInvalidConstantArg%(invalid_index)d) { | 5615 TEST_F(GLES2ImplementationTest, %(name)sInvalidConstantArg%(invalid_index)d) { |
5597 %(type)s data[%(count_param)d][%(count)d] = {{0}}; | 5616 %(type)s data[%(count_param)d][%(count)d] = {{0}}; |
5598 for (int ii = 0; ii < %(count_param)d; ++ii) { | 5617 for (int ii = 0; ii < %(count_param)d; ++ii) { |
5599 for (int jj = 0; jj < %(count)d; ++jj) { | 5618 for (int jj = 0; jj < %(count)d; ++jj) { |
5600 data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj); | 5619 data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj); |
5601 } | 5620 } |
5602 } | 5621 } |
5603 gl_->%(name)s(%(args)s, &data[0][0]); | 5622 gl_->%(name)s(%(args)s); |
5604 EXPECT_TRUE(NoCommandsWritten()); | 5623 EXPECT_TRUE(NoCommandsWritten()); |
5605 EXPECT_EQ(%(gl_error)s, CheckError()); | 5624 EXPECT_EQ(%(gl_error)s, CheckError()); |
5606 } | 5625 } |
5607 """ | 5626 """ |
5608 for invalid_arg in constants: | 5627 for invalid_arg in constants: |
5609 gl_arg_strings = [] | 5628 gl_arg_strings = [] |
5610 invalid = invalid_arg.GetInvalidArg(func) | 5629 invalid = invalid_arg.GetInvalidArg(func) |
5611 for arg in func.GetOriginalArgs()[0:-1]: | 5630 for arg in func.GetOriginalArgs(): |
5612 if arg is invalid_arg: | 5631 if arg is invalid_arg: |
5613 gl_arg_strings.append(invalid[0]) | 5632 gl_arg_strings.append(invalid[0]) |
5633 elif arg.IsPointer(): | |
5634 gl_arg_strings.append("&data[0][0]") | |
5614 else: | 5635 else: |
5615 valid_value = arg.GetValidClientSideArg(func) | 5636 valid_value = arg.GetValidClientSideArg(func) |
5616 gl_arg_strings.append(valid_value) | 5637 gl_arg_strings.append(valid_value) |
5617 if arg.name == "count": | 5638 if arg.name == "count": |
5618 count_param = int(valid_value) | 5639 count_param = int(valid_value) |
5619 | 5640 |
5620 file.Write(code % { | 5641 file.Write(code % { |
5621 'name': func.name, | 5642 'name': func.name, |
5622 'invalid_index': func.GetOriginalArgs().index(invalid_arg), | 5643 'invalid_index': func.GetOriginalArgs().index(invalid_arg), |
5623 'type': self.GetArrayType(func), | 5644 'type': self.GetArrayType(func), |
(...skipping 22 matching lines...) Expand all Loading... | |
5646 def WriteImmediateCmdSetHeader(self, func, file): | 5667 def WriteImmediateCmdSetHeader(self, func, file): |
5647 """Overrriden from TypeHandler.""" | 5668 """Overrriden from TypeHandler.""" |
5648 file.Write(" void SetHeader(GLsizei count) {\n") | 5669 file.Write(" void SetHeader(GLsizei count) {\n") |
5649 file.Write( | 5670 file.Write( |
5650 " header.SetCmdByTotalSize<ValueType>(ComputeSize(count));\n") | 5671 " header.SetCmdByTotalSize<ValueType>(ComputeSize(count));\n") |
5651 file.Write(" }\n") | 5672 file.Write(" }\n") |
5652 file.Write("\n") | 5673 file.Write("\n") |
5653 | 5674 |
5654 def WriteImmediateCmdInit(self, func, file): | 5675 def WriteImmediateCmdInit(self, func, file): |
5655 """Overrriden from TypeHandler.""" | 5676 """Overrriden from TypeHandler.""" |
5656 last_arg = func.GetLastOriginalArg() | 5677 file.Write(" void Init(%s) {\n" % |
5657 file.Write(" void Init(%s, %s _%s) {\n" % | 5678 func.MakeTypedInitString("_")) |
5658 (func.MakeTypedCmdArgString("_"), | |
5659 last_arg.type, last_arg.name)) | |
5660 file.Write(" SetHeader(_count);\n") | 5679 file.Write(" SetHeader(_count);\n") |
5661 args = func.GetCmdArgs() | 5680 args = func.GetCmdArgs() |
5662 for arg in args: | 5681 for arg in args: |
5663 file.Write(" %s = _%s;\n" % (arg.name, arg.name)) | 5682 file.Write(" %s = _%s;\n" % (arg.name, arg.name)) |
5664 file.Write(" memcpy(ImmediateDataAddress(this),\n") | 5683 file.Write(" memcpy(ImmediateDataAddress(this),\n") |
5665 file.Write(" _%s, ComputeDataSize(_count));\n" % last_arg.name) | 5684 pointer_arg = func.GetLastOriginalPointerArg() |
5685 file.Write(" _%s, ComputeDataSize(_count));\n" % pointer_arg.name) | |
5666 file.Write(" }\n") | 5686 file.Write(" }\n") |
5667 file.Write("\n") | 5687 file.Write("\n") |
5668 | 5688 |
5669 def WriteImmediateCmdSet(self, func, file): | 5689 def WriteImmediateCmdSet(self, func, file): |
5670 """Overrriden from TypeHandler.""" | 5690 """Overrriden from TypeHandler.""" |
5671 last_arg = func.GetLastOriginalArg() | 5691 file.Write(" void* Set(void* cmd%s) {\n" % |
5672 copy_args = func.MakeCmdArgString("_", False) | 5692 func.MakeTypedInitString("_", True)) |
5673 file.Write(" void* Set(void* cmd%s, %s _%s) {\n" % | 5693 file.Write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % |
5674 (func.MakeTypedCmdArgString("_", True), | 5694 func.MakeInitString("_")) |
5675 last_arg.type, last_arg.name)) | |
5676 file.Write(" static_cast<ValueType*>(cmd)->Init(%s, _%s);\n" % | |
5677 (copy_args, last_arg.name)) | |
5678 file.Write(" const uint32_t size = ComputeSize(_count);\n") | 5695 file.Write(" const uint32_t size = ComputeSize(_count);\n") |
5679 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>(" | 5696 file.Write(" return NextImmediateCmdAddressTotalSize<ValueType>(" |
5680 "cmd, size);\n") | 5697 "cmd, size);\n") |
5681 file.Write(" }\n") | 5698 file.Write(" }\n") |
5682 file.Write("\n") | 5699 file.Write("\n") |
5683 | 5700 |
5684 def WriteImmediateCmdHelper(self, func, file): | 5701 def WriteImmediateCmdHelper(self, func, file): |
5685 """Overrriden from TypeHandler.""" | 5702 """Overrriden from TypeHandler.""" |
5686 code = """ void %(name)s(%(typed_args)s) { | 5703 code = """ void %(name)s(%(typed_args)s) { |
5687 const uint32_t size = gles2::cmds::%(name)s::ComputeSize(count); | 5704 const uint32_t size = gles2::cmds::%(name)s::ComputeSize(count); |
5688 gles2::cmds::%(name)s* c = | 5705 gles2::cmds::%(name)s* c = |
5689 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(size); | 5706 GetImmediateCmdSpaceTotalSize<gles2::cmds::%(name)s>(size); |
5690 if (c) { | 5707 if (c) { |
5691 c->Init(%(args)s); | 5708 c->Init(%(args)s); |
5692 } | 5709 } |
5693 } | 5710 } |
5694 | 5711 |
5695 """ | 5712 """ |
5696 file.Write(code % { | 5713 file.Write(code % { |
5697 "name": func.name, | 5714 "name": func.name, |
5698 "typed_args": func.MakeTypedInitString(""), | 5715 "typed_args": func.MakeTypedInitString(""), |
5699 "args": func.MakeInitString("") | 5716 "args": func.MakeInitString("") |
5700 }) | 5717 }) |
5701 | 5718 |
5702 def WriteImmediateFormatTest(self, func, file): | 5719 def WriteImmediateFormatTest(self, func, file): |
5703 """Overrriden from TypeHandler.""" | 5720 """Overrriden from TypeHandler.""" |
5704 args = func.GetCmdArgs() | 5721 args = func.GetOriginalArgs() |
5705 count_param = 0 | 5722 count_param = 0 |
5706 for arg in args: | 5723 for arg in args: |
5707 if arg.name == "count": | 5724 if arg.name == "count": |
5708 count_param = int(arg.GetValidClientSideCmdArg(func)) | 5725 count_param = int(arg.GetValidClientSideCmdArg(func)) |
5709 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name) | 5726 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name) |
5710 file.Write(" const int kSomeBaseValueToTestWith = 51;\n") | 5727 file.Write(" const int kSomeBaseValueToTestWith = 51;\n") |
5711 file.Write(" static %s data[] = {\n" % self.GetArrayType(func)) | 5728 file.Write(" static %s data[] = {\n" % self.GetArrayType(func)) |
5712 for v in range(0, self.GetArrayCount(func) * count_param): | 5729 for v in range(0, self.GetArrayCount(func) * count_param): |
5713 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" % | 5730 file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" % |
5714 (self.GetArrayType(func), v)) | 5731 (self.GetArrayType(func), v)) |
5715 file.Write(" };\n") | 5732 file.Write(" };\n") |
5716 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" % | 5733 file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" % |
5717 (func.name, func.name)) | 5734 (func.name, func.name)) |
5718 file.Write(" const GLsizei kNumElements = %d;\n" % count_param) | 5735 file.Write(" const GLsizei kNumElements = %d;\n" % count_param) |
5719 file.Write(" const size_t kExpectedCmdSize =\n") | 5736 file.Write(" const size_t kExpectedCmdSize =\n") |
5720 file.Write(" sizeof(cmd) + kNumElements * sizeof(%s) * %d;\n" % | 5737 file.Write(" sizeof(cmd) + kNumElements * sizeof(%s) * %d;\n" % |
5721 (self.GetArrayType(func), self.GetArrayCount(func))) | 5738 (self.GetArrayType(func), self.GetArrayCount(func))) |
5722 file.Write(" void* next_cmd = cmd.Set(\n") | 5739 file.Write(" void* next_cmd = cmd.Set(\n") |
5723 file.Write(" &cmd") | 5740 file.Write(" &cmd") |
5724 for value, arg in enumerate(args): | 5741 for value, arg in enumerate(args): |
5725 file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 1)) | 5742 if arg.IsPointer(): |
5726 file.Write(",\n data);\n") | 5743 file.Write(",\n data") |
5744 elif arg.type == "GLboolean": | |
Ken Russell (switch to Gerrit)
2014/12/05 03:17:37
Why does GLboolean need to be special-cased? Is th
Zhenyao Mo
2014/12/05 17:59:01
Digging further, instead of checking the type is G
| |
5745 continue | |
5746 else: | |
5747 file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 1)) | |
5748 file.Write(");\n") | |
5727 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" % | 5749 file.Write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" % |
5728 func.name) | 5750 func.name) |
5729 file.Write(" cmd.header.command);\n") | 5751 file.Write(" cmd.header.command);\n") |
5730 file.Write(" EXPECT_EQ(kExpectedCmdSize, cmd.header.size * 4u);\n") | 5752 file.Write(" EXPECT_EQ(kExpectedCmdSize, cmd.header.size * 4u);\n") |
5731 for value, arg in enumerate(args): | 5753 for value, arg in enumerate(args): |
5754 if arg.IsPointer() or arg.type == "GLboolean": | |
5755 continue | |
5732 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" % | 5756 file.Write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" % |
5733 (arg.type, value + 1, arg.name)) | 5757 (arg.type, value + 1, arg.name)) |
5734 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n") | 5758 file.Write(" CheckBytesWrittenMatchesExpectedSize(\n") |
5735 file.Write(" next_cmd, sizeof(cmd) +\n") | 5759 file.Write(" next_cmd, sizeof(cmd) +\n") |
5736 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n") | 5760 file.Write(" RoundSizeToMultipleOfEntries(sizeof(data)));\n") |
5737 file.Write(" // TODO(gman): Check that data was inserted;\n") | 5761 file.Write(" // TODO(gman): Check that data was inserted;\n") |
5738 file.Write("}\n") | 5762 file.Write("}\n") |
5739 file.Write("\n") | 5763 file.Write("\n") |
5740 | 5764 |
5741 | 5765 |
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6971 self.args_for_cmds = self.original_args[:] | 6995 self.args_for_cmds = self.original_args[:] |
6972 | 6996 |
6973 self.return_type = info['return_type'] | 6997 self.return_type = info['return_type'] |
6974 if self.return_type != 'void': | 6998 if self.return_type != 'void': |
6975 self.return_arg = CreateArg(info['return_type'] + " result") | 6999 self.return_arg = CreateArg(info['return_type'] + " result") |
6976 else: | 7000 else: |
6977 self.return_arg = None | 7001 self.return_arg = None |
6978 | 7002 |
6979 self.num_pointer_args = sum( | 7003 self.num_pointer_args = sum( |
6980 [1 for arg in self.args_for_cmds if arg.IsPointer()]) | 7004 [1 for arg in self.args_for_cmds if arg.IsPointer()]) |
7005 if self.num_pointer_args > 0: | |
7006 for arg in reversed(self.original_args): | |
7007 if arg.IsPointer(): | |
7008 self.last_original_pointer_arg = arg | |
7009 break | |
7010 else: | |
7011 self.last_original_pointer_arg = None | |
6981 self.info = info | 7012 self.info = info |
6982 self.type_handler = self.type_handlers[info['type']] | 7013 self.type_handler = self.type_handlers[info['type']] |
6983 self.can_auto_generate = (self.num_pointer_args == 0 and | 7014 self.can_auto_generate = (self.num_pointer_args == 0 and |
6984 info['return_type'] == "void") | 7015 info['return_type'] == "void") |
6985 self.InitFunction() | 7016 self.InitFunction() |
6986 | 7017 |
6987 def ParseArgs(self, arg_string): | 7018 def ParseArgs(self, arg_string): |
6988 """Parses a function arg string.""" | 7019 """Parses a function arg string.""" |
6989 args = [] | 7020 args = [] |
6990 parts = arg_string.split(',') | 7021 parts = arg_string.split(',') |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7117 return self.init_args | 7148 return self.init_args |
7118 | 7149 |
7119 def GetOriginalArgs(self): | 7150 def GetOriginalArgs(self): |
7120 """Gets the original arguments to this function.""" | 7151 """Gets the original arguments to this function.""" |
7121 return self.original_args | 7152 return self.original_args |
7122 | 7153 |
7123 def GetLastOriginalArg(self): | 7154 def GetLastOriginalArg(self): |
7124 """Gets the last original argument to this function.""" | 7155 """Gets the last original argument to this function.""" |
7125 return self.original_args[len(self.original_args) - 1] | 7156 return self.original_args[len(self.original_args) - 1] |
7126 | 7157 |
7158 def GetLastOriginalPointerArg(self): | |
7159 return self.last_original_pointer_arg | |
7160 | |
7127 def __MaybePrependComma(self, arg_string, add_comma): | 7161 def __MaybePrependComma(self, arg_string, add_comma): |
7128 """Adds a comma if arg_string is not empty and add_comma is true.""" | 7162 """Adds a comma if arg_string is not empty and add_comma is true.""" |
7129 comma = "" | 7163 comma = "" |
7130 if add_comma and len(arg_string): | 7164 if add_comma and len(arg_string): |
7131 comma = ", " | 7165 comma = ", " |
7132 return "%s%s" % (comma, arg_string) | 7166 return "%s%s" % (comma, arg_string) |
7133 | 7167 |
7134 def MakeTypedOriginalArgString(self, prefix, add_comma = False): | 7168 def MakeTypedOriginalArgString(self, prefix, add_comma = False): |
7135 """Gets a list of arguments as they are in GL.""" | 7169 """Gets a list of arguments as they are in GL.""" |
7136 args = self.GetOriginalArgs() | 7170 args = self.GetOriginalArgs() |
(...skipping 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8876 Format(gen.generated_cpp_filenames) | 8910 Format(gen.generated_cpp_filenames) |
8877 | 8911 |
8878 if gen.errors > 0: | 8912 if gen.errors > 0: |
8879 print "%d errors" % gen.errors | 8913 print "%d errors" % gen.errors |
8880 return 1 | 8914 return 1 |
8881 return 0 | 8915 return 0 |
8882 | 8916 |
8883 | 8917 |
8884 if __name__ == '__main__': | 8918 if __name__ == '__main__': |
8885 sys.exit(main(sys.argv[1:])) | 8919 sys.exit(main(sys.argv[1:])) |
OLD | NEW |