| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 {'name': 'blend'}, | 75 {'name': 'blend'}, |
| 76 {'name': 'cull_face'}, | 76 {'name': 'cull_face'}, |
| 77 {'name': 'depth_test', 'state_flag': 'framebuffer_state_.clear_state_dirty'}, | 77 {'name': 'depth_test', 'state_flag': 'framebuffer_state_.clear_state_dirty'}, |
| 78 {'name': 'dither', 'default': True}, | 78 {'name': 'dither', 'default': True}, |
| 79 {'name': 'polygon_offset_fill'}, | 79 {'name': 'polygon_offset_fill'}, |
| 80 {'name': 'sample_alpha_to_coverage'}, | 80 {'name': 'sample_alpha_to_coverage'}, |
| 81 {'name': 'sample_coverage'}, | 81 {'name': 'sample_coverage'}, |
| 82 {'name': 'scissor_test'}, | 82 {'name': 'scissor_test'}, |
| 83 {'name': 'stencil_test', | 83 {'name': 'stencil_test', |
| 84 'state_flag': 'framebuffer_state_.clear_state_dirty'}, | 84 'state_flag': 'framebuffer_state_.clear_state_dirty'}, |
| 85 {'name': 'rasterizer_discard', 'es3': True}, |
| 85 ] | 86 ] |
| 86 | 87 |
| 87 _STATES = { | 88 _STATES = { |
| 88 'ClearColor': { | 89 'ClearColor': { |
| 89 'type': 'Normal', | 90 'type': 'Normal', |
| 90 'func': 'ClearColor', | 91 'func': 'ClearColor', |
| 91 'enum': 'GL_COLOR_CLEAR_VALUE', | 92 'enum': 'GL_COLOR_CLEAR_VALUE', |
| 92 'states': [ | 93 'states': [ |
| 93 {'name': 'color_clear_red', 'type': 'GLfloat', 'default': '0.0f'}, | 94 {'name': 'color_clear_red', 'type': 'GLfloat', 'default': '0.0f'}, |
| 94 {'name': 'color_clear_green', 'type': 'GLfloat', 'default': '0.0f'}, | 95 {'name': 'color_clear_green', 'type': 'GLfloat', 'default': '0.0f'}, |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 'GL_DST_ALPHA', | 892 'GL_DST_ALPHA', |
| 892 'GL_ONE_MINUS_DST_ALPHA', | 893 'GL_ONE_MINUS_DST_ALPHA', |
| 893 'GL_CONSTANT_COLOR', | 894 'GL_CONSTANT_COLOR', |
| 894 'GL_ONE_MINUS_CONSTANT_COLOR', | 895 'GL_ONE_MINUS_CONSTANT_COLOR', |
| 895 'GL_CONSTANT_ALPHA', | 896 'GL_CONSTANT_ALPHA', |
| 896 'GL_ONE_MINUS_CONSTANT_ALPHA', | 897 'GL_ONE_MINUS_CONSTANT_ALPHA', |
| 897 ], | 898 ], |
| 898 }, | 899 }, |
| 899 'Capability': { | 900 'Capability': { |
| 900 'type': 'GLenum', | 901 'type': 'GLenum', |
| 901 'valid': ["GL_%s" % cap['name'].upper() for cap in _CAPABILITY_FLAGS], | 902 'valid': ["GL_%s" % cap['name'].upper() for cap in _CAPABILITY_FLAGS |
| 903 if 'es3' not in cap or cap['es3'] != True], |
| 904 'valid_es3': ["GL_%s" % cap['name'].upper() for cap in _CAPABILITY_FLAGS |
| 905 if 'es3' in cap and cap['es3'] == True], |
| 902 'invalid': [ | 906 'invalid': [ |
| 903 'GL_CLIP_PLANE0', | 907 'GL_CLIP_PLANE0', |
| 904 'GL_POINT_SPRITE', | 908 'GL_POINT_SPRITE', |
| 905 ], | 909 ], |
| 906 }, | 910 }, |
| 907 'DrawMode': { | 911 'DrawMode': { |
| 908 'type': 'GLenum', | 912 'type': 'GLenum', |
| 909 'valid': [ | 913 'valid': [ |
| 910 'GL_POINTS', | 914 'GL_POINTS', |
| 911 'GL_LINE_STRIP', | 915 'GL_LINE_STRIP', |
| (...skipping 8615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9527 if isinstance(item['default'], list): | 9531 if isinstance(item['default'], list): |
| 9528 for ndx, value in enumerate(item['default']): | 9532 for ndx, value in enumerate(item['default']): |
| 9529 file.Write(" cached_%s[%d] = %s;\n" % (item['name'], ndx, value)) | 9533 file.Write(" cached_%s[%d] = %s;\n" % (item['name'], ndx, value)) |
| 9530 else: | 9534 else: |
| 9531 file.Write(" cached_%s = %s;\n" % (item['name'], item['default'])) | 9535 file.Write(" cached_%s = %s;\n" % (item['name'], item['default'])) |
| 9532 file.Write("}\n") | 9536 file.Write("}\n") |
| 9533 | 9537 |
| 9534 file.Write(""" | 9538 file.Write(""" |
| 9535 void ContextState::InitCapabilities(const ContextState* prev_state) const { | 9539 void ContextState::InitCapabilities(const ContextState* prev_state) const { |
| 9536 """) | 9540 """) |
| 9537 def WriteCapabilities(test_prev): | 9541 def WriteCapabilities(test_prev, es3_caps): |
| 9538 for capability in _CAPABILITY_FLAGS: | 9542 for capability in _CAPABILITY_FLAGS: |
| 9539 capability_name = capability['name'] | 9543 capability_name = capability['name'] |
| 9544 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 9545 if capability_es3 and not es3_caps or not capability_es3 and es3_caps: |
| 9546 continue |
| 9540 if test_prev: | 9547 if test_prev: |
| 9541 file.Write(""" if (prev_state->enable_flags.cached_%s != | 9548 file.Write(""" if (prev_state->enable_flags.cached_%s != |
| 9542 enable_flags.cached_%s)\n""" % | 9549 enable_flags.cached_%s) {\n""" % |
| 9543 (capability_name, capability_name)) | 9550 (capability_name, capability_name)) |
| 9544 file.Write(" EnableDisable(GL_%s, enable_flags.cached_%s);\n" % | 9551 file.Write(" EnableDisable(GL_%s, enable_flags.cached_%s);\n" % |
| 9545 (capability_name.upper(), capability_name)) | 9552 (capability_name.upper(), capability_name)) |
| 9553 if test_prev: |
| 9554 file.Write(" }") |
| 9546 | 9555 |
| 9547 file.Write(" if (prev_state) {") | 9556 file.Write(" if (prev_state) {") |
| 9548 WriteCapabilities(True) | 9557 WriteCapabilities(True, False) |
| 9558 file.Write(" if (feature_info_->IsES3Capable()) {\n") |
| 9559 WriteCapabilities(True, True) |
| 9560 file.Write(" }\n") |
| 9549 file.Write(" } else {") | 9561 file.Write(" } else {") |
| 9550 WriteCapabilities(False) | 9562 WriteCapabilities(False, False) |
| 9563 file.Write(" if (feature_info_->IsES3Capable()) {\n") |
| 9564 WriteCapabilities(False, True) |
| 9565 file.Write(" }\n") |
| 9551 file.Write(" }") | 9566 file.Write(" }") |
| 9552 | 9567 |
| 9553 file.Write("""} | 9568 file.Write("""} |
| 9554 | 9569 |
| 9555 void ContextState::InitState(const ContextState *prev_state) const { | 9570 void ContextState::InitState(const ContextState *prev_state) const { |
| 9556 """) | 9571 """) |
| 9557 | 9572 |
| 9558 def WriteStates(test_prev): | 9573 def WriteStates(test_prev): |
| 9559 # We need to sort the keys so the expectations match | 9574 # We need to sort the keys so the expectations match |
| 9560 for state_name in sorted(_STATES.keys()): | 9575 for state_name in sorted(_STATES.keys()): |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9776 else: | 9791 else: |
| 9777 func.WriteServiceUnitTest(file, { | 9792 func.WriteServiceUnitTest(file, { |
| 9778 'test_name': test_name | 9793 'test_name': test_name |
| 9779 }) | 9794 }) |
| 9780 file.Close() | 9795 file.Close() |
| 9781 self.generated_cpp_filenames.append(file.filename) | 9796 self.generated_cpp_filenames.append(file.filename) |
| 9782 file = CHeaderWriter( | 9797 file = CHeaderWriter( |
| 9783 filename % 0, | 9798 filename % 0, |
| 9784 "// It is included by gles2_cmd_decoder_unittest_base.cc\n") | 9799 "// It is included by gles2_cmd_decoder_unittest_base.cc\n") |
| 9785 file.Write( | 9800 file.Write( |
| 9786 """void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations() { | 9801 """void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations( |
| 9787 """) | 9802 bool es3_capable) {""") |
| 9788 for capability in _CAPABILITY_FLAGS: | 9803 for capability in _CAPABILITY_FLAGS: |
| 9789 file.Write(" ExpectEnableDisable(GL_%s, %s);\n" % | 9804 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 9790 (capability['name'].upper(), | 9805 if not capability_es3: |
| 9791 ('false', 'true')['default' in capability])) | 9806 file.Write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 9792 file.Write("""} | 9807 (capability['name'].upper(), |
| 9808 ('false', 'true')['default' in capability])) |
| 9809 |
| 9810 file.Write(" if (es3_capable) {") |
| 9811 for capability in _CAPABILITY_FLAGS: |
| 9812 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 9813 if capability_es3: |
| 9814 file.Write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 9815 (capability['name'].upper(), |
| 9816 ('false', 'true')['default' in capability])) |
| 9817 file.Write(""" } |
| 9818 } |
| 9793 | 9819 |
| 9794 void GLES2DecoderTestBase::SetupInitStateExpectations() { | 9820 void GLES2DecoderTestBase::SetupInitStateExpectations() { |
| 9795 """) | 9821 """) |
| 9796 | 9822 |
| 9797 # We need to sort the keys so the expectations match | 9823 # We need to sort the keys so the expectations match |
| 9798 for state_name in sorted(_STATES.keys()): | 9824 for state_name in sorted(_STATES.keys()): |
| 9799 state = _STATES[state_name] | 9825 state = _STATES[state_name] |
| 9800 if state['type'] == 'FrontBack': | 9826 if state['type'] == 'FrontBack': |
| 9801 num_states = len(state['states']) | 9827 num_states = len(state['states']) |
| 9802 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): | 9828 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10504 Format(gen.generated_cpp_filenames) | 10530 Format(gen.generated_cpp_filenames) |
| 10505 | 10531 |
| 10506 if gen.errors > 0: | 10532 if gen.errors > 0: |
| 10507 print "%d errors" % gen.errors | 10533 print "%d errors" % gen.errors |
| 10508 return 1 | 10534 return 1 |
| 10509 return 0 | 10535 return 0 |
| 10510 | 10536 |
| 10511 | 10537 |
| 10512 if __name__ == '__main__': | 10538 if __name__ == '__main__': |
| 10513 sys.exit(main(sys.argv[1:])) | 10539 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |