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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 _GL_TYPES_64 = { | 68 _GL_TYPES_64 = { |
69 'GLintptr': 'long long int', | 69 'GLintptr': 'long long int', |
70 'GLsizeiptr': 'long long int' | 70 'GLsizeiptr': 'long long int' |
71 } | 71 } |
72 | 72 |
73 # Capabilites selected with glEnable | 73 # Capabilites selected with glEnable |
74 _CAPABILITY_FLAGS = [ | 74 _CAPABILITY_FLAGS = [ |
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', |
| 78 'state_flag': 'framebuffer_state_' |
| 79 '.set_draw_framebuffer_clear_state_dirty(true)'}, |
78 {'name': 'dither', 'default': True}, | 80 {'name': 'dither', 'default': True}, |
79 {'name': 'polygon_offset_fill'}, | 81 {'name': 'polygon_offset_fill'}, |
80 {'name': 'sample_alpha_to_coverage'}, | 82 {'name': 'sample_alpha_to_coverage'}, |
81 {'name': 'sample_coverage'}, | 83 {'name': 'sample_coverage'}, |
82 {'name': 'scissor_test'}, | 84 {'name': 'scissor_test'}, |
83 {'name': 'stencil_test', | 85 {'name': 'stencil_test', |
84 'state_flag': 'framebuffer_state_.clear_state_dirty'}, | 86 'state_flag': 'framebuffer_state_' |
| 87 '.set_draw_framebuffer_clear_state_dirty(true)'}, |
85 {'name': 'rasterizer_discard', 'es3': True}, | 88 {'name': 'rasterizer_discard', 'es3': True}, |
86 {'name': 'primitive_restart_fixed_index', 'es3': True}, | 89 {'name': 'primitive_restart_fixed_index', 'es3': True}, |
87 {'name': 'multisample_ext', 'default': True, | 90 {'name': 'multisample_ext', 'default': True, |
88 'extension_flag': 'ext_multisample_compatibility'}, | 91 'extension_flag': 'ext_multisample_compatibility'}, |
89 {'name': 'sample_alpha_to_one_ext', | 92 {'name': 'sample_alpha_to_one_ext', |
90 'extension_flag': 'ext_multisample_compatibility'}, | 93 'extension_flag': 'ext_multisample_compatibility'}, |
91 ] | 94 ] |
92 | 95 |
93 _STATES = { | 96 _STATES = { |
94 'ClearColor': { | 97 'ClearColor': { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 'default': 'true', | 136 'default': 'true', |
134 'cached': True | 137 'cached': True |
135 }, | 138 }, |
136 { | 139 { |
137 'name': 'color_mask_alpha', | 140 'name': 'color_mask_alpha', |
138 'type': 'GLboolean', | 141 'type': 'GLboolean', |
139 'default': 'true', | 142 'default': 'true', |
140 'cached': True | 143 'cached': True |
141 }, | 144 }, |
142 ], | 145 ], |
143 'state_flag': 'framebuffer_state_.clear_state_dirty', | 146 'state_flag': 'framebuffer_state_' |
| 147 '.set_draw_framebuffer_clear_state_dirty(true)', |
144 }, | 148 }, |
145 'ClearStencil': { | 149 'ClearStencil': { |
146 'type': 'Normal', | 150 'type': 'Normal', |
147 'func': 'ClearStencil', | 151 'func': 'ClearStencil', |
148 'enum': 'GL_STENCIL_CLEAR_VALUE', | 152 'enum': 'GL_STENCIL_CLEAR_VALUE', |
149 'states': [ | 153 'states': [ |
150 {'name': 'stencil_clear', 'type': 'GLint', 'default': '0'}, | 154 {'name': 'stencil_clear', 'type': 'GLint', 'default': '0'}, |
151 ], | 155 ], |
152 }, | 156 }, |
153 'CoverageModulationCHROMIUM': { | 157 'CoverageModulationCHROMIUM': { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 'name': 'sample_coverage_invert', | 290 'name': 'sample_coverage_invert', |
287 'type': 'GLboolean', | 291 'type': 'GLboolean', |
288 'enum': 'GL_SAMPLE_COVERAGE_INVERT', | 292 'enum': 'GL_SAMPLE_COVERAGE_INVERT', |
289 'default': 'false', | 293 'default': 'false', |
290 }, | 294 }, |
291 ], | 295 ], |
292 }, | 296 }, |
293 'StencilMask': { | 297 'StencilMask': { |
294 'type': 'FrontBack', | 298 'type': 'FrontBack', |
295 'func': 'StencilMaskSeparate', | 299 'func': 'StencilMaskSeparate', |
296 'state_flag': 'framebuffer_state_.clear_state_dirty', | 300 'state_flag': 'framebuffer_state_' |
| 301 '.set_draw_framebuffer_clear_state_dirty(true)', |
297 'states': [ | 302 'states': [ |
298 { | 303 { |
299 'name': 'stencil_front_writemask', | 304 'name': 'stencil_front_writemask', |
300 'type': 'GLuint', | 305 'type': 'GLuint', |
301 'enum': 'GL_STENCIL_WRITEMASK', | 306 'enum': 'GL_STENCIL_WRITEMASK', |
302 'default': '0xFFFFFFFFU', | 307 'default': '0xFFFFFFFFU', |
303 'cached': True, | 308 'cached': True, |
304 }, | 309 }, |
305 { | 310 { |
306 'name': 'stencil_back_writemask', | 311 'name': 'stencil_back_writemask', |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 'func': 'DepthMask', | 522 'func': 'DepthMask', |
518 'enum': 'GL_DEPTH_WRITEMASK', | 523 'enum': 'GL_DEPTH_WRITEMASK', |
519 'states': [ | 524 'states': [ |
520 { | 525 { |
521 'name': 'depth_mask', | 526 'name': 'depth_mask', |
522 'type': 'GLboolean', | 527 'type': 'GLboolean', |
523 'default': 'true', | 528 'default': 'true', |
524 'cached': True | 529 'cached': True |
525 }, | 530 }, |
526 ], | 531 ], |
527 'state_flag': 'framebuffer_state_.clear_state_dirty', | 532 'state_flag': 'framebuffer_state_' |
| 533 '.set_draw_framebuffer_clear_state_dirty(true)', |
528 }, | 534 }, |
529 'Scissor': { | 535 'Scissor': { |
530 'type': 'Normal', | 536 'type': 'Normal', |
531 'func': 'Scissor', | 537 'func': 'Scissor', |
532 'enum': 'GL_SCISSOR_BOX', | 538 'enum': 'GL_SCISSOR_BOX', |
533 'states': [ | 539 'states': [ |
534 # NOTE: These defaults reset at GLES2DecoderImpl::Initialization. | 540 # NOTE: These defaults reset at GLES2DecoderImpl::Initialization. |
535 { | 541 { |
536 'name': 'scissor_x', | 542 'name': 'scissor_x', |
537 'type': 'GLint', | 543 'type': 'GLint', |
(...skipping 4882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5420 (func.name, args[ndx].name)) | 5426 (func.name, args[ndx].name)) |
5421 f.write(" return error::kNoError;\n") | 5427 f.write(" return error::kNoError;\n") |
5422 f.write(" }\n") | 5428 f.write(" }\n") |
5423 code = [] | 5429 code = [] |
5424 for ndx,item in enumerate(states): | 5430 for ndx,item in enumerate(states): |
5425 code.append("state_.%s != %s" % (item['name'], args[ndx].name)) | 5431 code.append("state_.%s != %s" % (item['name'], args[ndx].name)) |
5426 f.write(" if (%s) {\n" % " ||\n ".join(code)) | 5432 f.write(" if (%s) {\n" % " ||\n ".join(code)) |
5427 for ndx,item in enumerate(states): | 5433 for ndx,item in enumerate(states): |
5428 f.write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) | 5434 f.write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) |
5429 if 'state_flag' in state: | 5435 if 'state_flag' in state: |
5430 f.write(" %s = true;\n" % state['state_flag']) | 5436 f.write(" %s;\n" % state['state_flag']) |
5431 if not func.GetInfo("no_gl"): | 5437 if not func.GetInfo("no_gl"): |
5432 for ndx,item in enumerate(states): | 5438 for ndx,item in enumerate(states): |
5433 if item.get('cached', False): | 5439 if item.get('cached', False): |
5434 f.write(" state_.%s = %s;\n" % | 5440 f.write(" state_.%s = %s;\n" % |
5435 (CachedStateName(item), args[ndx].name)) | 5441 (CachedStateName(item), args[ndx].name)) |
5436 f.write(" %s(%s);\n" % | 5442 f.write(" %s(%s);\n" % |
5437 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 5443 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) |
5438 f.write(" }\n") | 5444 f.write(" }\n") |
5439 | 5445 |
5440 def WriteServiceUnitTest(self, func, f, *extras): | 5446 def WriteServiceUnitTest(self, func, f, *extras): |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5509 args = func.GetOriginalArgs() | 5515 args = func.GetOriginalArgs() |
5510 num_args = len(args) | 5516 num_args = len(args) |
5511 code = [] | 5517 code = [] |
5512 for ndx,item in enumerate(states): | 5518 for ndx,item in enumerate(states): |
5513 code.append("state_.%s != %s" % (item['name'], args[ndx % num_args].name)) | 5519 code.append("state_.%s != %s" % (item['name'], args[ndx % num_args].name)) |
5514 f.write(" if (%s) {\n" % " ||\n ".join(code)) | 5520 f.write(" if (%s) {\n" % " ||\n ".join(code)) |
5515 for ndx, item in enumerate(states): | 5521 for ndx, item in enumerate(states): |
5516 f.write(" state_.%s = %s;\n" % | 5522 f.write(" state_.%s = %s;\n" % |
5517 (item['name'], args[ndx % num_args].name)) | 5523 (item['name'], args[ndx % num_args].name)) |
5518 if 'state_flag' in state: | 5524 if 'state_flag' in state: |
5519 f.write(" %s = true;\n" % state['state_flag']) | 5525 f.write(" %s;\n" % state['state_flag']) |
5520 if not func.GetInfo("no_gl"): | 5526 if not func.GetInfo("no_gl"): |
5521 f.write(" %s(%s);\n" % | 5527 f.write(" %s(%s);\n" % |
5522 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 5528 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) |
5523 f.write(" }\n") | 5529 f.write(" }\n") |
5524 | 5530 |
5525 | 5531 |
5526 class StateSetFrontBackSeparateHandler(TypeHandler): | 5532 class StateSetFrontBackSeparateHandler(TypeHandler): |
5527 """Handler for commands that simply set state that have front/back.""" | 5533 """Handler for commands that simply set state that have front/back.""" |
5528 | 5534 |
5529 def WriteHandlerImplementation(self, func, f): | 5535 def WriteHandlerImplementation(self, func, f): |
(...skipping 15 matching lines...) Expand all Loading... |
5545 f.write(" }\n") | 5551 f.write(" }\n") |
5546 f.write(" if (changed) {\n") | 5552 f.write(" if (changed) {\n") |
5547 for group_ndx, group in enumerate(Grouper(num_args - 1, states)): | 5553 for group_ndx, group in enumerate(Grouper(num_args - 1, states)): |
5548 f.write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" % | 5554 f.write(" if (%s == %s || %s == GL_FRONT_AND_BACK) {\n" % |
5549 (face, ('GL_FRONT', 'GL_BACK')[group_ndx], face)) | 5555 (face, ('GL_FRONT', 'GL_BACK')[group_ndx], face)) |
5550 for ndx, item in enumerate(group): | 5556 for ndx, item in enumerate(group): |
5551 f.write(" state_.%s = %s;\n" % | 5557 f.write(" state_.%s = %s;\n" % |
5552 (item['name'], args[ndx + 1].name)) | 5558 (item['name'], args[ndx + 1].name)) |
5553 f.write(" }\n") | 5559 f.write(" }\n") |
5554 if 'state_flag' in state: | 5560 if 'state_flag' in state: |
5555 f.write(" %s = true;\n" % state['state_flag']) | 5561 f.write(" %s;\n" % state['state_flag']) |
5556 if not func.GetInfo("no_gl"): | 5562 if not func.GetInfo("no_gl"): |
5557 f.write(" %s(%s);\n" % | 5563 f.write(" %s(%s);\n" % |
5558 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 5564 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) |
5559 f.write(" }\n") | 5565 f.write(" }\n") |
5560 | 5566 |
5561 | 5567 |
5562 class StateSetFrontBackHandler(TypeHandler): | 5568 class StateSetFrontBackHandler(TypeHandler): |
5563 """Handler for commands that simply set state that set both front/back.""" | 5569 """Handler for commands that simply set state that set both front/back.""" |
5564 | 5570 |
5565 def WriteHandlerImplementation(self, func, f): | 5571 def WriteHandlerImplementation(self, func, f): |
5566 """Overrriden from TypeHandler.""" | 5572 """Overrriden from TypeHandler.""" |
5567 state_name = func.GetInfo('state') | 5573 state_name = func.GetInfo('state') |
5568 state = _STATES[state_name] | 5574 state = _STATES[state_name] |
5569 states = state['states'] | 5575 states = state['states'] |
5570 args = func.GetOriginalArgs() | 5576 args = func.GetOriginalArgs() |
5571 num_args = len(args) | 5577 num_args = len(args) |
5572 code = [] | 5578 code = [] |
5573 for group_ndx, group in enumerate(Grouper(num_args, states)): | 5579 for group_ndx, group in enumerate(Grouper(num_args, states)): |
5574 for ndx, item in enumerate(group): | 5580 for ndx, item in enumerate(group): |
5575 code.append("state_.%s != %s" % (item['name'], args[ndx].name)) | 5581 code.append("state_.%s != %s" % (item['name'], args[ndx].name)) |
5576 f.write(" if (%s) {\n" % " ||\n ".join(code)) | 5582 f.write(" if (%s) {\n" % " ||\n ".join(code)) |
5577 for group_ndx, group in enumerate(Grouper(num_args, states)): | 5583 for group_ndx, group in enumerate(Grouper(num_args, states)): |
5578 for ndx, item in enumerate(group): | 5584 for ndx, item in enumerate(group): |
5579 f.write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) | 5585 f.write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) |
5580 if 'state_flag' in state: | 5586 if 'state_flag' in state: |
5581 f.write(" %s = true;\n" % state['state_flag']) | 5587 f.write(" %s;\n" % state['state_flag']) |
5582 if not func.GetInfo("no_gl"): | 5588 if not func.GetInfo("no_gl"): |
5583 f.write(" %s(%s);\n" % | 5589 f.write(" %s(%s);\n" % |
5584 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) | 5590 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) |
5585 f.write(" }\n") | 5591 f.write(" }\n") |
5586 | 5592 |
5587 | 5593 |
5588 class StateSetNamedParameter(TypeHandler): | 5594 class StateSetNamedParameter(TypeHandler): |
5589 """Handler for commands that set a state chosen with an enum parameter.""" | 5595 """Handler for commands that set a state chosen with an enum parameter.""" |
5590 | 5596 |
5591 def WriteHandlerImplementation(self, func, f): | 5597 def WriteHandlerImplementation(self, func, f): |
(...skipping 5056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10648 switch (cap) { | 10654 switch (cap) { |
10649 """) | 10655 """) |
10650 for capability in _CAPABILITY_FLAGS: | 10656 for capability in _CAPABILITY_FLAGS: |
10651 f.write(" case GL_%s:\n" % capability['name'].upper()) | 10657 f.write(" case GL_%s:\n" % capability['name'].upper()) |
10652 if 'state_flag' in capability: | 10658 if 'state_flag' in capability: |
10653 | 10659 |
10654 f.write("""\ | 10660 f.write("""\ |
10655 state_.enable_flags.%(name)s = enabled; | 10661 state_.enable_flags.%(name)s = enabled; |
10656 if (state_.enable_flags.cached_%(name)s != enabled | 10662 if (state_.enable_flags.cached_%(name)s != enabled |
10657 || state_.ignore_cached_state) { | 10663 || state_.ignore_cached_state) { |
10658 %(state_flag)s = true; | 10664 %(state_flag)s; |
10659 } | 10665 } |
10660 return false; | 10666 return false; |
10661 """ % capability) | 10667 """ % capability) |
10662 else: | 10668 else: |
10663 f.write("""\ | 10669 f.write("""\ |
10664 state_.enable_flags.%(name)s = enabled; | 10670 state_.enable_flags.%(name)s = enabled; |
10665 if (state_.enable_flags.cached_%(name)s != enabled | 10671 if (state_.enable_flags.cached_%(name)s != enabled |
10666 || state_.ignore_cached_state) { | 10672 || state_.ignore_cached_state) { |
10667 state_.enable_flags.cached_%(name)s = enabled; | 10673 state_.enable_flags.cached_%(name)s = enabled; |
10668 return true; | 10674 return true; |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11516 Format(gen.generated_cpp_filenames) | 11522 Format(gen.generated_cpp_filenames) |
11517 | 11523 |
11518 if gen.errors > 0: | 11524 if gen.errors > 0: |
11519 print "%d errors" % gen.errors | 11525 print "%d errors" % gen.errors |
11520 return 1 | 11526 return 1 |
11521 return 0 | 11527 return 0 |
11522 | 11528 |
11523 | 11529 |
11524 if __name__ == '__main__': | 11530 if __name__ == '__main__': |
11525 sys.exit(main(sys.argv[1:])) | 11531 sys.exit(main(sys.argv[1:])) |
OLD | NEW |