| 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 'name': 'pack_alignment', | 407 'name': 'pack_alignment', |
| 408 'type': 'GLint', | 408 'type': 'GLint', |
| 409 'enum': 'GL_PACK_ALIGNMENT', | 409 'enum': 'GL_PACK_ALIGNMENT', |
| 410 'default': '4' | 410 'default': '4' |
| 411 }, | 411 }, |
| 412 { | 412 { |
| 413 'name': 'unpack_alignment', | 413 'name': 'unpack_alignment', |
| 414 'type': 'GLint', | 414 'type': 'GLint', |
| 415 'enum': 'GL_UNPACK_ALIGNMENT', | 415 'enum': 'GL_UNPACK_ALIGNMENT', |
| 416 'default': '4' | 416 'default': '4' |
| 417 }, |
| 418 { |
| 419 'name': 'pack_row_length', |
| 420 'type': 'GLint', |
| 421 'enum': 'GL_PACK_ROW_LENGTH', |
| 422 'default': '0', |
| 423 'es3': True |
| 424 }, |
| 425 { |
| 426 'name': 'pack_skip_pixels', |
| 427 'type': 'GLint', |
| 428 'enum': 'GL_PACK_SKIP_PIXELS', |
| 429 'default': '0', |
| 430 'es3': True |
| 431 }, |
| 432 { |
| 433 'name': 'pack_skip_rows', |
| 434 'type': 'GLint', |
| 435 'enum': 'GL_PACK_SKIP_ROWS', |
| 436 'default': '0', |
| 437 'es3': True |
| 438 }, |
| 439 { |
| 440 'name': 'unpack_row_length', |
| 441 'type': 'GLint', |
| 442 'enum': 'GL_UNPACK_ROW_LENGTH', |
| 443 'default': '0', |
| 444 'es3': True |
| 445 }, |
| 446 { |
| 447 'name': 'unpack_image_height', |
| 448 'type': 'GLint', |
| 449 'enum': 'GL_UNPACK_IMAGE_HEIGHT', |
| 450 'default': '0', |
| 451 'es3': True |
| 452 }, |
| 453 { |
| 454 'name': 'unpack_skip_pixels', |
| 455 'type': 'GLint', |
| 456 'enum': 'GL_UNPACK_SKIP_PIXELS', |
| 457 'default': '0', |
| 458 'es3': True |
| 459 }, |
| 460 { |
| 461 'name': 'unpack_skip_rows', |
| 462 'type': 'GLint', |
| 463 'enum': 'GL_UNPACK_SKIP_ROWS', |
| 464 'default': '0', |
| 465 'es3': True |
| 466 }, |
| 467 { |
| 468 'name': 'unpack_skip_images', |
| 469 'type': 'GLint', |
| 470 'enum': 'GL_UNPACK_SKIP_IMAGES', |
| 471 'default': '0', |
| 472 'es3': True |
| 417 } | 473 } |
| 418 ], | 474 ], |
| 419 }, | 475 }, |
| 420 # TODO: Consider implemenenting these states | 476 # TODO: Consider implemenenting these states |
| 421 # GL_ACTIVE_TEXTURE | 477 # GL_ACTIVE_TEXTURE |
| 422 'LineWidth': { | 478 'LineWidth': { |
| 423 'type': 'Normal', | 479 'type': 'Normal', |
| 424 'func': 'LineWidth', | 480 'func': 'LineWidth', |
| 425 'enum': 'GL_LINE_WIDTH', | 481 'enum': 'GL_LINE_WIDTH', |
| 426 'states': [ | 482 'states': [ |
| (...skipping 9731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10158 if test_prev: | 10214 if test_prev: |
| 10159 f.write(")\n") | 10215 f.write(")\n") |
| 10160 f.write( | 10216 f.write( |
| 10161 " gl%s(%s, %s);\n" % | 10217 " gl%s(%s, %s);\n" % |
| 10162 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], | 10218 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], |
| 10163 ", ".join(args))) | 10219 ", ".join(args))) |
| 10164 elif state['type'] == 'NamedParameter': | 10220 elif state['type'] == 'NamedParameter': |
| 10165 for item in state['states']: | 10221 for item in state['states']: |
| 10166 item_name = CachedStateName(item) | 10222 item_name = CachedStateName(item) |
| 10167 | 10223 |
| 10224 if 'es3' in item: |
| 10225 assert item['es3'] |
| 10226 f.write(" if (feature_info_->IsES3Capable()) {\n"); |
| 10168 if 'extension_flag' in item: | 10227 if 'extension_flag' in item: |
| 10169 f.write(" if (feature_info_->feature_flags().%s) {\n " % | 10228 f.write(" if (feature_info_->feature_flags().%s) {\n " % |
| 10170 item['extension_flag']) | 10229 item['extension_flag']) |
| 10171 if test_prev: | 10230 if test_prev: |
| 10172 if isinstance(item['default'], list): | 10231 if isinstance(item['default'], list): |
| 10173 f.write(" if (memcmp(prev_state->%s, %s, " | 10232 f.write(" if (memcmp(prev_state->%s, %s, " |
| 10174 "sizeof(%s) * %d)) {\n" % | 10233 "sizeof(%s) * %d)) {\n" % |
| 10175 (item_name, item_name, item['type'], | 10234 (item_name, item_name, item['type'], |
| 10176 len(item['default']))) | 10235 len(item['default']))) |
| 10177 else: | 10236 else: |
| 10178 f.write(" if (prev_state->%s != %s) {\n " % | 10237 f.write(" if (prev_state->%s != %s) {\n " % |
| 10179 (item_name, item_name)) | 10238 (item_name, item_name)) |
| 10180 if 'gl_version_flag' in item: | 10239 if 'gl_version_flag' in item: |
| 10181 item_name = item['gl_version_flag'] | 10240 item_name = item['gl_version_flag'] |
| 10182 inverted = '' | 10241 inverted = '' |
| 10183 if item_name[0] == '!': | 10242 if item_name[0] == '!': |
| 10184 inverted = '!' | 10243 inverted = '!' |
| 10185 item_name = item_name[1:] | 10244 item_name = item_name[1:] |
| 10186 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % | 10245 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % |
| 10187 (inverted, item_name)) | 10246 (inverted, item_name)) |
| 10188 f.write(" gl%s(%s, %s);\n" % | 10247 f.write(" gl%s(%s, %s);\n" % |
| 10189 (state['func'], | 10248 (state['func'], |
| 10190 (item['enum_set'] | 10249 (item['enum_set'] |
| 10191 if 'enum_set' in item else item['enum']), | 10250 if 'enum_set' in item else item['enum']), |
| 10192 item['name'])) | 10251 item['name'])) |
| 10193 if 'gl_version_flag' in item: | 10252 if 'gl_version_flag' in item or 'es3' in item: |
| 10194 f.write(" }\n") | 10253 f.write(" }\n") |
| 10195 if test_prev: | 10254 if test_prev: |
| 10196 if 'extension_flag' in item: | 10255 if 'extension_flag' in item: |
| 10197 f.write(" ") | 10256 f.write(" ") |
| 10198 f.write(" }") | 10257 f.write(" }") |
| 10199 if 'extension_flag' in item: | 10258 if 'extension_flag' in item: |
| 10200 f.write(" }") | 10259 f.write(" }") |
| 10201 else: | 10260 else: |
| 10202 if 'extension_flag' in state: | 10261 if 'extension_flag' in state: |
| 10203 f.write(" if (feature_info_->feature_flags().%s)\n " % | 10262 f.write(" if (feature_info_->feature_flags().%s)\n " % |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10380 f.write(" if (es3_capable) {") | 10439 f.write(" if (es3_capable) {") |
| 10381 for capability in _CAPABILITY_FLAGS: | 10440 for capability in _CAPABILITY_FLAGS: |
| 10382 capability_es3 = 'es3' in capability and capability['es3'] == True | 10441 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 10383 if capability_es3: | 10442 if capability_es3: |
| 10384 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % | 10443 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 10385 (capability['name'].upper(), | 10444 (capability['name'].upper(), |
| 10386 ('false', 'true')['default' in capability])) | 10445 ('false', 'true')['default' in capability])) |
| 10387 f.write(""" } | 10446 f.write(""" } |
| 10388 } | 10447 } |
| 10389 | 10448 |
| 10390 void GLES2DecoderTestBase::SetupInitStateExpectations() { | 10449 void GLES2DecoderTestBase::SetupInitStateExpectations(bool es3_capable) { |
| 10391 """) | 10450 """) |
| 10392 # We need to sort the keys so the expectations match | 10451 # We need to sort the keys so the expectations match |
| 10393 for state_name in sorted(_STATES.keys()): | 10452 for state_name in sorted(_STATES.keys()): |
| 10394 state = _STATES[state_name] | 10453 state = _STATES[state_name] |
| 10395 if state['type'] == 'FrontBack': | 10454 if state['type'] == 'FrontBack': |
| 10396 num_states = len(state['states']) | 10455 num_states = len(state['states']) |
| 10397 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): | 10456 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): |
| 10398 args = [] | 10457 args = [] |
| 10399 for item in group: | 10458 for item in group: |
| 10400 if 'expected' in item: | 10459 if 'expected' in item: |
| 10401 args.append(item['expected']) | 10460 args.append(item['expected']) |
| 10402 else: | 10461 else: |
| 10403 args.append(item['default']) | 10462 args.append(item['default']) |
| 10404 f.write( | 10463 f.write( |
| 10405 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10464 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10406 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) | 10465 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) |
| 10407 f.write(" .Times(1)\n") | 10466 f.write(" .Times(1)\n") |
| 10408 f.write(" .RetiresOnSaturation();\n") | 10467 f.write(" .RetiresOnSaturation();\n") |
| 10409 elif state['type'] == 'NamedParameter': | 10468 elif state['type'] == 'NamedParameter': |
| 10410 for item in state['states']: | 10469 for item in state['states']: |
| 10411 if 'extension_flag' in item: | 10470 if 'extension_flag' in item: |
| 10412 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | 10471 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10413 item['extension_flag']) | 10472 item['extension_flag']) |
| 10414 f.write(" ") | 10473 f.write(" ") |
| 10474 if 'es3' in item: |
| 10475 assert item['es3'] |
| 10476 f.write(" if (es3_capable) {\n") |
| 10477 f.write(" ") |
| 10415 expect_value = item['default'] | 10478 expect_value = item['default'] |
| 10416 if isinstance(expect_value, list): | 10479 if isinstance(expect_value, list): |
| 10417 # TODO: Currently we do not check array values. | 10480 # TODO: Currently we do not check array values. |
| 10418 expect_value = "_" | 10481 expect_value = "_" |
| 10419 | 10482 |
| 10420 f.write( | 10483 f.write( |
| 10421 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10484 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10422 (state['func'], | 10485 (state['func'], |
| 10423 (item['enum_set'] | 10486 (item['enum_set'] |
| 10424 if 'enum_set' in item else item['enum']), | 10487 if 'enum_set' in item else item['enum']), |
| 10425 expect_value)) | 10488 expect_value)) |
| 10426 f.write(" .Times(1)\n") | 10489 f.write(" .Times(1)\n") |
| 10427 f.write(" .RetiresOnSaturation();\n") | 10490 f.write(" .RetiresOnSaturation();\n") |
| 10428 if 'extension_flag' in item: | 10491 if 'extension_flag' in item or 'es3' in item: |
| 10429 f.write(" }\n") | 10492 f.write(" }\n") |
| 10430 else: | 10493 else: |
| 10431 if 'extension_flag' in state: | 10494 if 'extension_flag' in state: |
| 10432 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | 10495 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10433 state['extension_flag']) | 10496 state['extension_flag']) |
| 10434 f.write(" ") | 10497 f.write(" ") |
| 10435 args = [] | 10498 args = [] |
| 10436 for item in state['states']: | 10499 for item in state['states']: |
| 10437 if 'expected' in item: | 10500 if 'expected' in item: |
| 10438 args.append(item['expected']) | 10501 args.append(item['expected']) |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10753 | 10816 |
| 10754 """) | 10817 """) |
| 10755 | 10818 |
| 10756 enums = sorted(_NAMED_TYPE_INFO.keys()) | 10819 enums = sorted(_NAMED_TYPE_INFO.keys()) |
| 10757 for enum in enums: | 10820 for enum in enums: |
| 10758 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': | 10821 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': |
| 10759 f.write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % | 10822 f.write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % |
| 10760 enum) | 10823 enum) |
| 10761 valid_list = _NAMED_TYPE_INFO[enum]['valid'] | 10824 valid_list = _NAMED_TYPE_INFO[enum]['valid'] |
| 10762 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: | 10825 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: |
| 10763 valid_list = valid_list + _NAMED_TYPE_INFO[enum]['valid_es3'] | 10826 for es3_enum in _NAMED_TYPE_INFO[enum]['valid_es3']: |
| 10827 if not es3_enum in valid_list: |
| 10828 valid_list.append(es3_enum) |
| 10764 assert len(valid_list) == len(set(valid_list)) | 10829 assert len(valid_list) == len(set(valid_list)) |
| 10765 if len(valid_list) > 0: | 10830 if len(valid_list) > 0: |
| 10766 f.write(" static const EnumToString string_table[] = {\n") | 10831 f.write(" static const EnumToString string_table[] = {\n") |
| 10767 for value in valid_list: | 10832 for value in valid_list: |
| 10768 f.write(' { %s, "%s" },\n' % (value, value)) | 10833 f.write(' { %s, "%s" },\n' % (value, value)) |
| 10769 f.write(""" }; | 10834 f.write(""" }; |
| 10770 return GLES2Util::GetQualifiedEnumString( | 10835 return GLES2Util::GetQualifiedEnumString( |
| 10771 string_table, arraysize(string_table), value); | 10836 string_table, arraysize(string_table), value); |
| 10772 } | 10837 } |
| 10773 | 10838 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10994 help="base directory for resulting files, under chrome/src. default is " | 11059 help="base directory for resulting files, under chrome/src. default is " |
| 10995 "empty. Use this if you want the result stored under gen.") | 11060 "empty. Use this if you want the result stored under gen.") |
| 10996 parser.add_option( | 11061 parser.add_option( |
| 10997 "-v", "--verbose", action="store_true", | 11062 "-v", "--verbose", action="store_true", |
| 10998 help="prints more output.") | 11063 help="prints more output.") |
| 10999 | 11064 |
| 11000 (options, args) = parser.parse_args(args=argv) | 11065 (options, args) = parser.parse_args(args=argv) |
| 11001 | 11066 |
| 11002 # Add in states and capabilites to GLState | 11067 # Add in states and capabilites to GLState |
| 11003 gl_state_valid = _NAMED_TYPE_INFO['GLState']['valid'] | 11068 gl_state_valid = _NAMED_TYPE_INFO['GLState']['valid'] |
| 11069 gl_state_valid_es3 = _NAMED_TYPE_INFO['GLState']['valid_es3'] |
| 11004 for state_name in sorted(_STATES.keys()): | 11070 for state_name in sorted(_STATES.keys()): |
| 11005 state = _STATES[state_name] | 11071 state = _STATES[state_name] |
| 11006 if 'extension_flag' in state: | 11072 if 'extension_flag' in state: |
| 11007 continue | 11073 continue |
| 11008 if 'enum' in state: | 11074 if 'enum' in state: |
| 11009 if not state['enum'] in gl_state_valid: | 11075 if not state['enum'] in gl_state_valid: |
| 11010 gl_state_valid.append(state['enum']) | 11076 gl_state_valid.append(state['enum']) |
| 11011 else: | 11077 else: |
| 11012 for item in state['states']: | 11078 for item in state['states']: |
| 11013 if 'extension_flag' in item: | 11079 if 'extension_flag' in item: |
| 11014 continue | 11080 continue |
| 11015 if not item['enum'] in gl_state_valid: | 11081 if 'es3' in item: |
| 11016 gl_state_valid.append(item['enum']) | 11082 assert item['es3'] |
| 11083 if not item['enum'] in gl_state_valid_es3: |
| 11084 gl_state_valid_es3.append(item['enum']) |
| 11085 else: |
| 11086 if not item['enum'] in gl_state_valid: |
| 11087 gl_state_valid.append(item['enum']) |
| 11017 for capability in _CAPABILITY_FLAGS: | 11088 for capability in _CAPABILITY_FLAGS: |
| 11018 valid_value = "GL_%s" % capability['name'].upper() | 11089 valid_value = "GL_%s" % capability['name'].upper() |
| 11019 if not valid_value in gl_state_valid: | 11090 if not valid_value in gl_state_valid: |
| 11020 gl_state_valid.append(valid_value) | 11091 gl_state_valid.append(valid_value) |
| 11021 | 11092 |
| 11022 # This script lives under gpu/command_buffer, cd to base directory. | 11093 # This script lives under gpu/command_buffer, cd to base directory. |
| 11023 os.chdir(os.path.dirname(__file__) + "/../..") | 11094 os.chdir(os.path.dirname(__file__) + "/../..") |
| 11024 base_dir = os.getcwd() | 11095 base_dir = os.getcwd() |
| 11025 gen = GLGenerator(options.verbose) | 11096 gen = GLGenerator(options.verbose) |
| 11026 gen.ParseGLH("gpu/command_buffer/cmd_buffer_functions.txt") | 11097 gen.ParseGLH("gpu/command_buffer/cmd_buffer_functions.txt") |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11096 Format(gen.generated_cpp_filenames) | 11167 Format(gen.generated_cpp_filenames) |
| 11097 | 11168 |
| 11098 if gen.errors > 0: | 11169 if gen.errors > 0: |
| 11099 print "%d errors" % gen.errors | 11170 print "%d errors" % gen.errors |
| 11100 return 1 | 11171 return 1 |
| 11101 return 0 | 11172 return 0 |
| 11102 | 11173 |
| 11103 | 11174 |
| 11104 if __name__ == '__main__': | 11175 if __name__ == '__main__': |
| 11105 sys.exit(main(sys.argv[1:])) | 11176 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |