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 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 # bind function. | 1170 # bind function. |
1171 # states: array of states that get set by this function corresponding to | 1171 # states: array of states that get set by this function corresponding to |
1172 # the given arguments | 1172 # the given arguments |
1173 # state_flag: name of flag that is set to true when function is called. | 1173 # state_flag: name of flag that is set to true when function is called. |
1174 # no_gl: no GL function is called. | 1174 # no_gl: no GL function is called. |
1175 # valid_args: A dictionary of argument indices to args to use in unit tests | 1175 # valid_args: A dictionary of argument indices to args to use in unit tests |
1176 # when they can not be automatically determined. | 1176 # when they can not be automatically determined. |
1177 # pepper_interface: The pepper interface that is used for this extension | 1177 # pepper_interface: The pepper interface that is used for this extension |
1178 # invalid_test: False if no invalid test needed. | 1178 # invalid_test: False if no invalid test needed. |
1179 # shadowed: True = the value is shadowed so no glGetXXX call will be made. | 1179 # shadowed: True = the value is shadowed so no glGetXXX call will be made. |
| 1180 # first_element_only: For PUT types, True if only the first element of an |
| 1181 # array is used and we end up calling the single value |
| 1182 # corresponding function. eg. TexParameteriv -> TexParameteri |
1180 | 1183 |
1181 _FUNCTION_INFO = { | 1184 _FUNCTION_INFO = { |
1182 'ActiveTexture': { | 1185 'ActiveTexture': { |
1183 'decoder_func': 'DoActiveTexture', | 1186 'decoder_func': 'DoActiveTexture', |
1184 'unit_test': False, | 1187 'unit_test': False, |
1185 'impl_func': False, | 1188 'impl_func': False, |
1186 'client_test': False, | 1189 'client_test': False, |
1187 }, | 1190 }, |
1188 'AttachShader': {'decoder_func': 'DoAttachShader'}, | 1191 'AttachShader': {'decoder_func': 'DoAttachShader'}, |
1189 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, | 1192 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 'client_test': False, | 1888 'client_test': False, |
1886 'extension': True, | 1889 'extension': True, |
1887 }, | 1890 }, |
1888 'TexImage2D': { | 1891 'TexImage2D': { |
1889 'type': 'Manual', | 1892 'type': 'Manual', |
1890 'immediate': True, | 1893 'immediate': True, |
1891 'client_test': False, | 1894 'client_test': False, |
1892 }, | 1895 }, |
1893 'TexParameterf': { | 1896 'TexParameterf': { |
1894 'decoder_func': 'DoTexParameterf', | 1897 'decoder_func': 'DoTexParameterf', |
| 1898 'gl_test_func': 'glTexParameteri', |
1895 'valid_args': { | 1899 'valid_args': { |
1896 '2': 'GL_NEAREST' | 1900 '2': 'GL_NEAREST' |
1897 }, | 1901 }, |
1898 }, | 1902 }, |
1899 'TexParameteri': { | 1903 'TexParameteri': { |
1900 'decoder_func': 'DoTexParameteri', | 1904 'decoder_func': 'DoTexParameteri', |
1901 'valid_args': { | 1905 'valid_args': { |
1902 '2': 'GL_NEAREST' | 1906 '2': 'GL_NEAREST' |
1903 }, | 1907 }, |
1904 }, | 1908 }, |
1905 'TexParameterfv': { | 1909 'TexParameterfv': { |
1906 'type': 'PUT', | 1910 'type': 'PUT', |
1907 'data_type': 'GLfloat', | 1911 'data_type': 'GLfloat', |
1908 'data_value': 'GL_NEAREST', | 1912 'data_value': 'GL_NEAREST', |
1909 'count': 1, | 1913 'count': 1, |
1910 'decoder_func': 'DoTexParameterfv', | 1914 'decoder_func': 'DoTexParameterfv', |
| 1915 'gl_test_func': 'glTexParameteri', |
| 1916 'first_element_only': True, |
1911 }, | 1917 }, |
1912 'TexParameteriv': { | 1918 'TexParameteriv': { |
1913 'type': 'PUT', | 1919 'type': 'PUT', |
1914 'data_type': 'GLint', | 1920 'data_type': 'GLint', |
1915 'data_value': 'GL_NEAREST', | 1921 'data_value': 'GL_NEAREST', |
1916 'count': 1, | 1922 'count': 1, |
1917 'decoder_func': 'DoTexParameteriv', | 1923 'decoder_func': 'DoTexParameteriv', |
| 1924 'gl_test_func': 'glTexParameteri', |
| 1925 'first_element_only': True, |
1918 }, | 1926 }, |
1919 'TexSubImage2D': { | 1927 'TexSubImage2D': { |
1920 'type': 'Manual', | 1928 'type': 'Manual', |
1921 'immediate': True, | 1929 'immediate': True, |
1922 'client_test': False, | 1930 'client_test': False, |
1923 'cmd_args': 'GLenumTextureTarget target, GLint level, ' | 1931 'cmd_args': 'GLenumTextureTarget target, GLint level, ' |
1924 'GLint xoffset, GLint yoffset, ' | 1932 'GLint xoffset, GLint yoffset, ' |
1925 'GLsizei width, GLsizei height, ' | 1933 'GLsizei width, GLsizei height, ' |
1926 'GLenumTextureFormat format, GLenumPixelType type, ' | 1934 'GLenumTextureFormat format, GLenumPixelType type, ' |
1927 'const void* pixels, GLboolean internal' | 1935 'const void* pixels, GLboolean internal' |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2753 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) | 2761 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) |
2754 gl_func_name = func.GetGLTestFunctionName() | 2762 gl_func_name = func.GetGLTestFunctionName() |
2755 vars = { | 2763 vars = { |
2756 'test_name': 'GLES2DecoderTest%d' % file.file_num, | 2764 'test_name': 'GLES2DecoderTest%d' % file.file_num, |
2757 'name':name, | 2765 'name':name, |
2758 'gl_func_name': gl_func_name, | 2766 'gl_func_name': gl_func_name, |
2759 'args': ", ".join(arg_strings), | 2767 'args': ", ".join(arg_strings), |
2760 'gl_args': ", ".join(gl_arg_strings), | 2768 'gl_args': ", ".join(gl_arg_strings), |
2761 } | 2769 } |
2762 vars.update(extra) | 2770 vars.update(extra) |
| 2771 old_test = "" |
| 2772 while (old_test != test): |
| 2773 old_test = test |
| 2774 test = test % vars |
2763 file.Write(test % vars) | 2775 file.Write(test % vars) |
2764 | 2776 |
2765 def WriteInvalidUnitTest(self, func, file, test, extra = {}): | 2777 def WriteInvalidUnitTest(self, func, file, test, extra = {}): |
2766 """Writes a invalid unit test.""" | 2778 """Writes a invalid unit test.""" |
2767 for arg_index, arg in enumerate(func.GetOriginalArgs()): | 2779 for arg_index, arg in enumerate(func.GetOriginalArgs()): |
2768 num_invalid_values = arg.GetNumInvalidValues(func) | 2780 num_invalid_values = arg.GetNumInvalidValues(func) |
2769 for value_index in range(0, num_invalid_values): | 2781 for value_index in range(0, num_invalid_values): |
2770 arg_strings = [] | 2782 arg_strings = [] |
2771 parse_result = "kNoError" | 2783 parse_result = "kNoError" |
2772 gl_error = None | 2784 gl_error = None |
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4517 | 4529 |
4518 | 4530 |
4519 class PUTHandler(TypeHandler): | 4531 class PUTHandler(TypeHandler): |
4520 """Handler for glTexParameter_v, glVertexAttrib_v functions.""" | 4532 """Handler for glTexParameter_v, glVertexAttrib_v functions.""" |
4521 | 4533 |
4522 def __init__(self): | 4534 def __init__(self): |
4523 TypeHandler.__init__(self) | 4535 TypeHandler.__init__(self) |
4524 | 4536 |
4525 def WriteServiceUnitTest(self, func, file): | 4537 def WriteServiceUnitTest(self, func, file): |
4526 """Writes the service unit test for a command.""" | 4538 """Writes the service unit test for a command.""" |
| 4539 expected_call = "EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));" |
| 4540 if func.GetInfo("first_element_only"): |
| 4541 gl_arg_strings = [] |
| 4542 for count, arg in enumerate(func.GetOriginalArgs()): |
| 4543 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) |
| 4544 gl_arg_strings[-1] = "*" + gl_arg_strings[-1] |
| 4545 expected_call = ("EXPECT_CALL(*gl_, %%(gl_func_name)s(%s));" % |
| 4546 ", ".join(gl_arg_strings)) |
4527 valid_test = """ | 4547 valid_test = """ |
4528 TEST_F(%(test_name)s, %(name)sValidArgs) { | 4548 TEST_F(%(test_name)s, %(name)sValidArgs) { |
4529 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)); | |
4530 SpecializedSetup<cmds::%(name)s, 0>(true); | 4549 SpecializedSetup<cmds::%(name)s, 0>(true); |
4531 cmds::%(name)s cmd; | 4550 cmds::%(name)s cmd; |
4532 cmd.Init(%(args)s); | 4551 cmd.Init(%(args)s); |
4533 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; | 4552 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; |
| 4553 %(expected_call)s |
4534 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 4554 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
4535 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 4555 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
4536 } | 4556 } |
4537 """ | 4557 """ |
4538 extra = { | 4558 extra = { |
4539 'data_type': func.GetInfo('data_type'), | 4559 'data_type': func.GetInfo('data_type'), |
4540 'data_value': func.GetInfo('data_value') or '0', | 4560 'data_value': func.GetInfo('data_value') or '0', |
| 4561 'expected_call': expected_call, |
4541 } | 4562 } |
4542 self.WriteValidUnitTest(func, file, valid_test, extra) | 4563 self.WriteValidUnitTest(func, file, valid_test, extra) |
4543 | 4564 |
4544 invalid_test = """ | 4565 invalid_test = """ |
4545 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 4566 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
4546 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0); | 4567 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0); |
4547 SpecializedSetup<cmds::%(name)s, 0>(false); | 4568 SpecializedSetup<cmds::%(name)s, 0>(false); |
4548 cmds::%(name)s cmd; | 4569 cmds::%(name)s cmd; |
4549 cmd.Init(%(args)s); | 4570 cmd.Init(%(args)s); |
4550 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; | 4571 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; |
4551 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s | 4572 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s |
4552 } | 4573 } |
4553 """ | 4574 """ |
4554 self.WriteInvalidUnitTest(func, file, invalid_test, extra) | 4575 self.WriteInvalidUnitTest(func, file, invalid_test, extra) |
4555 | 4576 |
4556 def WriteImmediateServiceUnitTest(self, func, file): | 4577 def WriteImmediateServiceUnitTest(self, func, file): |
4557 """Writes the service unit test for a command.""" | 4578 """Writes the service unit test for a command.""" |
4558 valid_test = """ | 4579 valid_test = """ |
4559 TEST_F(%(test_name)s, %(name)sValidArgs) { | 4580 TEST_F(%(test_name)s, %(name)sValidArgs) { |
4560 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); | 4581 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); |
4561 EXPECT_CALL( | |
4562 *gl_, | |
4563 %(gl_func_name)s(%(gl_args)s, | |
4564 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd)))); | |
4565 SpecializedSetup<cmds::%(name)s, 0>(true); | 4582 SpecializedSetup<cmds::%(name)s, 0>(true); |
4566 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; | 4583 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; |
4567 cmd.Init(%(gl_args)s, &temp[0]); | 4584 cmd.Init(%(gl_args)s, &temp[0]); |
| 4585 EXPECT_CALL( |
| 4586 *gl_, |
| 4587 %(gl_func_name)s(%(gl_args)s, %(data_ref)sreinterpret_cast< |
| 4588 %(data_type)s*>(ImmediateDataAddress(&cmd)))); |
4568 EXPECT_EQ(error::kNoError, | 4589 EXPECT_EQ(error::kNoError, |
4569 ExecuteImmediateCmd(cmd, sizeof(temp))); | 4590 ExecuteImmediateCmd(cmd, sizeof(temp))); |
4570 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 4591 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
4571 } | 4592 } |
4572 """ | 4593 """ |
4573 gl_arg_strings = [] | 4594 gl_arg_strings = [] |
4574 gl_any_strings = [] | 4595 gl_any_strings = [] |
4575 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): | 4596 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): |
4576 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) | 4597 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) |
4577 gl_any_strings.append("_") | 4598 gl_any_strings.append("_") |
4578 extra = { | 4599 extra = { |
| 4600 'data_ref': ("*" if func.GetInfo('first_element_only') else ""), |
4579 'data_type': func.GetInfo('data_type'), | 4601 'data_type': func.GetInfo('data_type'), |
4580 'data_count': func.GetInfo('count'), | 4602 'data_count': func.GetInfo('count'), |
4581 'data_value': func.GetInfo('data_value') or '0', | 4603 'data_value': func.GetInfo('data_value') or '0', |
4582 'gl_args': ", ".join(gl_arg_strings), | 4604 'gl_args': ", ".join(gl_arg_strings), |
4583 'gl_any_args': ", ".join(gl_any_strings), | 4605 'gl_any_args': ", ".join(gl_any_strings), |
4584 } | 4606 } |
4585 self.WriteValidUnitTest(func, file, valid_test, extra) | 4607 self.WriteValidUnitTest(func, file, valid_test, extra) |
4586 | 4608 |
4587 invalid_test = """ | 4609 invalid_test = """ |
4588 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 4610 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
(...skipping 3029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7618 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h") | 7640 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h") |
7619 | 7641 |
7620 if gen.errors > 0: | 7642 if gen.errors > 0: |
7621 print "%d errors" % gen.errors | 7643 print "%d errors" % gen.errors |
7622 return 1 | 7644 return 1 |
7623 return 0 | 7645 return 0 |
7624 | 7646 |
7625 | 7647 |
7626 if __name__ == '__main__': | 7648 if __name__ == '__main__': |
7627 sys.exit(main(sys.argv[1:])) | 7649 sys.exit(main(sys.argv[1:])) |
OLD | NEW |