| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (c) 2011 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) 2011 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 _DO_NOT_EDIT_WARNING = """// This file is auto-generated from |
| 26 // gpu/command_buffer/build_gles2_cmd_buffer.py |
| 27 // DO NOT EDIT! |
| 28 |
| 29 """ |
| 30 |
| 25 # This string is copied directly out of the gl2.h file from GLES2.0 | 31 # This string is copied directly out of the gl2.h file from GLES2.0 |
| 26 # | 32 # |
| 27 # Edits: | 33 # Edits: |
| 28 # | 34 # |
| 29 # *) Any argument that is a resourceID has been changed to GLid<Type>. | 35 # *) Any argument that is a resourceID has been changed to GLid<Type>. |
| 30 # (not pointer arguments) and if it's allowed to be zero it's GLidZero<Type> | 36 # (not pointer arguments) and if it's allowed to be zero it's GLidZero<Type> |
| 31 # If it's allowed to not exist it's GLidBind<Type> | 37 # If it's allowed to not exist it's GLidBind<Type> |
| 32 # | 38 # |
| 33 # *) All GLenums have been changed to GLenumTypeOfEnum | 39 # *) All GLenums have been changed to GLenumTypeOfEnum |
| 34 # | 40 # |
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 CWriter.__init__(self, filename) | 1848 CWriter.__init__(self, filename) |
| 1843 | 1849 |
| 1844 base = os.path.dirname(os.path.abspath(filename)) | 1850 base = os.path.dirname(os.path.abspath(filename)) |
| 1845 for i in range(guard_depth): | 1851 for i in range(guard_depth): |
| 1846 base = os.path.dirname(base) | 1852 base = os.path.dirname(base) |
| 1847 | 1853 |
| 1848 hpath = os.path.abspath(filename)[len(base) + 1:] | 1854 hpath = os.path.abspath(filename)[len(base) + 1:] |
| 1849 self.guard = self._non_alnum_re.sub('_', hpath).upper() + '_' | 1855 self.guard = self._non_alnum_re.sub('_', hpath).upper() + '_' |
| 1850 | 1856 |
| 1851 self.Write(_LICENSE) | 1857 self.Write(_LICENSE) |
| 1852 self.Write( | 1858 self.Write(_DO_NOT_EDIT_WARNING) |
| 1853 "// This file is auto-generated. DO NOT EDIT!\n" | |
| 1854 "\n") | |
| 1855 if not file_comment == None: | 1859 if not file_comment == None: |
| 1856 self.Write(file_comment) | 1860 self.Write(file_comment) |
| 1857 self.Write("#ifndef %s\n" % self.guard) | 1861 self.Write("#ifndef %s\n" % self.guard) |
| 1858 self.Write("#define %s\n\n" % self.guard) | 1862 self.Write("#define %s\n\n" % self.guard) |
| 1859 | 1863 |
| 1860 def Close(self): | 1864 def Close(self): |
| 1861 self.Write("#endif // %s\n\n" % self.guard) | 1865 self.Write("#endif // %s\n\n" % self.guard) |
| 1862 CWriter.Close(self) | 1866 CWriter.Close(self) |
| 1863 | 1867 |
| 1864 class TypeHandler(object): | 1868 class TypeHandler(object): |
| (...skipping 3772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5637 file.Write(" %s (*%s)(%s);\n" % (func.return_type, func.name, arg)) | 5641 file.Write(" %s (*%s)(%s);\n" % (func.return_type, func.name, arg)) |
| 5638 file.Write("};\n\n") | 5642 file.Write("};\n\n") |
| 5639 | 5643 |
| 5640 file.Close() | 5644 file.Close() |
| 5641 | 5645 |
| 5642 def WritePepperGLES2Implementation(self, filename): | 5646 def WritePepperGLES2Implementation(self, filename): |
| 5643 """Writes the Pepper OpenGLES interface implementation.""" | 5647 """Writes the Pepper OpenGLES interface implementation.""" |
| 5644 | 5648 |
| 5645 file = CWriter(filename) | 5649 file = CWriter(filename) |
| 5646 file.Write(_LICENSE) | 5650 file.Write(_LICENSE) |
| 5647 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5651 file.Write(_DO_NOT_EDIT_WARNING) |
| 5648 | 5652 |
| 5649 file.Write("#include \"webkit/plugins/ppapi/ppb_opengles_impl.h\"\n\n") | 5653 file.Write("#include \"webkit/plugins/ppapi/ppb_opengles_impl.h\"\n\n") |
| 5650 | 5654 |
| 5651 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) | 5655 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) |
| 5652 file.Write("#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n") | 5656 file.Write("#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n") |
| 5657 file.Write("#include \"ppapi/shared_impl/resource_object_base.h\"\n") |
| 5658 file.Write("#include \"ppapi/shared_impl/tracker_base.h\"\n") |
| 5653 file.Write("#include \"webkit/plugins/ppapi/ppb_context_3d_impl.h\"\n\n") | 5659 file.Write("#include \"webkit/plugins/ppapi/ppb_context_3d_impl.h\"\n\n") |
| 5654 | 5660 |
| 5661 file.Write("using ppapi::ResourceObjectBase;\n") |
| 5662 file.Write("using ppapi::TrackerBase;\n\n") |
| 5655 file.Write("namespace webkit {\n") | 5663 file.Write("namespace webkit {\n") |
| 5656 file.Write("namespace ppapi {\n\n") | 5664 file.Write("namespace ppapi {\n\n") |
| 5657 file.Write("namespace {\n\n") | 5665 file.Write("namespace {\n\n") |
| 5658 | 5666 |
| 5667 file.Write("gpu::gles2::GLES2Implementation* GetGLES(PP_Resource context) {\
n") |
| 5668 file.Write(" ResourceObjectBase* base = TrackerBase::Get()->GetResourceAPI(
context);\n") |
| 5669 file.Write(" DCHECK(base->AsPPB_Context3D_API());\n") |
| 5670 file.Write(" return static_cast<PPB_Context3D_Impl*>(base)->gles2_impl();\n
") |
| 5671 file.Write("}\n\n") |
| 5672 |
| 5659 for func in self.original_functions: | 5673 for func in self.original_functions: |
| 5660 if not func.IsCoreGLFunction(): | 5674 if not func.IsCoreGLFunction(): |
| 5661 continue | 5675 continue |
| 5662 | 5676 |
| 5663 original_arg = func.MakeTypedOriginalArgString("") | 5677 original_arg = func.MakeTypedOriginalArgString("") |
| 5664 context_arg = "PP_Resource context_id" | 5678 context_arg = "PP_Resource context_id" |
| 5665 if len(original_arg): | 5679 if len(original_arg): |
| 5666 arg = context_arg + ", " + original_arg | 5680 arg = context_arg + ", " + original_arg |
| 5667 else: | 5681 else: |
| 5668 arg = context_arg | 5682 arg = context_arg |
| 5669 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) | 5683 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) |
| 5670 | 5684 |
| 5671 file.Write(""" scoped_refptr<PPB_Context3D_Impl> context = | |
| 5672 Resource::GetAs<PPB_Context3D_Impl>(context_id); | |
| 5673 """) | |
| 5674 | |
| 5675 return_str = "" if func.return_type == "void" else "return " | 5685 return_str = "" if func.return_type == "void" else "return " |
| 5676 file.Write(" %scontext->gles2_impl()->%s(%s);\n" % | 5686 file.Write(" %sGetGLES(context_id)->%s(%s);\n" % |
| 5677 (return_str, func.original_name, | 5687 (return_str, func.original_name, |
| 5678 func.MakeOriginalArgString(""))) | 5688 func.MakeOriginalArgString(""))) |
| 5679 file.Write("}\n\n") | 5689 file.Write("}\n\n") |
| 5680 | 5690 |
| 5681 file.Write("\nconst struct PPB_OpenGLES2_Dev ppb_opengles2 = {\n") | 5691 file.Write("\nconst struct PPB_OpenGLES2_Dev ppb_opengles2 = {\n") |
| 5682 file.Write(" &") | 5692 file.Write(" &") |
| 5683 file.Write(",\n &".join( | 5693 file.Write(",\n &".join( |
| 5684 f.name for f in self.original_functions if f.IsCoreGLFunction())) | 5694 f.name for f in self.original_functions if f.IsCoreGLFunction())) |
| 5685 file.Write("\n") | 5695 file.Write("\n") |
| 5686 file.Write("};\n\n") | 5696 file.Write("};\n\n") |
| 5687 | 5697 |
| 5688 file.Write("} // namespace\n") | 5698 file.Write("} // namespace\n") |
| 5689 | 5699 |
| 5690 file.Write(""" | 5700 file.Write(""" |
| 5691 const PPB_OpenGLES2_Dev* PPB_OpenGLES_Impl::GetInterface() { | 5701 const PPB_OpenGLES2_Dev* PPB_OpenGLES_Impl::GetInterface() { |
| 5692 return &ppb_opengles2; | 5702 return &ppb_opengles2; |
| 5693 } | 5703 } |
| 5694 | 5704 |
| 5695 """) | 5705 """) |
| 5696 file.Write("} // namespace ppapi\n") | 5706 file.Write("} // namespace ppapi\n") |
| 5697 file.Write("} // namespace webkit\n\n") | 5707 file.Write("} // namespace webkit\n\n") |
| 5698 | 5708 |
| 5699 file.Close() | 5709 file.Close() |
| 5700 | 5710 |
| 5701 def WritePepperGLES2ProxyImplementation(self, filename): | 5711 def WritePepperGLES2ProxyImplementation(self, filename): |
| 5702 """Writes the Pepper OpenGLES interface implementation.""" | 5712 """Writes the Pepper OpenGLES interface implementation.""" |
| 5703 | 5713 |
| 5704 file = CWriter(filename) | 5714 file = CWriter(filename) |
| 5705 file.Write(_LICENSE) | 5715 file.Write(_LICENSE) |
| 5706 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5716 file.Write(_DO_NOT_EDIT_WARNING) |
| 5707 | 5717 |
| 5708 file.Write("#include \"ppapi/proxy/ppb_opengles2_proxy.h\"\n\n") | 5718 file.Write("#include \"ppapi/proxy/ppb_opengles2_proxy.h\"\n\n") |
| 5709 | 5719 |
| 5710 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) | 5720 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n"
) |
| 5711 file.Write("#include \"ppapi/c/pp_errors.h\"\n") | 5721 file.Write("#include \"ppapi/c/pp_errors.h\"\n") |
| 5712 file.Write("#include \"ppapi/c/pp_resource.h\"\n") | 5722 file.Write("#include \"ppapi/c/pp_resource.h\"\n") |
| 5713 file.Write("#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n") | 5723 file.Write("#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n") |
| 5714 file.Write("#include \"ppapi/proxy/plugin_dispatcher.h\"\n") | 5724 file.Write("#include \"ppapi/proxy/plugin_dispatcher.h\"\n") |
| 5715 file.Write("#include \"ppapi/proxy/plugin_resource.h\"\n") | 5725 file.Write("#include \"ppapi/proxy/plugin_resource.h\"\n") |
| 5716 file.Write("#include \"ppapi/proxy/ppb_context_3d_proxy.h\"\n\n") | 5726 file.Write("#include \"ppapi/proxy/ppb_context_3d_proxy.h\"\n") |
| 5727 file.Write("#include \"ppapi/shared_impl/resource_object_base.h\"\n") |
| 5728 file.Write("#include \"ppapi/shared_impl/tracker_base.h\"\n\n") |
| 5717 | 5729 |
| 5718 file.Write("namespace pp {\n") | 5730 file.Write("namespace pp {\n") |
| 5719 file.Write("namespace proxy {\n\n") | 5731 file.Write("namespace proxy {\n\n") |
| 5720 file.Write("namespace {\n\n") | 5732 file.Write("namespace {\n\n") |
| 5721 | 5733 file.Write("gpu::gles2::GLES2Implementation* GetGLES(PP_Resource context) {\
n") |
| 5734 file.Write(" ppapi::ResourceObjectBase* base =\n") |
| 5735 file.Write(" ppapi::TrackerBase::Get()->GetResourceAPI(context);\n") |
| 5736 file.Write(" DCHECK(base->AsPPB_Context3D_API());\n") |
| 5737 file.Write(" return static_cast<Context3D*>(base)->gles2_impl();\n") |
| 5738 file.Write("}\n\n") |
| 5722 | 5739 |
| 5723 for func in self.original_functions: | 5740 for func in self.original_functions: |
| 5724 if not func.IsCoreGLFunction(): | 5741 if not func.IsCoreGLFunction(): |
| 5725 continue | 5742 continue |
| 5726 | 5743 |
| 5727 original_arg = func.MakeTypedOriginalArgString("") | 5744 original_arg = func.MakeTypedOriginalArgString("") |
| 5728 context_arg = "PP_Resource context_id" | 5745 context_arg = "PP_Resource context_id" |
| 5729 if len(original_arg): | 5746 if len(original_arg): |
| 5730 arg = context_arg + ", " + original_arg | 5747 arg = context_arg + ", " + original_arg |
| 5731 else: | 5748 else: |
| 5732 arg = context_arg | 5749 arg = context_arg |
| 5733 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) | 5750 file.Write("%s %s(%s) {\n" % (func.return_type, func.name, arg)) |
| 5734 | 5751 |
| 5735 file.Write(""" Context3D* context = PluginResource::GetAs<Context3D>(cont
ext_id);\n""") | |
| 5736 | |
| 5737 return_str = "" if func.return_type == "void" else "return " | 5752 return_str = "" if func.return_type == "void" else "return " |
| 5738 file.Write(" %scontext->gles2_impl()->%s(%s);\n" % | 5753 file.Write(" %sGetGLES(context_id)->%s(%s);\n" % |
| 5739 (return_str, func.original_name, | 5754 (return_str, func.original_name, |
| 5740 func.MakeOriginalArgString(""))) | 5755 func.MakeOriginalArgString(""))) |
| 5741 file.Write("}\n\n") | 5756 file.Write("}\n\n") |
| 5742 | 5757 |
| 5743 file.Write("const struct PPB_OpenGLES2_Dev opengles2_interface = {\n") | 5758 file.Write("const struct PPB_OpenGLES2_Dev opengles2_interface = {\n") |
| 5744 file.Write(" &") | 5759 file.Write(" &") |
| 5745 file.Write(",\n &".join( | 5760 file.Write(",\n &".join( |
| 5746 f.name for f in self.original_functions if f.IsCoreGLFunction())) | 5761 f.name for f in self.original_functions if f.IsCoreGLFunction())) |
| 5747 file.Write("\n") | 5762 file.Write("\n") |
| 5748 file.Write("};\n\n") | 5763 file.Write("};\n\n") |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5783 file.Write("} // namespace proxy\n") | 5798 file.Write("} // namespace proxy\n") |
| 5784 file.Write("} // namespace pp\n") | 5799 file.Write("} // namespace pp\n") |
| 5785 | 5800 |
| 5786 file.Close() | 5801 file.Close() |
| 5787 | 5802 |
| 5788 def WriteGLES2ToPPAPIBridge(self, filename): | 5803 def WriteGLES2ToPPAPIBridge(self, filename): |
| 5789 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" | 5804 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" |
| 5790 | 5805 |
| 5791 file = CWriter(filename) | 5806 file = CWriter(filename) |
| 5792 file.Write(_LICENSE) | 5807 file.Write(_LICENSE) |
| 5793 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5808 file.Write(_DO_NOT_EDIT_WARNING) |
| 5794 | 5809 |
| 5795 file.Write("#include <GLES2/gl2.h>\n") | 5810 file.Write("#include <GLES2/gl2.h>\n") |
| 5796 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") | 5811 file.Write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") |
| 5797 | 5812 |
| 5798 for func in self.original_functions: | 5813 for func in self.original_functions: |
| 5799 if not func.IsCoreGLFunction(): | 5814 if not func.IsCoreGLFunction(): |
| 5800 continue | 5815 continue |
| 5801 | 5816 |
| 5802 file.Write("%s GL_APIENTRY gl%s(%s) {\n" % | 5817 file.Write("%s GL_APIENTRY gl%s(%s) {\n" % |
| 5803 (func.return_type, func.name, | 5818 (func.return_type, func.name, |
| 5804 func.MakeTypedOriginalArgString(""))) | 5819 func.MakeTypedOriginalArgString(""))) |
| 5805 return_str = "" if func.return_type == "void" else "return " | 5820 return_str = "" if func.return_type == "void" else "return " |
| 5806 interface_str = "glGetInterfacePPAPI()" | 5821 interface_str = "glGetInterfacePPAPI()" |
| 5807 original_arg = func.MakeOriginalArgString("") | 5822 original_arg = func.MakeOriginalArgString("") |
| 5808 context_arg = "glGetCurrentContextPPAPI()" | 5823 context_arg = "glGetCurrentContextPPAPI()" |
| 5809 if len(original_arg): | 5824 if len(original_arg): |
| 5810 arg = context_arg + ", " + original_arg | 5825 arg = context_arg + ", " + original_arg |
| 5811 else: | 5826 else: |
| 5812 arg = context_arg | 5827 arg = context_arg |
| 5813 file.Write(" %s%s->%s(%s);\n" % | 5828 file.Write(" %s%s->%s(%s);\n" % |
| 5814 (return_str, interface_str, func.name, arg)) | 5829 (return_str, interface_str, func.name, arg)) |
| 5815 file.Write("}\n\n") | 5830 file.Write("}\n\n") |
| 5816 | 5831 |
| 5817 def WritePepperGLES2NaClProxy(self, filename): | 5832 def WritePepperGLES2NaClProxy(self, filename): |
| 5818 """Writes the Pepper OpenGLES interface implementation for NaCl.""" | 5833 """Writes the Pepper OpenGLES interface implementation for NaCl.""" |
| 5819 | 5834 |
| 5820 file = CWriter(filename) | 5835 file = CWriter(filename) |
| 5821 file.Write(_LICENSE) | 5836 file.Write(_LICENSE) |
| 5822 file.Write("// This file is auto-generated. DO NOT EDIT!\n\n") | 5837 file.Write(_DO_NOT_EDIT_WARNING) |
| 5823 | 5838 |
| 5824 file.Write("#include \"native_client/src/shared/ppapi_proxy" | 5839 file.Write("#include \"native_client/src/shared/ppapi_proxy" |
| 5825 "/plugin_context_3d.h\"\n\n") | 5840 "/plugin_context_3d.h\"\n\n") |
| 5826 | 5841 |
| 5827 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") | 5842 file.Write("#include \"gpu/command_buffer/client/gles2_implementation.h\"") |
| 5828 file.Write("\n#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n\n") | 5843 file.Write("\n#include \"ppapi/c/dev/ppb_opengles_dev.h\"\n\n") |
| 5829 | 5844 |
| 5830 file.Write("using ppapi_proxy::PluginContext3D;\n") | 5845 file.Write("using ppapi_proxy::PluginContext3D;\n") |
| 5831 file.Write("using ppapi_proxy::PluginResource;\n\n") | 5846 file.Write("using ppapi_proxy::PluginResource;\n\n") |
| 5832 file.Write("namespace {\n\n") | 5847 file.Write("namespace {\n\n") |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5944 | 5959 |
| 5945 if options.generate_docs: | 5960 if options.generate_docs: |
| 5946 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") | 5961 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") |
| 5947 | 5962 |
| 5948 if gen.errors > 0: | 5963 if gen.errors > 0: |
| 5949 print "%d errors" % gen.errors | 5964 print "%d errors" % gen.errors |
| 5950 sys.exit(1) | 5965 sys.exit(1) |
| 5951 | 5966 |
| 5952 if __name__ == '__main__': | 5967 if __name__ == '__main__': |
| 5953 main(sys.argv[1:]) | 5968 main(sys.argv[1:]) |
| OLD | NEW |