| 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 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 'needs_size': True, | 1424 'needs_size': True, |
| 1425 }, | 1425 }, |
| 1426 'BindBuffer': { | 1426 'BindBuffer': { |
| 1427 'type': 'Bind', | 1427 'type': 'Bind', |
| 1428 'decoder_func': 'DoBindBuffer', | 1428 'decoder_func': 'DoBindBuffer', |
| 1429 'gen_func': 'GenBuffersARB', | 1429 'gen_func': 'GenBuffersARB', |
| 1430 }, | 1430 }, |
| 1431 'BindBufferBase': { | 1431 'BindBufferBase': { |
| 1432 'type': 'Bind', | 1432 'type': 'Bind', |
| 1433 'id_mapping': [ 'Buffer' ], | 1433 'id_mapping': [ 'Buffer' ], |
| 1434 'gen_func': 'GenBuffersARB', |
| 1434 'unsafe': True, | 1435 'unsafe': True, |
| 1435 }, | 1436 }, |
| 1436 'BindFramebuffer': { | 1437 'BindFramebuffer': { |
| 1437 'type': 'Bind', | 1438 'type': 'Bind', |
| 1438 'decoder_func': 'DoBindFramebuffer', | 1439 'decoder_func': 'DoBindFramebuffer', |
| 1439 'gl_test_func': 'glBindFramebufferEXT', | 1440 'gl_test_func': 'glBindFramebufferEXT', |
| 1440 'gen_func': 'GenFramebuffersEXT', | 1441 'gen_func': 'GenFramebuffersEXT', |
| 1441 'trace_level': 1, | 1442 'trace_level': 1, |
| 1442 }, | 1443 }, |
| 1443 'BindRenderbuffer': { | 1444 'BindRenderbuffer': { |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 'expectation': False, | 2162 'expectation': False, |
| 2162 }, | 2163 }, |
| 2163 'IsShader': { | 2164 'IsShader': { |
| 2164 'type': 'Is', | 2165 'type': 'Is', |
| 2165 'decoder_func': 'DoIsShader', | 2166 'decoder_func': 'DoIsShader', |
| 2166 'expectation': False, | 2167 'expectation': False, |
| 2167 }, | 2168 }, |
| 2168 'IsSampler': { | 2169 'IsSampler': { |
| 2169 'type': 'Is', | 2170 'type': 'Is', |
| 2170 'id_mapping': [ 'Sampler' ], | 2171 'id_mapping': [ 'Sampler' ], |
| 2172 'expectation': False, |
| 2171 'unsafe': True, | 2173 'unsafe': True, |
| 2172 }, | 2174 }, |
| 2173 'IsTexture': { | 2175 'IsTexture': { |
| 2174 'type': 'Is', | 2176 'type': 'Is', |
| 2175 'decoder_func': 'DoIsTexture', | 2177 'decoder_func': 'DoIsTexture', |
| 2176 'expectation': False, | 2178 'expectation': False, |
| 2177 }, | 2179 }, |
| 2178 'IsTransformFeedback': { | 2180 'IsTransformFeedback': { |
| 2179 'type': 'Is', | 2181 'type': 'Is', |
| 2180 'id_mapping': [ 'TransformFeedback' ], | 2182 'id_mapping': [ 'TransformFeedback' ], |
| 2183 'expectation': False, |
| 2181 'unsafe': True, | 2184 'unsafe': True, |
| 2182 }, | 2185 }, |
| 2183 'LinkProgram': { | 2186 'LinkProgram': { |
| 2184 'decoder_func': 'DoLinkProgram', | 2187 'decoder_func': 'DoLinkProgram', |
| 2185 'impl_func': False, | 2188 'impl_func': False, |
| 2186 }, | 2189 }, |
| 2187 'MapBufferCHROMIUM': { | 2190 'MapBufferCHROMIUM': { |
| 2188 'gen_cmd': False, | 2191 'gen_cmd': False, |
| 2189 'extension': True, | 2192 'extension': True, |
| 2190 'chromium': True, | 2193 'chromium': True, |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3233 'cmd_name': func.name, | 3236 'cmd_name': func.name, |
| 3234 'field_name': name, | 3237 'field_name': name, |
| 3235 'offset': offset, | 3238 'offset': offset, |
| 3236 }) | 3239 }) |
| 3237 offset += _SIZE_OF_UINT32 | 3240 offset += _SIZE_OF_UINT32 |
| 3238 file.Write("\n") | 3241 file.Write("\n") |
| 3239 | 3242 |
| 3240 def WriteHandlerImplementation(self, func, file): | 3243 def WriteHandlerImplementation(self, func, file): |
| 3241 """Writes the handler implementation for this command.""" | 3244 """Writes the handler implementation for this command.""" |
| 3242 if func.IsUnsafe() and func.GetInfo('id_mapping'): | 3245 if func.IsUnsafe() and func.GetInfo('id_mapping'): |
| 3246 code_no_gen = """ if (!group_->Get%(type)sServiceId(%(var)s, &%(var)s)) { |
| 3247 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "%(func)s", "invalid %(var)s id"); |
| 3248 return error::kNoError; |
| 3249 } |
| 3250 """ |
| 3251 code_gen = """ if (!group_->Get%(type)sServiceId(%(var)s, &%(var)s)) { |
| 3252 if (!group_->bind_generates_resource()) { |
| 3253 LOCAL_SET_GL_ERROR( |
| 3254 GL_INVALID_OPERATION, "%(func)s", "invalid %(var)s id"); |
| 3255 return error::kNoError; |
| 3256 } |
| 3257 GLuint client_id = %(var)s; |
| 3258 gl%(gen_func)s(1, &%(var)s); |
| 3259 Create%(type)s(client_id, %(var)s); |
| 3260 } |
| 3261 """ |
| 3262 gen_func = func.GetInfo('gen_func') |
| 3243 for id_type in func.GetInfo('id_mapping'): | 3263 for id_type in func.GetInfo('id_mapping'): |
| 3244 file.Write(" group_->Get%sServiceId(%s, &%s);\n" % | 3264 if gen_func and id_type in gen_func: |
| 3245 (id_type, id_type.lower(), id_type.lower())) | 3265 file.Write(code_gen % { 'type': id_type, |
| 3266 'var': id_type.lower(), |
| 3267 'func': func.GetGLFunctionName(), |
| 3268 'gen_func': gen_func }) |
| 3269 else: |
| 3270 file.Write(code_no_gen % { 'type': id_type, |
| 3271 'var': id_type.lower(), |
| 3272 'func': func.GetGLFunctionName() }) |
| 3246 file.Write(" %s(%s);\n" % | 3273 file.Write(" %s(%s);\n" % |
| 3247 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 3274 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) |
| 3248 | 3275 |
| 3249 def WriteCmdSizeTest(self, func, file): | 3276 def WriteCmdSizeTest(self, func, file): |
| 3250 """Writes the size test for a command.""" | 3277 """Writes the size test for a command.""" |
| 3251 file.Write(" EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);\n") | 3278 file.Write(" EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);\n") |
| 3252 | 3279 |
| 3253 def WriteFormatTest(self, func, file): | 3280 def WriteFormatTest(self, func, file): |
| 3254 """Writes a format test for a command.""" | 3281 """Writes a format test for a command.""" |
| 3255 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name) | 3282 file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name) |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4392 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd)); | 4419 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd)); |
| 4393 } | 4420 } |
| 4394 """ | 4421 """ |
| 4395 else: | 4422 else: |
| 4396 valid_test += """ | 4423 valid_test += """ |
| 4397 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 4424 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 4398 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 4425 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4399 } | 4426 } |
| 4400 """ | 4427 """ |
| 4401 if func.GetInfo("gen_func"): | 4428 if func.GetInfo("gen_func"): |
| 4402 valid_test += """ | 4429 valid_test += """ |
| 4403 TEST_P(%(test_name)s, %(name)sValidArgsNewId) { | 4430 TEST_P(%(test_name)s, %(name)sValidArgsNewId) { |
| 4404 EXPECT_CALL(*gl_, %(gl_func_name)s(%(first_gl_arg)s, kNewServiceId)); | 4431 EXPECT_CALL(*gl_, |
| 4432 %(gl_func_name)s(%(all_except_last_gl_arg)s, kNewServiceId)); |
| 4405 EXPECT_CALL(*gl_, %(gl_gen_func_name)s(1, _)) | 4433 EXPECT_CALL(*gl_, %(gl_gen_func_name)s(1, _)) |
| 4406 .WillOnce(SetArgumentPointee<1>(kNewServiceId)); | 4434 .WillOnce(SetArgumentPointee<1>(kNewServiceId)); |
| 4407 SpecializedSetup<cmds::%(name)s, 0>(true); | 4435 SpecializedSetup<cmds::%(name)s, 0>(true); |
| 4408 cmds::%(name)s cmd; | 4436 cmds::%(name)s cmd; |
| 4409 cmd.Init(%(first_arg)s, kNewClientId); | 4437 cmd.Init(%(all_except_last_arg)s, kNewClientId);""" |
| 4438 if func.IsUnsafe(): |
| 4439 valid_test += """ |
| 4440 decoder_->set_unsafe_es3_apis_enabled(true); |
| 4441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 4442 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4443 EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL); |
| 4444 decoder_->set_unsafe_es3_apis_enabled(false); |
| 4445 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd)); |
| 4446 } |
| 4447 """ |
| 4448 else: |
| 4449 valid_test += """ |
| 4410 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 4450 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 4411 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 4451 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 4412 EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL); | 4452 EXPECT_TRUE(Get%(resource_type)s(kNewClientId) != NULL); |
| 4413 } | 4453 } |
| 4414 """ | 4454 """ |
| 4455 |
| 4456 all_except_last_arg = [ |
| 4457 arg.GetValidArg(func) for arg in func.GetOriginalArgs()[:-1] |
| 4458 ] |
| 4459 all_except_last_gl_arg = [ |
| 4460 arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[:-1] |
| 4461 ] |
| 4415 self.WriteValidUnitTest(func, file, valid_test, { | 4462 self.WriteValidUnitTest(func, file, valid_test, { |
| 4416 'first_arg': func.GetOriginalArgs()[0].GetValidArg(func), | 4463 'all_except_last_arg': ", ".join(all_except_last_arg), |
| 4417 'first_gl_arg': func.GetOriginalArgs()[0].GetValidGLArg(func), | 4464 'all_except_last_gl_arg': ", ".join(all_except_last_gl_arg), |
| 4418 'resource_type': func.GetOriginalArgs()[-1].resource_type, | 4465 'resource_type': func.GetOriginalArgs()[-1].resource_type, |
| 4419 'gl_gen_func_name': func.GetInfo("gen_func"), | 4466 'gl_gen_func_name': func.GetInfo("gen_func"), |
| 4420 }, *extras) | 4467 }, *extras) |
| 4421 | 4468 |
| 4422 invalid_test = """ | 4469 invalid_test = """ |
| 4423 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { | 4470 TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { |
| 4424 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0); | 4471 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0); |
| 4425 SpecializedSetup<cmds::%(name)s, 0>(false); | 4472 SpecializedSetup<cmds::%(name)s, 0>(false); |
| 4426 cmds::%(name)s cmd; | 4473 cmds::%(name)s cmd; |
| 4427 cmd.Init(%(args)s); | 4474 cmd.Init(%(args)s); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4442 | 4489 |
| 4443 file.Write("%s GLES2Implementation::%s(%s) {\n" % | 4490 file.Write("%s GLES2Implementation::%s(%s) {\n" % |
| 4444 (func.return_type, func.original_name, | 4491 (func.return_type, func.original_name, |
| 4445 func.MakeTypedOriginalArgString(""))) | 4492 func.MakeTypedOriginalArgString(""))) |
| 4446 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") | 4493 file.Write(" GPU_CLIENT_SINGLE_THREAD_CHECK();\n") |
| 4447 func.WriteDestinationInitalizationValidation(file) | 4494 func.WriteDestinationInitalizationValidation(file) |
| 4448 self.WriteClientGLCallLog(func, file) | 4495 self.WriteClientGLCallLog(func, file) |
| 4449 for arg in func.GetOriginalArgs(): | 4496 for arg in func.GetOriginalArgs(): |
| 4450 arg.WriteClientSideValidationCode(file, func) | 4497 arg.WriteClientSideValidationCode(file, func) |
| 4451 | 4498 |
| 4452 if func.IsUnsafe(): | 4499 code = """ if (Is%(type)sReservedId(%(id)s)) { |
| 4453 code = """ helper_->%(name)s(%(arg_string)s); | |
| 4454 CheckGLError(); | |
| 4455 } | |
| 4456 | |
| 4457 """ | |
| 4458 else: | |
| 4459 code = """ if (Is%(type)sReservedId(%(id)s)) { | |
| 4460 SetGLError(GL_INVALID_OPERATION, "%(name)s\", \"%(id)s reserved id"); | 4500 SetGLError(GL_INVALID_OPERATION, "%(name)s\", \"%(id)s reserved id"); |
| 4461 return; | 4501 return; |
| 4462 } | 4502 } |
| 4463 %(name)sHelper(%(arg_string)s); | 4503 %(name)sHelper(%(arg_string)s); |
| 4464 CheckGLError(); | 4504 CheckGLError(); |
| 4465 } | 4505 } |
| 4466 | 4506 |
| 4467 """ | 4507 """ |
| 4468 name_arg = None | 4508 name_arg = None |
| 4469 if len(func.GetOriginalArgs()) == 1: | 4509 if len(func.GetOriginalArgs()) == 1: |
| (...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6420 | 6460 |
| 6421 code = """ typedef cmds::%(func_name)s::Result Result; | 6461 code = """ typedef cmds::%(func_name)s::Result Result; |
| 6422 Result* result_dst = GetSharedMemoryAs<Result*>( | 6462 Result* result_dst = GetSharedMemoryAs<Result*>( |
| 6423 c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); | 6463 c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); |
| 6424 if (!result_dst) { | 6464 if (!result_dst) { |
| 6425 return error::kOutOfBounds; | 6465 return error::kOutOfBounds; |
| 6426 } | 6466 } |
| 6427 """ | 6467 """ |
| 6428 file.Write(code % {'func_name': func.name}) | 6468 file.Write(code % {'func_name': func.name}) |
| 6429 func.WriteHandlerValidation(file) | 6469 func.WriteHandlerValidation(file) |
| 6430 if func.IsUnsafe() and func.GetInfo('id_mapping'): | 6470 if func.IsUnsafe(): |
| 6431 for id_type in func.GetInfo('id_mapping'): | 6471 assert func.GetInfo('id_mapping') |
| 6432 file.Write(" group_->Get%sServiceId(%s, &%s);\n" % | 6472 assert len(func.GetInfo('id_mapping')) == 1 |
| 6433 (id_type, id_type.lower(), id_type.lower())) | 6473 id_type = func.GetInfo('id_mapping')[0] |
| 6434 file.Write(" *result_dst = %s(%s);\n" % | 6474 file.Write(" *result_dst = group_->Get%sServiceId(%s, &%s);\n" % |
| 6435 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 6475 (id_type, id_type.lower(), id_type.lower())) |
| 6476 else: |
| 6477 file.Write(" *result_dst = %s(%s);\n" % |
| 6478 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) |
| 6436 file.Write(" return error::kNoError;\n") | 6479 file.Write(" return error::kNoError;\n") |
| 6437 file.Write("}\n") | 6480 file.Write("}\n") |
| 6438 file.Write("\n") | 6481 file.Write("\n") |
| 6439 | 6482 |
| 6440 def WriteGLES2Implementation(self, func, file): | 6483 def WriteGLES2Implementation(self, func, file): |
| 6441 """Overrriden from TypeHandler.""" | 6484 """Overrriden from TypeHandler.""" |
| 6442 impl_func = func.GetInfo('impl_func') | 6485 impl_func = func.GetInfo('impl_func') |
| 6443 if impl_func == None or impl_func == True: | 6486 if impl_func == None or impl_func == True: |
| 6444 error_value = func.GetInfo("error_value") or "GL_FALSE" | 6487 error_value = func.GetInfo("error_value") or "GL_FALSE" |
| 6445 file.Write("%s GLES2Implementation::%s(%s) {\n" % | 6488 file.Write("%s GLES2Implementation::%s(%s) {\n" % |
| (...skipping 2822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9268 Format(gen.generated_cpp_filenames) | 9311 Format(gen.generated_cpp_filenames) |
| 9269 | 9312 |
| 9270 if gen.errors > 0: | 9313 if gen.errors > 0: |
| 9271 print "%d errors" % gen.errors | 9314 print "%d errors" % gen.errors |
| 9272 return 1 | 9315 return 1 |
| 9273 return 0 | 9316 return 0 |
| 9274 | 9317 |
| 9275 | 9318 |
| 9276 if __name__ == '__main__': | 9319 if __name__ == '__main__': |
| 9277 sys.exit(main(sys.argv[1:])) | 9320 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |