| 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 5964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5975 """ | 5975 """ |
| 5976 f.write(code) | 5976 f.write(code) |
| 5977 | 5977 |
| 5978 def WriteHandlerImplementation (self, func, f): | 5978 def WriteHandlerImplementation (self, func, f): |
| 5979 """Overrriden from TypeHandler.""" | 5979 """Overrriden from TypeHandler.""" |
| 5980 raise NotImplementedError("GENn functions are immediate") | 5980 raise NotImplementedError("GENn functions are immediate") |
| 5981 | 5981 |
| 5982 def WriteImmediateHandlerImplementation(self, func, f): | 5982 def WriteImmediateHandlerImplementation(self, func, f): |
| 5983 """Overrriden from TypeHandler.""" | 5983 """Overrriden from TypeHandler.""" |
| 5984 param_name = func.GetLastOriginalArg().name | 5984 param_name = func.GetLastOriginalArg().name |
| 5985 f.write(" if (!CheckUniqueAndNonNullIds(n, %s) || !%sHelper(n, %s)) {\n" | 5985 f.write(" auto %(name)s_copy = base::MakeUnique<GLuint[]>(n);\n" |
| 5986 " GLuint* %(name)s_safe = %(name)s_copy.get();\n" |
| 5987 " std::copy(%(name)s, %(name)s + n, %(name)s_safe);\n" |
| 5988 " if (!CheckUniqueAndNonNullIds(n, %(name)s_safe) ||\n" |
| 5989 " !%(func)sHelper(n, %(name)s_safe)) {\n" |
| 5986 " return error::kInvalidArguments;\n" | 5990 " return error::kInvalidArguments;\n" |
| 5987 " }\n" % | 5991 " }\n" % {'name': param_name, 'func': func.original_name}) |
| 5988 (param_name, func.original_name, param_name)) | |
| 5989 | 5992 |
| 5990 def WriteGLES2Implementation(self, func, f): | 5993 def WriteGLES2Implementation(self, func, f): |
| 5991 """Overrriden from TypeHandler.""" | 5994 """Overrriden from TypeHandler.""" |
| 5992 log_code = (""" GPU_CLIENT_LOG_CODE_BLOCK({ | 5995 log_code = (""" GPU_CLIENT_LOG_CODE_BLOCK({ |
| 5993 for (GLsizei i = 0; i < n; ++i) { | 5996 for (GLsizei i = 0; i < n; ++i) { |
| 5994 GPU_CLIENT_LOG(" " << i << ": " << %s[i]); | 5997 GPU_CLIENT_LOG(" " << i << ": " << %s[i]); |
| 5995 } | 5998 } |
| 5996 });""" % func.GetOriginalArgs()[1].name) | 5999 });""" % func.GetOriginalArgs()[1].name) |
| 5997 args = { | 6000 args = { |
| 5998 'log_code': log_code, | 6001 'log_code': log_code, |
| (...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7022 def WriteImmediateServiceUnitTest(self, func, f, *extras): | 7025 def WriteImmediateServiceUnitTest(self, func, f, *extras): |
| 7023 """Writes the service unit test for a command.""" | 7026 """Writes the service unit test for a command.""" |
| 7024 valid_test = """ | 7027 valid_test = """ |
| 7025 TEST_P(%(test_name)s, %(name)sValidArgs) { | 7028 TEST_P(%(test_name)s, %(name)sValidArgs) { |
| 7026 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); | 7029 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); |
| 7027 SpecializedSetup<cmds::%(name)s, 0>(true); | 7030 SpecializedSetup<cmds::%(name)s, 0>(true); |
| 7028 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; | 7031 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; |
| 7029 cmd.Init(%(gl_client_args)s, &temp[0]); | 7032 cmd.Init(%(gl_client_args)s, &temp[0]); |
| 7030 EXPECT_CALL( | 7033 EXPECT_CALL( |
| 7031 *gl_, | 7034 *gl_, |
| 7032 %(gl_func_name)s(%(gl_args)s, %(data_ref)sreinterpret_cast< | 7035 %(gl_func_name)s(%(gl_args)s, %(expectation)s));""" |
| 7033 %(data_type)s*>(ImmediateDataAddress(&cmd))));""" | |
| 7034 if func.IsUnsafe(): | 7036 if func.IsUnsafe(): |
| 7035 valid_test += """ | 7037 valid_test += """ |
| 7036 decoder_->set_unsafe_es3_apis_enabled(true);""" | 7038 decoder_->set_unsafe_es3_apis_enabled(true);""" |
| 7037 valid_test += """ | 7039 valid_test += """ |
| 7038 EXPECT_EQ(error::kNoError, | 7040 EXPECT_EQ(error::kNoError, |
| 7039 ExecuteImmediateCmd(cmd, sizeof(temp))); | 7041 ExecuteImmediateCmd(cmd, sizeof(temp))); |
| 7040 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" | 7042 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" |
| 7041 if func.IsUnsafe(): | 7043 if func.IsUnsafe(): |
| 7042 valid_test += """ | 7044 valid_test += """ |
| 7043 decoder_->set_unsafe_es3_apis_enabled(false); | 7045 decoder_->set_unsafe_es3_apis_enabled(false); |
| 7044 EXPECT_EQ(error::kUnknownCommand, | 7046 EXPECT_EQ(error::kUnknownCommand, |
| 7045 ExecuteImmediateCmd(cmd, sizeof(temp)));""" | 7047 ExecuteImmediateCmd(cmd, sizeof(temp)));""" |
| 7046 valid_test += """ | 7048 valid_test += """ |
| 7047 } | 7049 } |
| 7048 """ | 7050 """ |
| 7049 gl_client_arg_strings = [ | 7051 gl_client_arg_strings = [ |
| 7050 arg.GetValidArg(func) for arg in func.GetOriginalArgs()[0:-1] | 7052 arg.GetValidArg(func) for arg in func.GetOriginalArgs()[0:-1] |
| 7051 ] | 7053 ] |
| 7052 gl_arg_strings = [ | 7054 gl_arg_strings = [ |
| 7053 arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[0:-1] | 7055 arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[0:-1] |
| 7054 ] | 7056 ] |
| 7055 gl_any_strings = ["_"] * len(gl_arg_strings) | 7057 gl_any_strings = ["_"] * len(gl_arg_strings) |
| 7058 data_count = self.GetArrayCount(func) |
| 7059 if func.GetInfo('first_element_only'): |
| 7060 expectation = "temp[0]" |
| 7061 else: |
| 7062 expectation = "PointsToArray(temp, %s)" % data_count |
| 7056 | 7063 |
| 7057 extra = { | 7064 extra = { |
| 7058 'data_ref': ("*" if func.GetInfo('first_element_only') else ""), | 7065 'expectation': expectation, |
| 7059 'data_type': self.GetArrayType(func), | 7066 'data_type': self.GetArrayType(func), |
| 7060 'data_count': self.GetArrayCount(func), | 7067 'data_count': data_count, |
| 7061 'data_value': func.GetInfo('data_value') or '0', | 7068 'data_value': func.GetInfo('data_value') or '0', |
| 7062 'gl_client_args': ", ".join(gl_client_arg_strings), | 7069 'gl_client_args': ", ".join(gl_client_arg_strings), |
| 7063 'gl_args': ", ".join(gl_arg_strings), | 7070 'gl_args': ", ".join(gl_arg_strings), |
| 7064 'gl_any_args': ", ".join(gl_any_strings), | 7071 'gl_any_args': ", ".join(gl_any_strings), |
| 7065 } | 7072 } |
| 7066 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) | 7073 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) |
| 7067 | 7074 |
| 7068 invalid_test = """ | 7075 invalid_test = """ |
| 7069 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 7076 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
| 7070 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();""" | 7077 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();""" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7345 'gl_args': ", ".join(gl_arg_strings), | 7352 'gl_args': ", ".join(gl_arg_strings), |
| 7346 'args': ", ".join(arg_strings), | 7353 'args': ", ".join(arg_strings), |
| 7347 } | 7354 } |
| 7348 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) | 7355 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) |
| 7349 | 7356 |
| 7350 def WriteImmediateServiceUnitTest(self, func, f, *extras): | 7357 def WriteImmediateServiceUnitTest(self, func, f, *extras): |
| 7351 """Overridden from TypeHandler.""" | 7358 """Overridden from TypeHandler.""" |
| 7352 valid_test = """ | 7359 valid_test = """ |
| 7353 TEST_P(%(test_name)s, %(name)sValidArgs) { | 7360 TEST_P(%(test_name)s, %(name)sValidArgs) { |
| 7354 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); | 7361 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); |
| 7362 SpecializedSetup<cmds::%(name)s, 0>(true); |
| 7363 %(data_type)s temp[%(data_count)s * 2] = { 0, }; |
| 7355 EXPECT_CALL( | 7364 EXPECT_CALL( |
| 7356 *gl_, | 7365 *gl_, |
| 7357 %(gl_func_name)s(%(gl_args)s, | 7366 %(gl_func_name)s(%(gl_args)s, |
| 7358 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd)))); | 7367 PointsToArray(temp, %(data_count)s))); |
| 7359 SpecializedSetup<cmds::%(name)s, 0>(true); | |
| 7360 %(data_type)s temp[%(data_count)s * 2] = { 0, }; | |
| 7361 cmd.Init(%(args)s, &temp[0]);""" | 7368 cmd.Init(%(args)s, &temp[0]);""" |
| 7362 if func.IsUnsafe(): | 7369 if func.IsUnsafe(): |
| 7363 valid_test += """ | 7370 valid_test += """ |
| 7364 decoder_->set_unsafe_es3_apis_enabled(true);""" | 7371 decoder_->set_unsafe_es3_apis_enabled(true);""" |
| 7365 valid_test += """ | 7372 valid_test += """ |
| 7366 EXPECT_EQ(error::kNoError, | 7373 EXPECT_EQ(error::kNoError, |
| 7367 ExecuteImmediateCmd(cmd, sizeof(temp))); | 7374 ExecuteImmediateCmd(cmd, sizeof(temp))); |
| 7368 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" | 7375 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" |
| 7369 if func.IsUnsafe(): | 7376 if func.IsUnsafe(): |
| 7370 valid_test += """ | 7377 valid_test += """ |
| (...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8984 match = re.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self.type) | 8991 match = re.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self.type) |
| 8985 assert match | 8992 assert match |
| 8986 return match.groupdict()['element_type'] | 8993 return match.groupdict()['element_type'] |
| 8987 | 8994 |
| 8988 def AddCmdArgs(self, args): | 8995 def AddCmdArgs(self, args): |
| 8989 """Overridden from Argument.""" | 8996 """Overridden from Argument.""" |
| 8990 pass | 8997 pass |
| 8991 | 8998 |
| 8992 def WriteGetCode(self, f): | 8999 def WriteGetCode(self, f): |
| 8993 """Overridden from Argument.""" | 9000 """Overridden from Argument.""" |
| 8994 f.write( | 9001 f.write(" %s %s = GetImmediateDataAs<%s>(\n" % |
| 8995 " %s %s = GetImmediateDataAs<%s>(\n" % | 9002 (self.type, self.name, self.type)) |
| 8996 (self.type, self.name, self.type)) | |
| 8997 f.write(" c, data_size, immediate_data_size);\n") | 9003 f.write(" c, data_size, immediate_data_size);\n") |
| 8998 | 9004 |
| 8999 def WriteValidationCode(self, f, func): | 9005 def WriteValidationCode(self, f, func): |
| 9000 """Overridden from Argument.""" | 9006 """Overridden from Argument.""" |
| 9001 if self.optional: | 9007 if self.optional: |
| 9002 return | 9008 return |
| 9003 f.write(" if (%s == NULL) {\n" % self.name) | 9009 f.write(" if (%s == NULL) {\n" % self.name) |
| 9004 f.write(" return error::kOutOfBounds;\n") | 9010 f.write(" return error::kOutOfBounds;\n") |
| 9005 f.write(" }\n") | 9011 f.write(" }\n") |
| 9006 | 9012 |
| (...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11303 Format(gen.generated_cpp_filenames) | 11309 Format(gen.generated_cpp_filenames) |
| 11304 | 11310 |
| 11305 if gen.errors > 0: | 11311 if gen.errors > 0: |
| 11306 print "%d errors" % gen.errors | 11312 print "%d errors" % gen.errors |
| 11307 return 1 | 11313 return 1 |
| 11308 return 0 | 11314 return 0 |
| 11309 | 11315 |
| 11310 | 11316 |
| 11311 if __name__ == '__main__': | 11317 if __name__ == '__main__': |
| 11312 sys.exit(main(sys.argv[1:])) | 11318 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |