Chromium Code Reviews| 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 6123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6134 """ | 6134 """ |
| 6135 f.write(code) | 6135 f.write(code) |
| 6136 | 6136 |
| 6137 def WriteHandlerImplementation (self, func, f): | 6137 def WriteHandlerImplementation (self, func, f): |
| 6138 """Overrriden from TypeHandler.""" | 6138 """Overrriden from TypeHandler.""" |
| 6139 raise NotImplementedError("GENn functions are immediate") | 6139 raise NotImplementedError("GENn functions are immediate") |
| 6140 | 6140 |
| 6141 def WriteImmediateHandlerImplementation(self, func, f): | 6141 def WriteImmediateHandlerImplementation(self, func, f): |
| 6142 """Overrriden from TypeHandler.""" | 6142 """Overrriden from TypeHandler.""" |
| 6143 param_name = func.GetLastOriginalArg().name | 6143 param_name = func.GetLastOriginalArg().name |
| 6144 f.write(" if (!CheckUniqueAndNonNullIds(n, %s) || !%sHelper(n, %s)) {\n" | 6144 f.write(" auto %(name)s_copy = base::MakeUnique<GLuint[]>(n);\n" |
| 6145 " GLuint* %(name)s_safe = %(name)s_copy.get();\n" | |
| 6146 " for (GLsizei i = 0; i < n; ++i)\n" | |
| 6147 " %(name)s_safe[i] = %(name)s[i];\n" | |
|
no sievers
2016/08/23 21:09:04
maybe std::copy here?
piman
2016/08/23 23:27:50
Done.
| |
| 6148 " if (!CheckUniqueAndNonNullIds(n, %(name)s_safe) ||\n" | |
| 6149 " !%(func)sHelper(n, %(name)s_safe)) {\n" | |
| 6145 " return error::kInvalidArguments;\n" | 6150 " return error::kInvalidArguments;\n" |
| 6146 " }\n" % | 6151 " }\n" % {'name': param_name, 'func': func.original_name}) |
| 6147 (param_name, func.original_name, param_name)) | |
| 6148 | 6152 |
| 6149 def WriteGLES2Implementation(self, func, f): | 6153 def WriteGLES2Implementation(self, func, f): |
| 6150 """Overrriden from TypeHandler.""" | 6154 """Overrriden from TypeHandler.""" |
| 6151 log_code = (""" GPU_CLIENT_LOG_CODE_BLOCK({ | 6155 log_code = (""" GPU_CLIENT_LOG_CODE_BLOCK({ |
| 6152 for (GLsizei i = 0; i < n; ++i) { | 6156 for (GLsizei i = 0; i < n; ++i) { |
| 6153 GPU_CLIENT_LOG(" " << i << ": " << %s[i]); | 6157 GPU_CLIENT_LOG(" " << i << ": " << %s[i]); |
| 6154 } | 6158 } |
| 6155 });""" % func.GetOriginalArgs()[1].name) | 6159 });""" % func.GetOriginalArgs()[1].name) |
| 6156 args = { | 6160 args = { |
| 6157 'log_code': log_code, | 6161 'log_code': log_code, |
| (...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7181 def WriteImmediateServiceUnitTest(self, func, f, *extras): | 7185 def WriteImmediateServiceUnitTest(self, func, f, *extras): |
| 7182 """Writes the service unit test for a command.""" | 7186 """Writes the service unit test for a command.""" |
| 7183 valid_test = """ | 7187 valid_test = """ |
| 7184 TEST_P(%(test_name)s, %(name)sValidArgs) { | 7188 TEST_P(%(test_name)s, %(name)sValidArgs) { |
| 7185 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); | 7189 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); |
| 7186 SpecializedSetup<cmds::%(name)s, 0>(true); | 7190 SpecializedSetup<cmds::%(name)s, 0>(true); |
| 7187 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; | 7191 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; |
| 7188 cmd.Init(%(gl_client_args)s, &temp[0]); | 7192 cmd.Init(%(gl_client_args)s, &temp[0]); |
| 7189 EXPECT_CALL( | 7193 EXPECT_CALL( |
| 7190 *gl_, | 7194 *gl_, |
| 7191 %(gl_func_name)s(%(gl_args)s, %(data_ref)sreinterpret_cast< | 7195 %(gl_func_name)s(%(gl_args)s, %(expectation)s));""" |
| 7192 %(data_type)s*>(ImmediateDataAddress(&cmd))));""" | |
| 7193 if func.IsUnsafe(): | 7196 if func.IsUnsafe(): |
| 7194 valid_test += """ | 7197 valid_test += """ |
| 7195 decoder_->set_unsafe_es3_apis_enabled(true);""" | 7198 decoder_->set_unsafe_es3_apis_enabled(true);""" |
| 7196 valid_test += """ | 7199 valid_test += """ |
| 7197 EXPECT_EQ(error::kNoError, | 7200 EXPECT_EQ(error::kNoError, |
| 7198 ExecuteImmediateCmd(cmd, sizeof(temp))); | 7201 ExecuteImmediateCmd(cmd, sizeof(temp))); |
| 7199 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" | 7202 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" |
| 7200 if func.IsUnsafe(): | 7203 if func.IsUnsafe(): |
| 7201 valid_test += """ | 7204 valid_test += """ |
| 7202 decoder_->set_unsafe_es3_apis_enabled(false); | 7205 decoder_->set_unsafe_es3_apis_enabled(false); |
| 7203 EXPECT_EQ(error::kUnknownCommand, | 7206 EXPECT_EQ(error::kUnknownCommand, |
| 7204 ExecuteImmediateCmd(cmd, sizeof(temp)));""" | 7207 ExecuteImmediateCmd(cmd, sizeof(temp)));""" |
| 7205 valid_test += """ | 7208 valid_test += """ |
| 7206 } | 7209 } |
| 7207 """ | 7210 """ |
| 7208 gl_client_arg_strings = [ | 7211 gl_client_arg_strings = [ |
| 7209 arg.GetValidArg(func) for arg in func.GetOriginalArgs()[0:-1] | 7212 arg.GetValidArg(func) for arg in func.GetOriginalArgs()[0:-1] |
| 7210 ] | 7213 ] |
| 7211 gl_arg_strings = [ | 7214 gl_arg_strings = [ |
| 7212 arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[0:-1] | 7215 arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[0:-1] |
| 7213 ] | 7216 ] |
| 7214 gl_any_strings = ["_"] * len(gl_arg_strings) | 7217 gl_any_strings = ["_"] * len(gl_arg_strings) |
| 7218 data_count = self.GetArrayCount(func) | |
| 7219 if func.GetInfo('first_element_only'): | |
| 7220 expectation = "temp[0]" | |
| 7221 else: | |
| 7222 expectation = "PointsToArray(temp, %s)" % data_count | |
| 7215 | 7223 |
| 7216 extra = { | 7224 extra = { |
| 7217 'data_ref': ("*" if func.GetInfo('first_element_only') else ""), | 7225 'expectation': expectation, |
| 7218 'data_type': self.GetArrayType(func), | 7226 'data_type': self.GetArrayType(func), |
| 7219 'data_count': self.GetArrayCount(func), | 7227 'data_count': data_count, |
| 7220 'data_value': func.GetInfo('data_value') or '0', | 7228 'data_value': func.GetInfo('data_value') or '0', |
| 7221 'gl_client_args': ", ".join(gl_client_arg_strings), | 7229 'gl_client_args': ", ".join(gl_client_arg_strings), |
| 7222 'gl_args': ", ".join(gl_arg_strings), | 7230 'gl_args': ", ".join(gl_arg_strings), |
| 7223 'gl_any_args': ", ".join(gl_any_strings), | 7231 'gl_any_args': ", ".join(gl_any_strings), |
| 7224 } | 7232 } |
| 7225 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) | 7233 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) |
| 7226 | 7234 |
| 7227 invalid_test = """ | 7235 invalid_test = """ |
| 7228 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 7236 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
| 7229 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();""" | 7237 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();""" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7504 'gl_args': ", ".join(gl_arg_strings), | 7512 'gl_args': ", ".join(gl_arg_strings), |
| 7505 'args': ", ".join(arg_strings), | 7513 'args': ", ".join(arg_strings), |
| 7506 } | 7514 } |
| 7507 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) | 7515 self.WriteValidUnitTest(func, f, valid_test, extra, *extras) |
| 7508 | 7516 |
| 7509 def WriteImmediateServiceUnitTest(self, func, f, *extras): | 7517 def WriteImmediateServiceUnitTest(self, func, f, *extras): |
| 7510 """Overridden from TypeHandler.""" | 7518 """Overridden from TypeHandler.""" |
| 7511 valid_test = """ | 7519 valid_test = """ |
| 7512 TEST_P(%(test_name)s, %(name)sValidArgs) { | 7520 TEST_P(%(test_name)s, %(name)sValidArgs) { |
| 7513 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); | 7521 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); |
| 7522 SpecializedSetup<cmds::%(name)s, 0>(true); | |
| 7523 %(data_type)s temp[%(data_count)s * 2] = { 0, }; | |
| 7514 EXPECT_CALL( | 7524 EXPECT_CALL( |
| 7515 *gl_, | 7525 *gl_, |
| 7516 %(gl_func_name)s(%(gl_args)s, | 7526 %(gl_func_name)s(%(gl_args)s, |
| 7517 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd)))); | 7527 PointsToArray(temp, %(data_count)s))); |
| 7518 SpecializedSetup<cmds::%(name)s, 0>(true); | |
| 7519 %(data_type)s temp[%(data_count)s * 2] = { 0, }; | |
| 7520 cmd.Init(%(args)s, &temp[0]);""" | 7528 cmd.Init(%(args)s, &temp[0]);""" |
| 7521 if func.IsUnsafe(): | 7529 if func.IsUnsafe(): |
| 7522 valid_test += """ | 7530 valid_test += """ |
| 7523 decoder_->set_unsafe_es3_apis_enabled(true);""" | 7531 decoder_->set_unsafe_es3_apis_enabled(true);""" |
| 7524 valid_test += """ | 7532 valid_test += """ |
| 7525 EXPECT_EQ(error::kNoError, | 7533 EXPECT_EQ(error::kNoError, |
| 7526 ExecuteImmediateCmd(cmd, sizeof(temp))); | 7534 ExecuteImmediateCmd(cmd, sizeof(temp))); |
| 7527 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" | 7535 EXPECT_EQ(GL_NO_ERROR, GetGLError());""" |
| 7528 if func.IsUnsafe(): | 7536 if func.IsUnsafe(): |
| 7529 valid_test += """ | 7537 valid_test += """ |
| (...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9143 match = re.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self.type) | 9151 match = re.match('(const\s+)?(?P<element_type>[\w]+)\s*\*', self.type) |
| 9144 assert match | 9152 assert match |
| 9145 return match.groupdict()['element_type'] | 9153 return match.groupdict()['element_type'] |
| 9146 | 9154 |
| 9147 def AddCmdArgs(self, args): | 9155 def AddCmdArgs(self, args): |
| 9148 """Overridden from Argument.""" | 9156 """Overridden from Argument.""" |
| 9149 pass | 9157 pass |
| 9150 | 9158 |
| 9151 def WriteGetCode(self, f): | 9159 def WriteGetCode(self, f): |
| 9152 """Overridden from Argument.""" | 9160 """Overridden from Argument.""" |
| 9153 f.write( | 9161 f.write(" %s %s = GetImmediateDataAs<%s>(\n" % |
| 9154 " %s %s = GetImmediateDataAs<%s>(\n" % | 9162 (self.type, self.name, self.type)) |
| 9155 (self.type, self.name, self.type)) | |
| 9156 f.write(" c, data_size, immediate_data_size);\n") | 9163 f.write(" c, data_size, immediate_data_size);\n") |
| 9157 | 9164 |
| 9158 def WriteValidationCode(self, f, func): | 9165 def WriteValidationCode(self, f, func): |
| 9159 """Overridden from Argument.""" | 9166 """Overridden from Argument.""" |
| 9160 if self.optional: | 9167 if self.optional: |
| 9161 return | 9168 return |
| 9162 f.write(" if (%s == NULL) {\n" % self.name) | 9169 f.write(" if (%s == NULL) {\n" % self.name) |
| 9163 f.write(" return error::kOutOfBounds;\n") | 9170 f.write(" return error::kOutOfBounds;\n") |
| 9164 f.write(" }\n") | 9171 f.write(" }\n") |
| 9165 | 9172 |
| (...skipping 2339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11505 Format(gen.generated_cpp_filenames) | 11512 Format(gen.generated_cpp_filenames) |
| 11506 | 11513 |
| 11507 if gen.errors > 0: | 11514 if gen.errors > 0: |
| 11508 print "%d errors" % gen.errors | 11515 print "%d errors" % gen.errors |
| 11509 return 1 | 11516 return 1 |
| 11510 return 0 | 11517 return 0 |
| 11511 | 11518 |
| 11512 | 11519 |
| 11513 if __name__ == '__main__': | 11520 if __name__ == '__main__': |
| 11514 sys.exit(main(sys.argv[1:])) | 11521 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |