| 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 4592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4603 def ToUnderscore(input_string): | 4603 def ToUnderscore(input_string): |
| 4604 """converts CamelCase to camel_case.""" | 4604 """converts CamelCase to camel_case.""" |
| 4605 words = SplitWords(input_string) | 4605 words = SplitWords(input_string) |
| 4606 return '_'.join([word.lower() for word in words]) | 4606 return '_'.join([word.lower() for word in words]) |
| 4607 | 4607 |
| 4608 def CachedStateName(item): | 4608 def CachedStateName(item): |
| 4609 if item.get('cached', False): | 4609 if item.get('cached', False): |
| 4610 return 'cached_' + item['name'] | 4610 return 'cached_' + item['name'] |
| 4611 return item['name'] | 4611 return item['name'] |
| 4612 | 4612 |
| 4613 def GuardState(state, operation): |
| 4614 if 'manual' in state: |
| 4615 assert state['manual'] |
| 4616 return "" |
| 4617 |
| 4618 result = [] |
| 4619 result_end = [] |
| 4620 if 'es3' in state: |
| 4621 assert state['es3'] |
| 4622 result.append(" if (feature_info_->IsES3Capable()) {\n"); |
| 4623 result_end.append(" }\n") |
| 4624 if 'extension_flag' in state: |
| 4625 result.append(" if (feature_info_->feature_flags().%s) {\n " % |
| 4626 (state['extension_flag'])) |
| 4627 result_end.append(" }\n") |
| 4628 if 'gl_version_flag' in state: |
| 4629 name = state['gl_version_flag'] |
| 4630 inverted = '' |
| 4631 if name[0] == '!': |
| 4632 inverted = '!' |
| 4633 name = name[1:] |
| 4634 result.append(" if (%sfeature_info_->gl_version_info().%s) {\n" % |
| 4635 (inverted, name)) |
| 4636 result_end.append(" }\n") |
| 4637 |
| 4638 result.append(operation) |
| 4639 return ''.join(result + result_end) |
| 4640 |
| 4613 def ToGLExtensionString(extension_flag): | 4641 def ToGLExtensionString(extension_flag): |
| 4614 """Returns GL-type extension string of a extension flag.""" | 4642 """Returns GL-type extension string of a extension flag.""" |
| 4615 if extension_flag == "oes_compressed_etc1_rgb8_texture": | 4643 if extension_flag == "oes_compressed_etc1_rgb8_texture": |
| 4616 return "OES_compressed_ETC1_RGB8_texture" # Fixup inconsitency with rgb8, | 4644 return "OES_compressed_ETC1_RGB8_texture" # Fixup inconsitency with rgb8, |
| 4617 # unfortunate. | 4645 # unfortunate. |
| 4618 uppercase_words = [ 'img', 'ext', 'arb', 'chromium', 'oes', 'amd', 'bgra8888', | 4646 uppercase_words = [ 'img', 'ext', 'arb', 'chromium', 'oes', 'amd', 'bgra8888', |
| 4619 'egl', 'atc', 'etc1', 'angle'] | 4647 'egl', 'atc', 'etc1', 'angle'] |
| 4620 parts = extension_flag.split('_') | 4648 parts = extension_flag.split('_') |
| 4621 return "_".join( | 4649 return "_".join( |
| 4622 [part.upper() if part in uppercase_words else part for part in parts]) | 4650 [part.upper() if part in uppercase_words else part for part in parts]) |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5605 args = func.GetOriginalArgs() | 5633 args = func.GetOriginalArgs() |
| 5606 num_args = len(args) | 5634 num_args = len(args) |
| 5607 assert num_args == 2 | 5635 assert num_args == 2 |
| 5608 f.write(" switch (%s) {\n" % args[0].name) | 5636 f.write(" switch (%s) {\n" % args[0].name) |
| 5609 for state in states: | 5637 for state in states: |
| 5610 f.write(" case %s:\n" % state['enum']) | 5638 f.write(" case %s:\n" % state['enum']) |
| 5611 f.write(" if (state_.%s != %s) {\n" % | 5639 f.write(" if (state_.%s != %s) {\n" % |
| 5612 (state['name'], args[1].name)) | 5640 (state['name'], args[1].name)) |
| 5613 f.write(" state_.%s = %s;\n" % (state['name'], args[1].name)) | 5641 f.write(" state_.%s = %s;\n" % (state['name'], args[1].name)) |
| 5614 if not func.GetInfo("no_gl"): | 5642 if not func.GetInfo("no_gl"): |
| 5615 f.write(" %s(%s);\n" % | 5643 operation = " %s(%s);\n" % \ |
| 5616 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 5644 (func.GetGLFunctionName(), func.MakeOriginalArgString("")) |
| 5645 f.write(GuardState(state, operation)) |
| 5617 f.write(" }\n") | 5646 f.write(" }\n") |
| 5618 f.write(" break;\n") | 5647 f.write(" break;\n") |
| 5619 f.write(" default:\n") | 5648 f.write(" default:\n") |
| 5620 f.write(" NOTREACHED();\n") | 5649 f.write(" NOTREACHED();\n") |
| 5621 f.write(" }\n") | 5650 f.write(" }\n") |
| 5622 | 5651 |
| 5623 | 5652 |
| 5624 class CustomHandler(TypeHandler): | 5653 class CustomHandler(TypeHandler): |
| 5625 """Handler for commands that are auto-generated but require minor tweaks.""" | 5654 """Handler for commands that are auto-generated but require minor tweaks.""" |
| 5626 | 5655 |
| (...skipping 4780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10407 if test_prev: | 10436 if test_prev: |
| 10408 f.write(")\n") | 10437 f.write(")\n") |
| 10409 f.write( | 10438 f.write( |
| 10410 " gl%s(%s, %s);\n" % | 10439 " gl%s(%s, %s);\n" % |
| 10411 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], | 10440 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], |
| 10412 ", ".join(args))) | 10441 ", ".join(args))) |
| 10413 elif state['type'] == 'NamedParameter': | 10442 elif state['type'] == 'NamedParameter': |
| 10414 for item in state['states']: | 10443 for item in state['states']: |
| 10415 item_name = CachedStateName(item) | 10444 item_name = CachedStateName(item) |
| 10416 | 10445 |
| 10417 if 'manual' in item: | 10446 operation = [] |
| 10418 assert item['manual'] | |
| 10419 continue | |
| 10420 if 'es3' in item: | |
| 10421 assert item['es3'] | |
| 10422 f.write(" if (feature_info_->IsES3Capable()) {\n"); | |
| 10423 if 'extension_flag' in item: | |
| 10424 f.write(" if (feature_info_->feature_flags().%s) {\n " % | |
| 10425 item['extension_flag']) | |
| 10426 if test_prev: | 10447 if test_prev: |
| 10427 if isinstance(item['default'], list): | 10448 if isinstance(item['default'], list): |
| 10428 f.write(" if (memcmp(prev_state->%s, %s, " | 10449 operation.append(" if (memcmp(prev_state->%s, %s, " |
| 10429 "sizeof(%s) * %d)) {\n" % | 10450 "sizeof(%s) * %d)) {\n" % |
| 10430 (item_name, item_name, item['type'], | 10451 (item_name, item_name, item['type'], |
| 10431 len(item['default']))) | 10452 len(item['default']))) |
| 10432 else: | 10453 else: |
| 10433 f.write(" if (prev_state->%s != %s) {\n " % | 10454 operation.append(" if (prev_state->%s != %s) {\n " % |
| 10434 (item_name, item_name)) | 10455 (item_name, item_name)) |
| 10435 if 'gl_version_flag' in item: | 10456 |
| 10436 item_name = item['gl_version_flag'] | 10457 operation.append(" gl%s(%s, %s);\n" % |
| 10437 inverted = '' | 10458 (state['func'], |
| 10438 if item_name[0] == '!': | 10459 (item['enum_set'] |
| 10439 inverted = '!' | 10460 if 'enum_set' in item else item['enum']), |
| 10440 item_name = item_name[1:] | 10461 item['name'])) |
| 10441 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % | 10462 |
| 10442 (inverted, item_name)) | |
| 10443 f.write(" gl%s(%s, %s);\n" % | |
| 10444 (state['func'], | |
| 10445 (item['enum_set'] | |
| 10446 if 'enum_set' in item else item['enum']), | |
| 10447 item['name'])) | |
| 10448 if 'gl_version_flag' in item or 'es3' in item: | |
| 10449 f.write(" }\n") | |
| 10450 if test_prev: | 10463 if test_prev: |
| 10451 if 'extension_flag' in item: | 10464 operation.append(" }") |
| 10452 f.write(" ") | 10465 |
| 10453 f.write(" }") | 10466 guarded_operation = GuardState(item, ''.join(operation)) |
| 10454 if 'extension_flag' in item: | 10467 f.write(guarded_operation) |
| 10455 f.write(" }") | |
| 10456 else: | 10468 else: |
| 10457 if 'extension_flag' in state: | 10469 if 'extension_flag' in state: |
| 10458 f.write(" if (feature_info_->feature_flags().%s)\n " % | 10470 f.write(" if (feature_info_->feature_flags().%s)\n " % |
| 10459 state['extension_flag']) | 10471 state['extension_flag']) |
| 10460 if test_prev: | 10472 if test_prev: |
| 10461 f.write(" if (") | 10473 f.write(" if (") |
| 10462 args = [] | 10474 args = [] |
| 10463 for place, item in enumerate(state['states']): | 10475 for place, item in enumerate(state['states']): |
| 10464 item_name = CachedStateName(item) | 10476 item_name = CachedStateName(item) |
| 10465 args.append('%s' % item_name) | 10477 args.append('%s' % item_name) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10649 for capability in _CAPABILITY_FLAGS: | 10661 for capability in _CAPABILITY_FLAGS: |
| 10650 capability_es3 = 'es3' in capability and capability['es3'] == True | 10662 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 10651 if capability_es3: | 10663 if capability_es3: |
| 10652 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % | 10664 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 10653 (capability['name'].upper(), | 10665 (capability['name'].upper(), |
| 10654 ('false', 'true')['default' in capability])) | 10666 ('false', 'true')['default' in capability])) |
| 10655 f.write(""" } | 10667 f.write(""" } |
| 10656 } | 10668 } |
| 10657 | 10669 |
| 10658 void GLES2DecoderTestBase::SetupInitStateExpectations(bool es3_capable) { | 10670 void GLES2DecoderTestBase::SetupInitStateExpectations(bool es3_capable) { |
| 10671 const auto& feature_info_ = group_->feature_info(); |
| 10659 """) | 10672 """) |
| 10660 # We need to sort the keys so the expectations match | 10673 # We need to sort the keys so the expectations match |
| 10661 for state_name in sorted(_STATES.keys()): | 10674 for state_name in sorted(_STATES.keys()): |
| 10662 state = _STATES[state_name] | 10675 state = _STATES[state_name] |
| 10663 if state['type'] == 'FrontBack': | 10676 if state['type'] == 'FrontBack': |
| 10664 num_states = len(state['states']) | 10677 num_states = len(state['states']) |
| 10665 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): | 10678 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): |
| 10666 args = [] | 10679 args = [] |
| 10667 for item in group: | 10680 for item in group: |
| 10668 if 'expected' in item: | 10681 if 'expected' in item: |
| 10669 args.append(item['expected']) | 10682 args.append(item['expected']) |
| 10670 else: | 10683 else: |
| 10671 args.append(item['default']) | 10684 args.append(item['default']) |
| 10672 f.write( | 10685 f.write( |
| 10673 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10686 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10674 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) | 10687 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) |
| 10675 f.write(" .Times(1)\n") | 10688 f.write(" .Times(1)\n") |
| 10676 f.write(" .RetiresOnSaturation();\n") | 10689 f.write(" .RetiresOnSaturation();\n") |
| 10677 elif state['type'] == 'NamedParameter': | 10690 elif state['type'] == 'NamedParameter': |
| 10678 for item in state['states']: | 10691 for item in state['states']: |
| 10679 if 'manual' in item: | |
| 10680 assert item['manual'] | |
| 10681 continue | |
| 10682 if 'extension_flag' in item: | |
| 10683 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | |
| 10684 item['extension_flag']) | |
| 10685 f.write(" ") | |
| 10686 if 'es3' in item: | |
| 10687 assert item['es3'] | |
| 10688 f.write(" if (es3_capable) {\n") | |
| 10689 f.write(" ") | |
| 10690 expect_value = item['default'] | 10692 expect_value = item['default'] |
| 10691 if isinstance(expect_value, list): | 10693 if isinstance(expect_value, list): |
| 10692 # TODO: Currently we do not check array values. | 10694 # TODO: Currently we do not check array values. |
| 10693 expect_value = "_" | 10695 expect_value = "_" |
| 10694 | 10696 |
| 10695 f.write( | 10697 operation = [] |
| 10696 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10698 operation.append( |
| 10697 (state['func'], | 10699 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10698 (item['enum_set'] | 10700 (state['func'], |
| 10699 if 'enum_set' in item else item['enum']), | 10701 (item['enum_set'] |
| 10700 expect_value)) | 10702 if 'enum_set' in item else item['enum']), |
| 10701 f.write(" .Times(1)\n") | 10703 expect_value)) |
| 10702 f.write(" .RetiresOnSaturation();\n") | 10704 operation.append(" .Times(1)\n") |
| 10703 if 'extension_flag' in item or 'es3' in item: | 10705 operation.append(" .RetiresOnSaturation();\n") |
| 10704 f.write(" }\n") | 10706 |
| 10707 guarded_operation = GuardState(item, ''.join(operation)) |
| 10708 f.write(guarded_operation) |
| 10705 else: | 10709 else: |
| 10706 if 'extension_flag' in state: | 10710 if 'extension_flag' in state: |
| 10707 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | 10711 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10708 state['extension_flag']) | 10712 state['extension_flag']) |
| 10709 f.write(" ") | 10713 f.write(" ") |
| 10710 args = [] | 10714 args = [] |
| 10711 for item in state['states']: | 10715 for item in state['states']: |
| 10712 if 'expected' in item: | 10716 if 'expected' in item: |
| 10713 args.append(item['expected']) | 10717 args.append(item['expected']) |
| 10714 else: | 10718 else: |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11432 Format(gen.generated_cpp_filenames) | 11436 Format(gen.generated_cpp_filenames) |
| 11433 | 11437 |
| 11434 if gen.errors > 0: | 11438 if gen.errors > 0: |
| 11435 print "%d errors" % gen.errors | 11439 print "%d errors" % gen.errors |
| 11436 return 1 | 11440 return 1 |
| 11437 return 0 | 11441 return 0 |
| 11438 | 11442 |
| 11439 | 11443 |
| 11440 if __name__ == '__main__': | 11444 if __name__ == '__main__': |
| 11441 sys.exit(main(sys.argv[1:])) | 11445 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |