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) 2006-2009 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 |
(...skipping 30 matching lines...) Expand all Loading... |
41 'GLint': 'int', | 41 'GLint': 'int', |
42 'GLsizei': 'int', | 42 'GLsizei': 'int', |
43 'GLubyte': 'unsigned char', | 43 'GLubyte': 'unsigned char', |
44 'GLushort': 'unsigned short', | 44 'GLushort': 'unsigned short', |
45 'GLuint': 'unsigned int', | 45 'GLuint': 'unsigned int', |
46 'GLfloat': 'float', | 46 'GLfloat': 'float', |
47 'GLclampf': 'float', | 47 'GLclampf': 'float', |
48 'GLvoid': 'void', | 48 'GLvoid': 'void', |
49 'GLfixed': 'int', | 49 'GLfixed': 'int', |
50 'GLclampx': 'int', | 50 'GLclampx': 'int', |
51 'GLintptr': 'khronos_intptr_t', | 51 'GLintptr': 'long int', |
52 'GLsizeiptr': 'khronos_ssize_t', | 52 'GLsizeiptr': 'long int', |
53 } | 53 } |
54 _GL_FUNCTIONS = """ | 54 _GL_FUNCTIONS = """ |
55 GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); | 55 GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); |
56 GL_APICALL void GL_APIENTRY glAttachShader (GLidProgram program, GLidSha
der shader); | 56 GL_APICALL void GL_APIENTRY glAttachShader (GLidProgram program, GLidSha
der shader); |
57 GL_APICALL void GL_APIENTRY glBindAttribLocation (GLidProgram program, G
Luint index, const char* name); | 57 GL_APICALL void GL_APIENTRY glBindAttribLocation (GLidProgram program, G
Luint index, const char* name); |
58 GL_APICALL void GL_APIENTRY glBindBuffer (GLenumBufferTarget target, GLi
dBindBuffer buffer); | 58 GL_APICALL void GL_APIENTRY glBindBuffer (GLenumBufferTarget target, GLi
dBindBuffer buffer); |
59 GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenumFrameBufferTarget t
arget, GLidBindFramebuffer framebuffer); | 59 GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenumFrameBufferTarget t
arget, GLidBindFramebuffer framebuffer); |
60 GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenumRenderBufferTarget
target, GLidBindRenderbuffer renderbuffer); | 60 GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenumRenderBufferTarget
target, GLidBindRenderbuffer renderbuffer); |
61 GL_APICALL void GL_APIENTRY glBindTexture (GLenumTextureBindTarget targe
t, GLidBindTexture texture); | 61 GL_APICALL void GL_APIENTRY glBindTexture (GLenumTextureBindTarget targe
t, GLidBindTexture texture); |
62 GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green,
GLclampf blue, GLclampf alpha); | 62 GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green,
GLclampf blue, GLclampf alpha); |
(...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 'needs_size': True, | 1455 'needs_size': True, |
1456 'cmd_args': | 1456 'cmd_args': |
1457 'GLuint shader, const char* data', | 1457 'GLuint shader, const char* data', |
1458 }, | 1458 }, |
1459 'StencilMask': {'decoder_func': 'DoStencilMask'}, | 1459 'StencilMask': {'decoder_func': 'DoStencilMask'}, |
1460 'StencilMaskSeparate': {'decoder_func': 'DoStencilMaskSeparate'}, | 1460 'StencilMaskSeparate': {'decoder_func': 'DoStencilMaskSeparate'}, |
1461 'SwapBuffers': { | 1461 'SwapBuffers': { |
1462 'type': 'Custom', | 1462 'type': 'Custom', |
1463 'impl_func': False, | 1463 'impl_func': False, |
1464 'unit_test': False, | 1464 'unit_test': False, |
| 1465 'extension': True, |
1465 }, | 1466 }, |
1466 'TexImage2D': {'type': 'Manual', 'immediate': True}, | 1467 'TexImage2D': {'type': 'Manual', 'immediate': True}, |
1467 'TexParameterf': {'decoder_func': 'DoTexParameterf'}, | 1468 'TexParameterf': {'decoder_func': 'DoTexParameterf'}, |
1468 'TexParameteri': {'decoder_func': 'DoTexParameteri'}, | 1469 'TexParameteri': {'decoder_func': 'DoTexParameteri'}, |
1469 'TexParameterfv': { | 1470 'TexParameterfv': { |
1470 'type': 'PUT', | 1471 'type': 'PUT', |
1471 'data_type': 'GLfloat', | 1472 'data_type': 'GLfloat', |
1472 'count': 1, | 1473 'count': 1, |
1473 'decoder_func': 'DoTexParameterfv', | 1474 'decoder_func': 'DoTexParameterfv', |
1474 }, | 1475 }, |
(...skipping 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4506 def GetInfo(self, name): | 4507 def GetInfo(self, name): |
4507 """Returns a value from the function info for this function.""" | 4508 """Returns a value from the function info for this function.""" |
4508 if hasattr(self.info, name): | 4509 if hasattr(self.info, name): |
4509 return getattr(self.info, name) | 4510 return getattr(self.info, name) |
4510 return None | 4511 return None |
4511 | 4512 |
4512 def AddInfo(self, name, value): | 4513 def AddInfo(self, name, value): |
4513 """Adds an info.""" | 4514 """Adds an info.""" |
4514 setattr(self.info, name, value) | 4515 setattr(self.info, name, value) |
4515 | 4516 |
| 4517 def IsCoreGLFunction(self): |
| 4518 return not self.GetInfo('extension') |
| 4519 |
4516 def GetGLFunctionName(self): | 4520 def GetGLFunctionName(self): |
4517 """Gets the function to call to execute GL for this command.""" | 4521 """Gets the function to call to execute GL for this command.""" |
4518 if self.GetInfo('decoder_func'): | 4522 if self.GetInfo('decoder_func'): |
4519 return self.GetInfo('decoder_func') | 4523 return self.GetInfo('decoder_func') |
4520 return "gl%s" % self.original_name | 4524 return "gl%s" % self.original_name |
4521 | 4525 |
4522 def GetGLTestFunctionName(self): | 4526 def GetGLTestFunctionName(self): |
4523 gl_func_name = self.GetInfo('gl_test_func') | 4527 gl_func_name = self.GetInfo('gl_test_func') |
4524 if gl_func_name == None: | 4528 if gl_func_name == None: |
4525 gl_func_name = self.GetGLFunctionName() | 4529 gl_func_name = self.GetGLFunctionName() |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5248 'post': post, | 5252 'post': post, |
5249 }) | 5253 }) |
5250 pre = ' ' | 5254 pre = ' ' |
5251 file.Write("}\n\n"); | 5255 file.Write("}\n\n"); |
5252 file.Close() | 5256 file.Close() |
5253 | 5257 |
5254 def WritePepperGLES2Interface(self, filename): | 5258 def WritePepperGLES2Interface(self, filename): |
5255 """Writes the Pepper OpenGLES interface definition.""" | 5259 """Writes the Pepper OpenGLES interface definition.""" |
5256 file = CHeaderWriter( | 5260 file = CHeaderWriter( |
5257 filename, | 5261 filename, |
5258 "// This interface is used to access common and lite profile OpenGL ES " | 5262 "// OpenGL ES interface.\n", |
5259 "2.0\n// functions.\n", | |
5260 3) | 5263 3) |
5261 | 5264 |
5262 file.Write("#include \"ppapi/GLES2/khrplatform.h\"\n\n") | 5265 file.Write("#ifndef __gl2_h_\n") |
5263 | |
5264 file.Write("#define PPB_OPENGLES_DEV_INTERFACE \"PPB_OpenGLES(Dev);2.0\"\n\n
") | |
5265 | |
5266 for (k, v) in _GL_TYPES.iteritems(): | 5266 for (k, v) in _GL_TYPES.iteritems(): |
5267 file.Write("typedef %s %s;\n" % (v, k)) | 5267 file.Write("typedef %s %s;\n" % (v, k)) |
| 5268 file.Write("#endif // __gl2_h_\n\n") |
5268 | 5269 |
5269 file.Write("\nstruct PPB_OpenGLES_Dev {\n") | 5270 file.Write("#define PPB_OPENGLES2_DEV_INTERFACE \"PPB_OpenGLES(Dev);2.0\"\n"
) |
| 5271 |
| 5272 file.Write("\nstruct PPB_OpenGLES2_Dev {\n") |
5270 for func in self.original_functions: | 5273 for func in self.original_functions: |
5271 if func.GetInfo('extension'): | 5274 if not func.IsCoreGLFunction(): |
5272 continue | 5275 continue |
5273 file.Write(" %s (*%s)(%s);\n" % | 5276 |
5274 (func.return_type, func.name, | 5277 original_arg = func.MakeTypedOriginalArgString("") |
5275 func.MakeTypedOriginalArgString(""))) | 5278 context_arg = "PP_Resource context" |
| 5279 if len(original_arg): |
| 5280 arg = context_arg + ", " + original_arg |
| 5281 else: |
| 5282 arg = context_arg |
| 5283 file.Write(" %s (*%s)(%s);\n" % (func.return_type, func.name, arg)) |
5276 file.Write("};\n\n") | 5284 file.Write("};\n\n") |
5277 | 5285 |
5278 file.Close() | 5286 file.Close() |
5279 | 5287 |
5280 def WritePepperGLES2Implementation(self, filename): | 5288 def WritePepperGLES2Implementation(self, filename): |
5281 """Writes the Pepper OpenGLES interface implementation.""" | 5289 """Writes the Pepper OpenGLES interface implementation.""" |
5282 | 5290 |
5283 file = CWriter(filename) | 5291 file = CWriter(filename) |
5284 file.Write(_LICENSE) | 5292 file.Write(_LICENSE) |
5285 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5293 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") |
5286 | 5294 |
5287 file.Write("#include \"webkit/glue/plugins/pepper_graphics_3d.h\"\n\n") | 5295 file.Write("#include \"webkit/plugins/ppapi/ppb_graphics_3d_impl.h\"\n\n") |
5288 | 5296 |
5289 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") | 5297 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") |
5290 file.Write("\n#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n\n") | 5298 file.Write("\n#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n\n") |
5291 | 5299 |
5292 file.Write("namespace pepper {\n\n") | 5300 file.Write("namespace webkit {\n") |
| 5301 file.Write("namespace ppapi {\n\n") |
5293 file.Write("namespace {\n\n") | 5302 file.Write("namespace {\n\n") |
5294 | 5303 |
5295 for func in self.original_functions: | 5304 for func in self.original_functions: |
5296 if func.GetInfo('extension'): | 5305 if not func.IsCoreGLFunction(): |
5297 continue | 5306 continue |
5298 file.Write("%s %s(%s) {\n" % | 5307 |
5299 (func.return_type, func.name, | 5308 original_arg = func.MakeTypedOriginalArgString("") |
5300 func.MakeTypedOriginalArgString(""))) | 5309 context_arg = "PP_Resource context" |
5301 return_string = "return " | 5310 if len(original_arg): |
5302 if func.return_type == "void": | 5311 arg = context_arg + ", " + original_arg |
5303 return_string = "" | 5312 else: |
5304 file.Write(" %sGraphics3D::GetCurrent()->impl()->%s(%s);\n" % | 5313 arg = context_arg |
5305 (return_string, func.original_name, | 5314 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) |
| 5315 |
| 5316 file.Write(""" scoped_refptr<PPB_Graphics3D_Impl> graphics_3d = |
| 5317 Resource::GetAs<PPB_Graphics3D_Impl>(context); |
| 5318 """) |
| 5319 |
| 5320 return_str = "" if func.return_type == "void" else "return " |
| 5321 file.Write(" %sgraphics_3d->impl()->%s(%s);\n" % |
| 5322 (return_str, func.original_name, |
5306 func.MakeOriginalArgString(""))) | 5323 func.MakeOriginalArgString(""))) |
5307 file.Write("}\n") | 5324 file.Write("}\n\n") |
5308 | 5325 |
5309 file.Write("\nconst struct PPB_OpenGLES_Dev ppb_opengles = {\n") | 5326 file.Write("\nconst struct PPB_OpenGLES2_Dev ppb_opengles2 = {\n") |
5310 | |
5311 file.Write(" &") | 5327 file.Write(" &") |
5312 file.Write(",\n &".join( | 5328 file.Write(",\n &".join( |
5313 f.name for f in self.original_functions if not f.GetInfo('extension'))) | 5329 f.name for f in self.original_functions if f.IsCoreGLFunction())) |
5314 file.Write("\n") | 5330 file.Write("\n") |
| 5331 file.Write("};\n\n") |
5315 | 5332 |
5316 file.Write("};\n\n") | |
5317 file.Write("} // namespace\n") | 5333 file.Write("} // namespace\n") |
5318 | 5334 |
5319 file.Write(""" | 5335 file.Write(""" |
5320 const PPB_OpenGLES_Dev* Graphics3D::GetOpenGLESInterface() { | 5336 const PPB_OpenGLES2_Dev* PPB_Graphics3D_Impl::GetOpenGLES2Interface() { |
5321 return &ppb_opengles; | 5337 return &ppb_opengles2; |
5322 } | 5338 } |
5323 | 5339 |
5324 """) | 5340 """) |
5325 file.Write("} // namespace pepper\n\n") | 5341 file.Write("} // namespace ppapi\n") |
| 5342 file.Write("} // namespace webkit\n\n") |
5326 | 5343 |
5327 file.Close() | 5344 file.Close() |
5328 | 5345 |
5329 def WriteGLES2ToPPAPIBridge(self, filename): | 5346 def WriteGLES2ToPPAPIBridge(self, filename): |
5330 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" | 5347 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" |
5331 | 5348 |
5332 file = CWriter(filename) | 5349 file = CWriter(filename) |
5333 file.Write(_LICENSE) | 5350 file.Write(_LICENSE) |
5334 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5351 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") |
5335 | 5352 |
5336 file.Write("#include <GLES2/gl2.h>\n\n") | 5353 file.Write("#include <GLES2/gl2.h>\n") |
| 5354 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") |
5337 | 5355 |
5338 for func in self.original_functions: | 5356 for func in self.original_functions: |
5339 if func.GetInfo('extension') or func.name == 'SwapBuffers': | 5357 if not func.IsCoreGLFunction(): |
5340 continue | 5358 continue |
5341 | 5359 |
5342 file.Write("%s GL_APIENTRY gl%s(%s) {\n" % | 5360 file.Write("%s GL_APIENTRY gl%s(%s) {\n" % |
5343 (func.return_type, func.name, | 5361 (func.return_type, func.name, |
5344 func.MakeTypedOriginalArgString(""))) | 5362 func.MakeTypedOriginalArgString(""))) |
5345 if func.return_type != "void": | 5363 return_str = "" if func.return_type == "void" else "return " |
5346 file.Write(" return 0;\n") | 5364 interface_str = "glGetInterfacePPAPI()" |
| 5365 original_arg = func.MakeOriginalArgString("") |
| 5366 context_arg = "glGetCurrentContextPPAPI()" |
| 5367 if len(original_arg): |
| 5368 arg = context_arg + ", " + original_arg |
| 5369 else: |
| 5370 arg = context_arg |
| 5371 file.Write(" %s%s->%s(%s);\n" % |
| 5372 (return_str, interface_str, func.name, arg)) |
5347 file.Write("}\n\n") | 5373 file.Write("}\n\n") |
5348 | 5374 |
5349 def main(argv): | 5375 def main(argv): |
5350 """This is the main function.""" | 5376 """This is the main function.""" |
5351 parser = OptionParser() | 5377 parser = OptionParser() |
5352 parser.add_option( | 5378 parser.add_option( |
5353 "-g", "--generate-implementation-templates", action="store_true", | 5379 "-g", "--generate-implementation-templates", action="store_true", |
5354 help="generates files that are generally hand edited..") | 5380 help="generates files that are generally hand edited..") |
5355 parser.add_option( | 5381 parser.add_option( |
5356 "--generate-command-id-tests", action="store_true", | 5382 "--generate-command-id-tests", action="store_true", |
5357 help="generate tests for commands ids. Commands MUST not change ID!") | 5383 help="generate tests for commands ids. Commands MUST not change ID!") |
5358 parser.add_option( | 5384 parser.add_option( |
(...skipping 14 matching lines...) Expand all Loading... |
5373 | 5399 |
5374 gen = GLGenerator(options.verbose) | 5400 gen = GLGenerator(options.verbose) |
5375 gen.ParseGLH("common/GLES2/gl2.h") | 5401 gen.ParseGLH("common/GLES2/gl2.h") |
5376 | 5402 |
5377 if options.alternate_mode == "ppapi": | 5403 if options.alternate_mode == "ppapi": |
5378 gen.WritePepperGLES2Interface("ppapi/c/dev/ppb_opengles_dev.h") | 5404 gen.WritePepperGLES2Interface("ppapi/c/dev/ppb_opengles_dev.h") |
5379 gen.WriteGLES2ToPPAPIBridge("ppapi/lib/gl/gles2/gles2.c") | 5405 gen.WriteGLES2ToPPAPIBridge("ppapi/lib/gl/gles2/gles2.c") |
5380 | 5406 |
5381 elif options.alternate_mode == "chrome_ppapi": | 5407 elif options.alternate_mode == "chrome_ppapi": |
5382 gen.WritePepperGLES2Implementation( | 5408 gen.WritePepperGLES2Implementation( |
5383 "webkit/glue/plugins/pepper_graphics_3d_gl.cc") | 5409 "webkit/plugins/ppapi/ppb_opengles_impl.cc") |
5384 | 5410 |
5385 else: | 5411 else: |
5386 gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") | 5412 gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") |
5387 gen.WriteFormat("common/gles2_cmd_format_autogen.h") | 5413 gen.WriteFormat("common/gles2_cmd_format_autogen.h") |
5388 gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") | 5414 gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") |
5389 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") | 5415 gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") |
5390 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") | 5416 gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") |
5391 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") | 5417 gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") |
5392 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") | 5418 gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") |
5393 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") | 5419 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") |
5394 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") | 5420 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") |
5395 gen.WriteServiceUtilsImplementation( | 5421 gen.WriteServiceUtilsImplementation( |
5396 "service/gles2_cmd_validation_implementation_autogen.h") | 5422 "service/gles2_cmd_validation_implementation_autogen.h") |
5397 | 5423 |
5398 if options.generate_command_id_tests: | 5424 if options.generate_command_id_tests: |
5399 gen.WriteCommandIdTest("common/gles2_cmd_id_test_autogen.h") | 5425 gen.WriteCommandIdTest("common/gles2_cmd_id_test_autogen.h") |
5400 | 5426 |
5401 if options.generate_docs: | 5427 if options.generate_docs: |
5402 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") | 5428 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") |
5403 | 5429 |
5404 if gen.errors > 0: | 5430 if gen.errors > 0: |
5405 print "%d errors" % gen.errors | 5431 print "%d errors" % gen.errors |
5406 sys.exit(1) | 5432 sys.exit(1) |
5407 | 5433 |
5408 if __name__ == '__main__': | 5434 if __name__ == '__main__': |
5409 main(sys.argv[1:]) | 5435 main(sys.argv[1:]) |
OLD | NEW |