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 2683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2694 }, | 2694 }, |
| 2695 'GetIntegeri_v': { | 2695 'GetIntegeri_v': { |
| 2696 'type': 'GETn', | 2696 'type': 'GETn', |
| 2697 'result': ['SizedResult<GLint>'], | 2697 'result': ['SizedResult<GLint>'], |
| 2698 'client_test': False, | 2698 'client_test': False, |
| 2699 'unsafe': True | 2699 'unsafe': True |
| 2700 }, | 2700 }, |
| 2701 'GetInternalformativ': { | 2701 'GetInternalformativ': { |
| 2702 'type': 'GETn', | 2702 'type': 'GETn', |
| 2703 'result': ['SizedResult<GLint>'], | 2703 'result': ['SizedResult<GLint>'], |
| 2704 'unit_test': False, | |
| 2704 'unsafe': True, | 2705 'unsafe': True, |
| 2705 }, | 2706 }, |
| 2706 'GetMaxValueInBufferCHROMIUM': { | 2707 'GetMaxValueInBufferCHROMIUM': { |
| 2707 'type': 'Is', | 2708 'type': 'Is', |
| 2708 'decoder_func': 'DoGetMaxValueInBufferCHROMIUM', | 2709 'decoder_func': 'DoGetMaxValueInBufferCHROMIUM', |
| 2709 'result': ['GLuint'], | 2710 'result': ['GLuint'], |
| 2710 'unit_test': False, | 2711 'unit_test': False, |
| 2711 'client_test': False, | 2712 'client_test': False, |
| 2712 'extension': True, | 2713 'extension': True, |
| 2713 'chromium': True, | 2714 'chromium': True, |
| (...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6283 class GETnHandler(TypeHandler): | 6284 class GETnHandler(TypeHandler): |
| 6284 """Handler for GETn for glGetBooleanv, glGetFloatv, ... type functions.""" | 6285 """Handler for GETn for glGetBooleanv, glGetFloatv, ... type functions.""" |
| 6285 | 6286 |
| 6286 def __init__(self): | 6287 def __init__(self): |
| 6287 TypeHandler.__init__(self) | 6288 TypeHandler.__init__(self) |
| 6288 | 6289 |
| 6289 def NeedsDataTransferFunction(self, func): | 6290 def NeedsDataTransferFunction(self, func): |
| 6290 """Overriden from TypeHandler.""" | 6291 """Overriden from TypeHandler.""" |
| 6291 return False | 6292 return False |
| 6292 | 6293 |
| 6294 def __GetCountLimitValidation(self, func): | |
| 6295 if func.name == 'GetInternalformativ': | |
| 6296 return """ | |
| 6297 if (%(count_param)s > 0) { | |
| 6298 // Sanity check for |bufSize| and set its upbound. | |
| 6299 GLint value = 0; | |
| 6300 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("%(func_name)s"); | |
| 6301 glGetInternalformativ( | |
| 6302 target, format, GL_NUM_SAMPLE_COUNTS, 1, &value); | |
| 6303 GLenum error = LOCAL_PEEK_GL_ERROR("%(func_name)s"); | |
| 6304 if (error != GL_NO_ERROR) { | |
| 6305 return error::kNoError; | |
| 6306 } | |
| 6307 if (value < %(count_param)s) { | |
| 6308 %(count_param)s = value; | |
| 6309 } | |
| 6310 } | |
| 6311 """ | |
|
piman
2015/06/01 21:29:36
I don't think this should belong to the generator.
| |
| 6312 return None | |
| 6313 | |
| 6314 def __GetCountParam(self, func): | |
| 6315 for arg in func.GetCmdArgs(): | |
| 6316 if arg.name == 'bufSize': | |
| 6317 return arg.name | |
| 6318 return None | |
| 6319 | |
| 6293 def WriteServiceImplementation(self, func, file): | 6320 def WriteServiceImplementation(self, func, file): |
| 6294 """Overrriden from TypeHandler.""" | 6321 """Overrriden from TypeHandler.""" |
| 6295 self.WriteServiceHandlerFunctionHeader(func, file) | 6322 self.WriteServiceHandlerFunctionHeader(func, file) |
| 6296 last_arg = func.GetLastOriginalArg() | 6323 last_arg = func.GetLastOriginalArg() |
| 6297 # All except shm_id and shm_offset. | 6324 # All except shm_id and shm_offset. |
| 6298 all_but_last_args = func.GetCmdArgs()[:-2] | 6325 all_but_last_args = func.GetCmdArgs()[:-2] |
| 6299 for arg in all_but_last_args: | 6326 for arg in all_but_last_args: |
| 6300 arg.WriteGetCode(file) | 6327 arg.WriteGetCode(file) |
| 6301 | 6328 |
| 6302 code = """ typedef cmds::%(func_name)s::Result Result; | 6329 code = """ typedef cmds::%(func_name)s::Result Result; |
| 6303 GLsizei num_values = 0; | 6330 GLsizei num_values = 0;""" |
| 6304 GetNumValuesReturnedForGLGet(pname, &num_values); | 6331 count_param = self.__GetCountParam(func) |
| 6332 if count_param: | |
| 6333 count_param_validation = self.__GetCountLimitValidation(func) | |
| 6334 if count_param_validation: | |
| 6335 code += count_param_validation | |
| 6336 code += """ | |
| 6337 if (%(count_param)s > 0) { | |
| 6338 num_values = static_cast<GLsizei>(%(count_param)s); | |
| 6339 }""" | |
| 6340 else: | |
| 6341 code += """ | |
| 6342 GetNumValuesReturnedForGLGet(pname, &num_values);""" | |
| 6343 code += """ | |
| 6305 Result* result = GetSharedMemoryAs<Result*>( | 6344 Result* result = GetSharedMemoryAs<Result*>( |
| 6306 c.%(last_arg_name)s_shm_id, c.%(last_arg_name)s_shm_offset, | 6345 c.%(last_arg_name)s_shm_id, c.%(last_arg_name)s_shm_offset, |
| 6307 Result::ComputeSize(num_values)); | 6346 Result::ComputeSize(num_values)); |
| 6308 %(last_arg_type)s %(last_arg_name)s = result ? result->GetData() : NULL; | 6347 %(last_arg_type)s %(last_arg_name)s = result ? result->GetData() : NULL; |
| 6309 """ | 6348 """ |
| 6310 file.Write(code % { | 6349 file.Write(code % { |
| 6311 'last_arg_type': last_arg.type, | 6350 'last_arg_type': last_arg.type, |
| 6312 'last_arg_name': last_arg.name, | 6351 'last_arg_name': last_arg.name, |
| 6313 'func_name': func.name, | 6352 'func_name': func.name, |
| 6353 'count_param': count_param, | |
| 6314 }) | 6354 }) |
| 6315 func.WriteHandlerValidation(file) | 6355 func.WriteHandlerValidation(file) |
| 6316 code = """ // Check that the client initialized the result. | 6356 code = """ // Check that the client initialized the result. |
| 6317 if (result->size != 0) { | 6357 if (result->size != 0) { |
| 6318 return error::kInvalidArguments; | 6358 return error::kInvalidArguments; |
| 6319 } | 6359 } |
| 6320 """ | 6360 """ |
| 6321 shadowed = func.GetInfo('shadowed') | 6361 shadowed = func.GetInfo('shadowed') |
| 6322 if not shadowed: | 6362 if not shadowed: |
| 6323 file.Write(' LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("%s");\n' % func.name) | 6363 file.Write(' LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("%s");\n' % func.name) |
| 6324 file.Write(code) | 6364 file.Write(code) |
| 6325 func.WriteHandlerImplementation(file) | 6365 func.WriteHandlerImplementation(file) |
| 6326 if shadowed: | 6366 if shadowed: |
| 6327 code = """ result->SetNumResults(num_values); | 6367 code = """ result->SetNumResults(num_values); |
| 6328 return error::kNoError; | 6368 return error::kNoError; |
| 6329 } | 6369 } |
| 6330 """ | 6370 """ |
| 6331 else: | 6371 else: |
| 6332 code = """ GLenum error = glGetError(); | 6372 code = """ GLenum error = LOCAL_PEEK_GL_ERROR("%(func_name)s"); |
| 6333 if (error == GL_NO_ERROR) { | 6373 if (error == GL_NO_ERROR) { |
| 6334 result->SetNumResults(num_values); | 6374 result->SetNumResults(num_values); |
| 6335 } else { | |
| 6336 LOCAL_SET_GL_ERROR(error, "%(func_name)s", ""); | |
| 6337 } | 6375 } |
| 6338 return error::kNoError; | 6376 return error::kNoError; |
| 6339 } | 6377 } |
| 6340 | 6378 |
| 6341 """ | 6379 """ |
| 6342 file.Write(code % {'func_name': func.name}) | 6380 file.Write(code % {'func_name': func.name}) |
| 6343 | 6381 |
| 6344 def WriteGLES2Implementation(self, func, file): | 6382 def WriteGLES2Implementation(self, func, file): |
| 6345 """Overrriden from TypeHandler.""" | 6383 """Overrriden from TypeHandler.""" |
| 6346 impl_decl = func.GetInfo('impl_decl') | 6384 impl_decl = func.GetInfo('impl_decl') |
| (...skipping 4677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11024 Format(gen.generated_cpp_filenames) | 11062 Format(gen.generated_cpp_filenames) |
| 11025 | 11063 |
| 11026 if gen.errors > 0: | 11064 if gen.errors > 0: |
| 11027 print "%d errors" % gen.errors | 11065 print "%d errors" % gen.errors |
| 11028 return 1 | 11066 return 1 |
| 11029 return 0 | 11067 return 0 |
| 11030 | 11068 |
| 11031 | 11069 |
| 11032 if __name__ == '__main__': | 11070 if __name__ == '__main__': |
| 11033 sys.exit(main(sys.argv[1:])) | 11071 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |