diff options
author | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-13 23:52:06 +0000 |
---|---|---|
committer | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-13 23:52:06 +0000 |
commit | aa80d6f3701438f0a87b8ebefdde011dbaf2c569 (patch) | |
tree | bb269d64bbc653710848982402f0b3ac7a4646eb /gpu/command_buffer/build_gles2_cmd_buffer.py | |
parent | 4775604ab44e737268f30d8fc3a29eb308475d00 (diff) | |
download | chromium_src-aa80d6f3701438f0a87b8ebefdde011dbaf2c569.zip chromium_src-aa80d6f3701438f0a87b8ebefdde011dbaf2c569.tar.gz chromium_src-aa80d6f3701438f0a87b8ebefdde011dbaf2c569.tar.bz2 |
Update build_gles2_cmd_buffer.py for PPAPI.
BUG=none
TEST=generated files on Linux are not different from before, PPAPI files compile fine.
Review URL: http://codereview.chromium.org/3227005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59305 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer/build_gles2_cmd_buffer.py')
-rwxr-xr-x | gpu/command_buffer/build_gles2_cmd_buffer.py | 162 |
1 files changed, 139 insertions, 23 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py index 4381fdc..2c76fcf 100755 --- a/gpu/command_buffer/build_gles2_cmd_buffer.py +++ b/gpu/command_buffer/build_gles2_cmd_buffer.py @@ -16,7 +16,7 @@ _SIZE_OF_UINT32 = 4 _SIZE_OF_COMMAND_HEADER = 4 _FIRST_SPECIFIC_COMMAND_ID = 256 -_LICENSE = """// Copyright (c) 2009 The Chromium Authors. All rights reserved. +_LICENSE = """// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,6 +32,25 @@ _LICENSE = """// Copyright (c) 2009 The Chromium Authors. All rights reserved. # # *) All GLenums have been changed to GLenumTypeOfEnum # +_GL_TYPES = { + 'GLenum': 'unsigned int', + 'GLboolean': 'unsigned char', + 'GLbitfield': 'unsigned int', + 'GLbyte': 'signed char', + 'GLshort': 'short', + 'GLint': 'int', + 'GLsizei': 'int', + 'GLubyte': 'unsigned char', + 'GLushort': 'unsigned short', + 'GLuint': 'unsigned int', + 'GLfloat': 'float', + 'GLclampf': 'float', + 'GLvoid': 'void', + 'GLfixed': 'int', + 'GLclampx': 'int', + 'GLintptr': 'khronos_intptr_t', + 'GLsizeiptr': 'khronos_ssize_t', +} _GL_FUNCTIONS = """ GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); GL_APICALL void GL_APIENTRY glAttachShader (GLidProgram program, GLidShader shader); @@ -1595,11 +1614,15 @@ class CWriter(object): if splitter >= 0 and not string[splitter + 1] == '=' and splitter < 80: return splitter parts = string.split('(') + fptr = re.compile('\*\w*\)') if len(parts) > 1: splitter = len(parts[0]) for ii in range(1, len(parts)): + # Don't split on the dot in "if (.condition)". if (not parts[ii - 1][-3:] == "if " and - (len(parts[ii]) > 0 and not parts[ii][0] == ")") + # Don't split "(.)" or "(.*fptr)". + (len(parts[ii]) > 0 and + not parts[ii][0] == ")" and not fptr.match(parts[ii])) and splitter < 80): return splitter splitter += len(parts[ii]) + 1 @@ -1651,10 +1674,13 @@ class CHeaderWriter(CWriter): _non_alnum_re = re.compile(r'[^a-zA-Z0-9]') - def __init__(self, filename, file_comment = None): + def __init__(self, filename, file_comment = None, guard_depth = 3): CWriter.__init__(self, filename) - base = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + base = os.path.dirname(os.path.abspath(filename)) + for i in range(guard_depth): + base = os.path.dirname(base) + hpath = os.path.abspath(filename)[len(base) + 1:] self.guard = self._non_alnum_re.sub('_', hpath).upper() + '_' @@ -5085,9 +5111,83 @@ class GLGenerator(object): 'post': post, }) pre = ' ' - file.Write("}\n"); + file.Write("}\n\n"); file.Close() + def WritePepperGLES2Interface(self, filename): + """Writes the Pepper OpenGLES interface definition.""" + file = CHeaderWriter( + filename, + "// This interface is used to access common and lite profile OpenGL ES " + "2.0\n// functions.\n", + 2) + + file.Write("#include \"../GLES2/khrplatform.h\"\n\n") + + file.Write("#define PPB_OPENGLES_INTERFACE \"PPB_OpenGLES;2.0\"\n\n") + + for (k, v) in _GL_TYPES.iteritems(): + file.Write("typedef %s %s;\n" % (v, k)) + + file.Write("\ntypedef struct _ppb_OpenGLES {\n") + for func in self.original_functions: + if func.name[-3:] == "EXT": + continue + file.Write(" %s (*%s)(%s);\n" % + (func.return_type, func.name, + func.MakeTypedOriginalArgString(""))) + file.Write("} PPB_OpenGLES;\n\n") + + file.Close() + + def WritePepperGLES2Implementation(self, filename): + """Writes the Pepper OpenGLES interface implementation.""" + + file = CWriter(filename) + file.Write(_LICENSE) + file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") + + file.Write("#include \"webkit/glue/plugins/pepper_graphics_3d.h\"\n\n") + + file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") + file.Write("\n#include \"third_party/ppapi/c/ppb_opengles.h\"\n\n") + + file.Write("namespace pepper {\n\n") + file.Write("namespace {\n\n") + + for func in self.original_functions: + if func.name[-3:] == "EXT": + continue + file.Write("%s %s(%s) {\n" % + (func.return_type, func.name, + func.MakeTypedOriginalArgString(""))) + return_string = "return " + if func.return_type == "void": + return_string = "" + file.Write(" %sGraphics3D::GetCurrent()->impl()->%s(%s);\n" % + (return_string, func.original_name, + func.MakeOriginalArgString(""))) + file.Write("}\n") + + file.Write("\nconst PPB_OpenGLES ppb_opengles = {\n") + + file.Write(" &") + file.Write(",\n &".join( + f.name for f in self.original_functions if f.name[-3:] != "EXT")) + file.Write("\n") + + file.Write("};\n\n") + file.Write("} // namespace\n") + + file.Write(""" +const PPB_OpenGLES* Graphics3D::GetOpenGLESInterface() { + return &ppb_opengles; +} + +""") + file.Write("} // namespace pepper\n\n") + + file.Close() def main(argv): """This is the main function.""" @@ -5102,6 +5202,13 @@ def main(argv): "--generate-docs", action="store_true", help="generate a docs friendly version of the command formats.") parser.add_option( + "--alternate-mode", type="choice", + choices=("ppapi", "chrome_ppapi", "ppapi_gles2"), + help="generate files for other projects. \"ppapi\" must be run from the " + "directory containing the ppapi directory, and will generate ppapi " + "bindings. \"chrome_ppapi\" must be run from chrome src directory and " + "will generate chrome plumbing for ppapi.") + parser.add_option( "-v", "--verbose", action="store_true", help="prints more output.") @@ -5109,23 +5216,32 @@ def main(argv): gen = GLGenerator(options.verbose) gen.ParseGLH("common/GLES2/gl2.h") - gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") - gen.WriteFormat("common/gles2_cmd_format_autogen.h") - gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") - gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") - gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") - gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") - gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") - gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") - gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") - gen.WriteServiceUtilsImplementation( - "service/gles2_cmd_validation_implementation_autogen.h") - - if options.generate_command_id_tests: - gen.WriteCommandIdTest("common/gles2_cmd_id_test_autogen.h") - - if options.generate_docs: - gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") + + if options.alternate_mode == "ppapi": + gen.WritePepperGLES2Interface("ppapi/c/ppb_opengles.h") + + elif options.alternate_mode == "chrome_ppapi": + gen.WritePepperGLES2Implementation( + "webkit/glue/plugins/pepper_graphics_3d_gl.cc") + + else: + gen.WriteCommandIds("common/gles2_cmd_ids_autogen.h") + gen.WriteFormat("common/gles2_cmd_format_autogen.h") + gen.WriteFormatTest("common/gles2_cmd_format_test_autogen.h") + gen.WriteGLES2ImplementationHeader("client/gles2_implementation_autogen.h") + gen.WriteGLES2CLibImplementation("client/gles2_c_lib_autogen.h") + gen.WriteCmdHelperHeader("client/gles2_cmd_helper_autogen.h") + gen.WriteServiceImplementation("service/gles2_cmd_decoder_autogen.h") + gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") + gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") + gen.WriteServiceUtilsImplementation( + "service/gles2_cmd_validation_implementation_autogen.h") + + if options.generate_command_id_tests: + gen.WriteCommandIdTest("common/gles2_cmd_id_test_autogen.h") + + if options.generate_docs: + gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") if gen.errors > 0: print "%d errors" % gen.errors |