OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """code generator for GLES2 command buffers.""" | 7 """code generator for GLES2 command buffers.""" |
8 | 8 |
9 import os | 9 import os |
10 import os.path | 10 import os.path |
11 import sys | 11 import sys |
12 import re | 12 import re |
13 from optparse import OptionParser | 13 from optparse import OptionParser |
14 | 14 |
15 _SIZE_OF_UINT32 = 4 | 15 _SIZE_OF_UINT32 = 4 |
16 _SIZE_OF_COMMAND_HEADER = 4 | 16 _SIZE_OF_COMMAND_HEADER = 4 |
17 _FIRST_SPECIFIC_COMMAND_ID = 256 | 17 _FIRST_SPECIFIC_COMMAND_ID = 256 |
18 | 18 |
19 _LICENSE = """// Copyright (c) 2010 The Chromium Authors. All rights reserved. | 19 _LICENSE = """// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
20 // Use of this source code is governed by a BSD-style license that can be | 20 // Use of this source code is governed by a BSD-style license that can be |
21 // found in the LICENSE file. | 21 // found in the LICENSE file. |
22 | 22 |
23 """ | 23 """ |
24 | 24 |
25 # This string is copied directly out of the gl2.h file from GLES2.0 | 25 # This string is copied directly out of the gl2.h file from GLES2.0 |
26 # | 26 # |
27 # Edits: | 27 # Edits: |
28 # | 28 # |
29 # *) Any argument that is a resourceID has been changed to GLid<Type>. | 29 # *) Any argument that is a resourceID has been changed to GLid<Type>. |
(...skipping 5319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5349 const PPB_OpenGLES2_Dev* PPB_OpenGLES_Impl::GetInterface() { | 5349 const PPB_OpenGLES2_Dev* PPB_OpenGLES_Impl::GetInterface() { |
5350 return &ppb_opengles2; | 5350 return &ppb_opengles2; |
5351 } | 5351 } |
5352 | 5352 |
5353 """) | 5353 """) |
5354 file.Write("} // namespace ppapi\n") | 5354 file.Write("} // namespace ppapi\n") |
5355 file.Write("} // namespace webkit\n\n") | 5355 file.Write("} // namespace webkit\n\n") |
5356 | 5356 |
5357 file.Close() | 5357 file.Close() |
5358 | 5358 |
| 5359 def WritePepperGLES2ProxyImplementation(self, filename): |
| 5360 """Writes the Pepper OpenGLES interface implementation.""" |
| 5361 |
| 5362 file = CWriter(filename) |
| 5363 file.Write(_LICENSE) |
| 5364 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") |
| 5365 |
| 5366 file.Write("#include \"ppapi/proxy/ppb_opengles2_proxy.h\"\n\n") |
| 5367 |
| 5368 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) |
| 5369 file.Write("#include \"ppapi/c/pp_errors.h\"\n") |
| 5370 file.Write("#include \"ppapi/c/pp_resource.h\"\n") |
| 5371 file.Write("#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n") |
| 5372 file.Write("#include \"ppapi/proxy/plugin_dispatcher.h\"\n") |
| 5373 file.Write("#include \"ppapi/proxy/plugin_resource.h\"\n") |
| 5374 file.Write("#include \"ppapi/proxy/ppb_context_3d_proxy.h\"\n\n") |
| 5375 |
| 5376 file.Write("namespace pp {\n") |
| 5377 file.Write("namespace proxy {\n\n") |
| 5378 file.Write("namespace {\n\n") |
| 5379 |
| 5380 |
| 5381 for func in self.original_functions: |
| 5382 if not func.IsCoreGLFunction(): |
| 5383 continue |
| 5384 |
| 5385 original_arg = func.MakeTypedOriginalArgString("") |
| 5386 context_arg = "PP_Resource context_id" |
| 5387 if len(original_arg): |
| 5388 arg = context_arg + ", " + original_arg |
| 5389 else: |
| 5390 arg = context_arg |
| 5391 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) |
| 5392 |
| 5393 file.Write(""" Context3D* context = PluginResource::GetAs<Context3D>(cont
ext_id);\n""") |
| 5394 |
| 5395 return_str = "" if func.return_type == "void" else "return " |
| 5396 file.Write(" %scontext->gles2_impl()->%s(%s);\n" % |
| 5397 (return_str, func.original_name, |
| 5398 func.MakeOriginalArgString(""))) |
| 5399 file.Write("}\n\n") |
| 5400 |
| 5401 file.Write("const struct PPB_OpenGLES2_Dev ppb_opengles2 = {\n") |
| 5402 file.Write(" &") |
| 5403 file.Write(",\n &".join( |
| 5404 f.name for f in self.original_functions if f.IsCoreGLFunction())) |
| 5405 file.Write("\n") |
| 5406 file.Write("};\n\n") |
| 5407 |
| 5408 file.Write("} // namespace\n") |
| 5409 |
| 5410 file.Write(""" |
| 5411 PPB_OpenGLES2_Proxy::PPB_OpenGLES2_Proxy(Dispatcher* dispatcher, |
| 5412 const void* target_interface) |
| 5413 : InterfaceProxy(dispatcher, target_interface) { |
| 5414 } |
| 5415 |
| 5416 PPB_OpenGLES2_Proxy::~PPB_OpenGLES2_Proxy() { |
| 5417 } |
| 5418 |
| 5419 const void* PPB_OpenGLES2_Proxy::GetSourceInterface() const { |
| 5420 return &ppb_opengles2; |
| 5421 } |
| 5422 |
| 5423 InterfaceID PPB_OpenGLES2_Proxy::GetInterfaceId() const { |
| 5424 return INTERFACE_ID_NONE; |
| 5425 } |
| 5426 |
| 5427 bool PPB_OpenGLES2_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 5428 return false; |
| 5429 } |
| 5430 |
| 5431 """) |
| 5432 file.Write("} // namespace proxy\n") |
| 5433 file.Write("} // namespace pp\n") |
| 5434 |
| 5435 file.Close() |
| 5436 |
5359 def WriteGLES2ToPPAPIBridge(self, filename): | 5437 def WriteGLES2ToPPAPIBridge(self, filename): |
5360 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" | 5438 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" |
5361 | 5439 |
5362 file = CWriter(filename) | 5440 file = CWriter(filename) |
5363 file.Write(_LICENSE) | 5441 file.Write(_LICENSE) |
5364 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5442 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") |
5365 | 5443 |
5366 file.Write("#include <GLES2/gl2.h>\n") | 5444 file.Write("#include <GLES2/gl2.h>\n") |
5367 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") | 5445 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") |
5368 | 5446 |
(...skipping 23 matching lines...) Expand all Loading... |
5392 "-g", "--generate-implementation-templates", action="store_true", | 5470 "-g", "--generate-implementation-templates", action="store_true", |
5393 help="generates files that are generally hand edited..") | 5471 help="generates files that are generally hand edited..") |
5394 parser.add_option( | 5472 parser.add_option( |
5395 "--generate-command-id-tests", action="store_true", | 5473 "--generate-command-id-tests", action="store_true", |
5396 help="generate tests for commands ids. Commands MUST not change ID!") | 5474 help="generate tests for commands ids. Commands MUST not change ID!") |
5397 parser.add_option( | 5475 parser.add_option( |
5398 "--generate-docs", action="store_true", | 5476 "--generate-docs", action="store_true", |
5399 help="generate a docs friendly version of the command formats.") | 5477 help="generate a docs friendly version of the command formats.") |
5400 parser.add_option( | 5478 parser.add_option( |
5401 "--alternate-mode", type="choice", | 5479 "--alternate-mode", type="choice", |
5402 choices=("ppapi", "chrome_ppapi"), | 5480 choices=("ppapi", "chrome_ppapi", "chrome_ppapi_proxy"), |
5403 help="generate files for other projects. \"ppapi\" will generate ppapi " | 5481 help="generate files for other projects. \"ppapi\" will generate ppapi " |
5404 "bindings. \"chrome_ppapi\" generate chrome implementation for ppapi.") | 5482 "bindings. \"chrome_ppapi\" generate chrome implementation for ppapi. " |
| 5483 "\"chrome_ppapi_proxy\" will generate the glue for the chrome IPC ppapi" |
| 5484 "proxy.") |
5405 parser.add_option( | 5485 parser.add_option( |
5406 "--output-dir", | 5486 "--output-dir", |
5407 help="base directory for resulting files, under chrome/src. default is " | 5487 help="base directory for resulting files, under chrome/src. default is " |
5408 "empty. Use this if you want the result stored under gen.") | 5488 "empty. Use this if you want the result stored under gen.") |
5409 parser.add_option( | 5489 parser.add_option( |
5410 "-v", "--verbose", action="store_true", | 5490 "-v", "--verbose", action="store_true", |
5411 help="prints more output.") | 5491 help="prints more output.") |
5412 | 5492 |
5413 (options, args) = parser.parse_args(args=argv) | 5493 (options, args) = parser.parse_args(args=argv) |
5414 | 5494 |
(...skipping 11 matching lines...) Expand all Loading... |
5426 # To trigger this action, do "make ppapi_gles_bindings" | 5506 # To trigger this action, do "make ppapi_gles_bindings" |
5427 os.chdir("ppapi"); | 5507 os.chdir("ppapi"); |
5428 gen.WritePepperGLES2Interface("c/dev/ppb_opengles_dev.h") | 5508 gen.WritePepperGLES2Interface("c/dev/ppb_opengles_dev.h") |
5429 gen.WriteGLES2ToPPAPIBridge("lib/gl/gles2/gles2.c") | 5509 gen.WriteGLES2ToPPAPIBridge("lib/gl/gles2/gles2.c") |
5430 | 5510 |
5431 elif options.alternate_mode == "chrome_ppapi": | 5511 elif options.alternate_mode == "chrome_ppapi": |
5432 # To trigger this action, do "make ppapi_gles_implementation" | 5512 # To trigger this action, do "make ppapi_gles_implementation" |
5433 gen.WritePepperGLES2Implementation( | 5513 gen.WritePepperGLES2Implementation( |
5434 "webkit/plugins/ppapi/ppb_opengles_impl.cc") | 5514 "webkit/plugins/ppapi/ppb_opengles_impl.cc") |
5435 | 5515 |
| 5516 elif options.alternate_mode == "chrome_ppapi_proxy": |
| 5517 gen.WritePepperGLES2ProxyImplementation( |
| 5518 "ppapi/proxy/ppb_opengles2_proxy.cc") |
| 5519 |
5436 else: | 5520 else: |
5437 os.chdir("gpu/command_buffer") | 5521 os.chdir("gpu/command_buffer") |
5438 gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") | 5522 gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") |
5439 gen.WriteFormat("common/gles2_cmd_format_autogen.h") | 5523 gen.WriteFormat("common/gles2_cmd_format_autogen.h") |
5440 gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") | 5524 gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") |
5441 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") | 5525 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") |
5442 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") | 5526 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") |
5443 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") | 5527 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") |
5444 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") | 5528 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") |
5445 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") | 5529 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") |
5446 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") | 5530 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") |
5447 gen.WriteServiceUtilsImplementation( | 5531 gen.WriteServiceUtilsImplementation( |
5448 "service/gles2_cmd_validation_implementation_autogen.h") | 5532 "service/gles2_cmd_validation_implementation_autogen.h") |
5449 | 5533 |
5450 if options.generate_command_id_tests: | 5534 if options.generate_command_id_tests: |
5451 gen.WriteCommandIdTest("common/gles2_cmd_id_test_autogen.h") | 5535 gen.WriteCommandIdTest("common/gles2_cmd_id_test_autogen.h") |
5452 | 5536 |
5453 if options.generate_docs: | 5537 if options.generate_docs: |
5454 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") | 5538 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") |
5455 | 5539 |
5456 if gen.errors > 0: | 5540 if gen.errors > 0: |
5457 print "%d errors" % gen.errors | 5541 print "%d errors" % gen.errors |
5458 sys.exit(1) | 5542 sys.exit(1) |
5459 | 5543 |
5460 if __name__ == '__main__': | 5544 if __name__ == '__main__': |
5461 main(sys.argv[1:]) | 5545 main(sys.argv[1:]) |
OLD | NEW |