aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/glx/gen_gl_wrappers.py
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-12-22 12:51:45 +0100
committermarha <marha@users.sourceforge.net>2013-12-22 12:51:45 +0100
commitc81020559f329a516191927222b3698ba7370aca (patch)
tree6f004f5723ca41881b2ba703ed619a92faebfe16 /xorg-server/hw/xwin/glx/gen_gl_wrappers.py
parentc043f97a8572e1f509251288d8bcd70d0fb96770 (diff)
downloadvcxsrv-c81020559f329a516191927222b3698ba7370aca.tar.gz
vcxsrv-c81020559f329a516191927222b3698ba7370aca.tar.bz2
vcxsrv-c81020559f329a516191927222b3698ba7370aca.zip
libxtrans fontconfig glproto libX11 libxcb xcbproto mesa xserver pixman xkeyboard-config git update 22 Dec 2013
xserver commit a68df147421da21528b5be2d34678383922fa352 libxcb commit f653464554469b5767f1c99abced25a76bace047 libxcb/xcb-proto commit 4087fc682c5ceb849b74442e17a6b73176e5eecb xkeyboard-config commit a224a636139d22e1dc7ca7d23782cd656e87bcf5 libX11 commit 3d69b0a83e62f8f6fbdd952fc49cdbdf8825e1e6 libXdmcp commit 089081dca4ba3598c6f9bf401c029378943b5854 libXext commit bb24f2970f2e425f4df90c9b73d078ad15a73fbb libfontenc commit 3acba630d8b57084f7e92c15732408711ed5137a libXinerama commit edd95182b26eb5d576d4878c559e0f17dddaa909 libXau commit 304a11be4727c5a7feeb2501e8e001466f8ce84e xkbcomp commit e3e6e938535532bfad175c1635256ab7fb3ac943 pixman commit 945ab7a6f3eb6241f07e8f094dc0e647d1f10d9d xextproto commit 3f355f138d6df57e067458a20f47307883048adb randrproto commit e7526e6b5fe0966929cda10b2ded0258413744db glproto commit f84853d97d5749308992412a215fa518b6536eb3 mkfontscale commit 880a0c4733e62e54e6a0f1238c7430727d23657b xwininfo commit ba0d1b0da21d2dbdd81098ed5778f3792b472e13 libXft commit 4acfdaf95adb0a05c2a25550bdde036c865902f4 libXmu commit 22d9c590901e121936f50dee97dc60c4f7defb63 libxtrans commit 2c0a7840a28ae696e80e73157856d7a049fdf6c7 fontconfig commit 5c725f2f5829238d16116f782d00d8bb0defaf08 mesa commit 2efe7927d38983029784825fc4897e9b77aa237e
Diffstat (limited to 'xorg-server/hw/xwin/glx/gen_gl_wrappers.py')
-rw-r--r--xorg-server/hw/xwin/glx/gen_gl_wrappers.py766
1 files changed, 463 insertions, 303 deletions
diff --git a/xorg-server/hw/xwin/glx/gen_gl_wrappers.py b/xorg-server/hw/xwin/glx/gen_gl_wrappers.py
index 2273589c9..683b9d903 100644
--- a/xorg-server/hw/xwin/glx/gen_gl_wrappers.py
+++ b/xorg-server/hw/xwin/glx/gen_gl_wrappers.py
@@ -1,325 +1,485 @@
-#!/usr/bin/python
+#!/usr/bin/python3
#
-# Comedy python script to generate cdecl to stdcall wrappers for GL functions
+# python script to generate cdecl to stdcall wrappers for GL functions
+# adapted from genheaders.py
#
-# This is designed to operate on OpenGL spec files from
-# http://www.opengl.org/registry/api/
-#
-#
-# Copyright (c) Jon TURNEY 2009
+# Copyright (c) 2013 The Khronos Group Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the "Software"),
-# to deal in the Software without restriction, including without limitation
-# the rights to use, copy, modify, merge, publish, distribute, sublicense,
-# and/or sell copies of the Software, and to permit persons to whom the
-# Software is furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
-# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-# DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name(s) of the above copyright
-# holders shall not be used in advertising or otherwise to promote the sale,
-# use or other dealings in this Software without prior written authorization.
-#
-
-import sys
-import re
-import getopt
-
-dispatchheader = ''
-prefix = 'gl'
-preresolve = False
-staticwrappers = False
-
-opts, args = getopt.getopt(sys.argv[1:], "", ['spec=', 'typemap=', 'dispatch-header=', 'prefix=', 'preresolve', 'staticwrappers' ])
-
-for o,a in opts:
- if o == '--typemap' :
- typemapfile = a
- elif o == '--dispatch-header' :
- dispatchheader = a
- elif o == '--spec' :
- specfile = a
- elif o == '--prefix' :
- prefix = a
- elif o == '--preresolve' :
- preresolve = True
- elif o == '--staticwrappers' :
- staticwrappers = True
-
+# copy of this software and/or associated documentation files (the
+# "Materials"), to deal in the Materials without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Materials, and to
+# permit persons to whom the Materials are furnished to do so, subject to
+# the following conditions:
#
-# look for all the SET_ macros in dispatch.h, this is the set of functions
-# we need to generate
-#
-
-dispatch = {}
-
-if dispatchheader :
- fh = open(dispatchheader)
- dispatchh = fh.readlines()
-
- dispatch_regex = re.compile(r'^SET_(\S*)\(')
-
- for line in dispatchh :
- line = line.strip()
- m1 = dispatch_regex.search(line)
-
- if m1 :
- dispatch[m1.group(1)] = 1
-
- del dispatch['by_offset']
-
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Materials.
#
-# read the typemap .tm file
-#
-
-typemap = {}
-
-fh = open(typemapfile)
-tm = fh.readlines()
-
-typemap_regex = re.compile(r'#define\sSET_(\S*)\(')
-
-for line in tm :
- # ignore everything after a '#' as a comment
- hash = line.find('#')
- if hash != -1 :
- line = line[:hash-1]
-
- # ignore blank lines
- if line.startswith('#') or len(line) == 0 :
- continue
-
- l = line.split(',')
- typemap[l[0]] = l[3].strip()
-
-# interestingly, * is not a C type
-if typemap['void'] == '*' :
- typemap['void'] = 'void'
-
-#
-# crudely parse the .spec file
-#
-
-r1 = re.compile(r'\t(\S*)\s+(\S*.*)')
-r2 = re.compile(r'(.*)\((.*)\)')
-r3 = re.compile(r'glWindowPos.*MESA')
-r4 = re.compile(r'gl.*Program(s|)NV')
-r5 = re.compile(r'glGetVertexAttribfvNV')
-
-wrappers = {}
-
-fh = open(specfile)
-glspec = fh.readlines()
-param_count = 0
-
-for line in glspec :
- line = line.rstrip()
-
- # ignore everything after a '#' as a comment
- hash = line.find('#')
- if hash != -1 :
- line = line[:hash-1]
-
- # ignore blank lines
- if line.startswith('#') or len(line) == 0 :
- continue
-
- # lines containing ':' aren't intersting to us
- if line.count(':') != 0 :
- continue
-
- # attributes of each function follow the name, indented by a tab
- if not line.startswith('\t') :
- m1 = r2.search(line)
- if m1 :
- function = m1.group(1)
- arglist_use = m1.group(2)
- wrappers[function] = {}
-
- # ensure formal parameter names don't collide with reserved names or shadow global declarations
- arglist_use = ',' .join([i.rstrip() + '_' for i in arglist_use.split(",")])
-
- wrappers[function]['arglist_use'] = arglist_use
- param_count = 0
- else :
- m1 = r1.search(line)
- if m1 :
- attribute = m1.group(1)
- value = m1.group(2)
-
- # make param attributes unique and ordered
- if attribute == 'param' :
- attribute = 'param' + '%02d' % param_count
- param_count += 1
-
- wrappers[function][attribute] = value
-
-#
-# now emit code
-#
-
-print '/* Automatically generated by ' + sys.argv[0] + ' DO NOT EDIT */'
-print '/* from ' + specfile + ' and typemap ' + typemapfile + ' */'
-print ''
-
-#
-# if required, emit code for non-lazy function resolving
-#
-
-if preresolve :
- for w in sorted(wrappers.keys()) :
- funcname = prefix + w
- print 'RESOLVE_DECL(PFN' + funcname.upper() + 'PROC);'
-
- print ''
- print 'void ' + prefix + 'ResolveExtensionProcs(void)'
- print '{'
-
- for w in sorted(wrappers.keys()) :
- funcname = prefix + w
- print ' PRERESOLVE(PFN' + funcname.upper() + 'PROC, "' + funcname + '");'
-
- print '}\n'
+# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+
+import sys, time, pdb, string, cProfile
+from reg import *
+
+# Default input / log files
+errFilename = None
+diagFilename = 'diag.txt'
+regFilename = 'gl.xml'
+outFilename = 'gen_gl_wrappers.c'
+
+protect=True
+prefix="gl"
+preresolve=False
+wrapper=False
+shim=False
+thunk=False
+thunkdefs=False
+staticwrappers=False
+nodebug=False
+
+#exclude base WGL API
+WinGDI={key: 1 for key in [
+ "wglCopyContext"
+ ,"wglCreateContext"
+ ,"wglCreateLayerContext"
+ ,"wglDeleteContext"
+ ,"wglGetCurrentContext"
+ ,"wglGetCurrentDC"
+ ,"wglGetProcAddress"
+ ,"wglMakeCurrent"
+ ,"wglShareLists"
+ ,"wglUseFontBitmapsA"
+ ,"wglUseFontBitmapsW"
+ ,"wglUseFontBitmaps"
+ ,"SwapBuffers"
+ ,"wglUseFontOutlinesA"
+ ,"wglUseFontOutlinesW"
+ ,"wglUseFontOutlines"
+ ,"wglDescribeLayerPlane"
+ ,"wglSetLayerPaletteEntries"
+ ,"wglGetLayerPaletteEntries"
+ ,"wglRealizeLayerPalette"
+ ,"wglSwapLayerBuffers"
+ ,"wglSwapMultipleBuffers"
+ ,"ChoosePixelFormat"
+ ,"DescribePixelFormat"
+ ,"GetEnhMetaFilePixelFormat"
+ ,"GetPixelFormat"
+ ,"SetPixelFormat"
+]}
+
+if __name__ == '__main__':
+ i = 1
+ while (i < len(sys.argv)):
+ arg = sys.argv[i]
+ i = i + 1
+ if (arg == '-noprotect'):
+ print('Disabling inclusion protection in output headers', file=sys.stderr)
+ protect = False
+ elif (arg == '-registry'):
+ regFilename = sys.argv[i]
+ i = i+1
+ print('Using registry', regFilename, file=sys.stderr)
+ elif (arg == '-outfile'):
+ outFilename = sys.argv[i]
+ i = i+1
+ elif (arg == '-preresolve'):
+ preresolve=True
+ elif (arg == '-wrapper'):
+ wrapper=True
+ elif (arg == '-shim'):
+ shim=True
+ elif (arg == '-thunk'):
+ thunk=True
+ elif (arg == '-thunkdefs'):
+ thunkdefs=True
+ elif (arg == '-staticwrappers'):
+ staticwrappers=True
+ elif (arg == '-prefix'):
+ prefix = sys.argv[i]
+ i = i+1
+ elif (arg == '-nodebug'):
+ nodebug = True
+ elif (arg[0:1] == '-'):
+ print('Unrecognized argument:', arg, file=sys.stderr)
+ exit(1)
+
+print('Generating', outFilename, file=sys.stderr)
+
+# Load & parse registry
+reg = Registry()
+tree = etree.parse(regFilename)
+reg.loadElementTree(tree)
+
+allVersions = '.*'
+
+genOpts = CGeneratorOptions(
+ apiname = prefix,
+ profile = 'compatibility',
+ versions = allVersions,
+ emitversions = allVersions,
+ defaultExtensions = prefix, # Default extensions for GL
+ protectFile = protect,
+ protectFeature = protect,
+ protectProto = protect,
+ )
+
+# create error/warning & diagnostic files
+if (errFilename):
+ errWarn = open(errFilename,'w')
+else:
+ errWarn = sys.stderr
+diag = open(diagFilename, 'w')
+
+class PreResolveOutputGenerator(OutputGenerator):
+ def __init__(self,
+ errFile = sys.stderr,
+ warnFile = sys.stderr,
+ diagFile = sys.stdout):
+ OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+ self.wrappers={}
+ def beginFile(self, genOpts):
+ self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+ def endFile(self):
+ self.outFile.write('\nvoid ' + prefix + 'ResolveExtensionProcs(void)\n{\n')
+ for funcname in self.wrappers.keys():
+ self.outFile.write( ' PRERESOLVE(PFN' + funcname.upper() + 'PROC, "' + funcname + '");\n')
+ self.outFile.write('}\n\n')
+ def beginFeature(self, interface, emit):
+ OutputGenerator.beginFeature(self, interface, emit)
+ def endFeature(self):
+ OutputGenerator.endFeature(self)
+ def genType(self, typeinfo, name):
+ OutputGenerator.genType(self, typeinfo, name)
+ def genEnum(self, enuminfo, name):
+ OutputGenerator.genEnum(self, enuminfo, name)
+ def genCmd(self, cmd, name):
+ OutputGenerator.genCmd(self, cmd, name)
+
+ if name in WinGDI:
+ return
+
+ self.outFile.write('RESOLVE_DECL(PFN' + name.upper() + 'PROC);\n')
+ self.wrappers[name]=1
+
+class WrapperOutputGenerator(OutputGenerator):
+ def __init__(self,
+ errFile = sys.stderr,
+ warnFile = sys.stderr,
+ diagFile = sys.stdout):
+ OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+ def beginFile(self, genOpts):
+ self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+ def endFile(self):
+ pass
+ def beginFeature(self, interface, emit):
+ OutputGenerator.beginFeature(self, interface, emit)
+ self.OldVersion = self.featureName.startswith('GL_VERSION_1_0') or self.featureName.startswith('GL_VERSION_1_1')
+ def endFeature(self):
+ OutputGenerator.endFeature(self)
+ def genType(self, typeinfo, name):
+ OutputGenerator.genType(self, typeinfo, name)
+ def genEnum(self, enuminfo, name):
+ OutputGenerator.genEnum(self, enuminfo, name)
+ def genCmd(self, cmd, name):
+ OutputGenerator.genCmd(self, cmd, name)
+
+ if name in WinGDI:
+ return
+
+ proto=noneStr(cmd.elem.find('proto'))
+ rettype=noneStr(proto.text)
+ if rettype.lower()!="void ":
+ plist = ([t for t in proto.itertext()])
+ rettype = ''.join(plist[:-1])
+ rettype=rettype.strip()
+ if staticwrappers: self.outFile.write("static ")
+ self.outFile.write("%s %sWrapper("%(rettype, name))
+ params = cmd.elem.findall('param')
+ plist=[]
+ for param in params:
+ paramlist = ([t for t in param.itertext()])
+ paramtype = ''.join(paramlist[:-1])
+ paramname = paramlist[-1]
+ plist.append((paramtype, paramname))
+ Comma=""
+ if len(plist):
+ for ptype, pname in plist:
+ self.outFile.write("%s%s%s_"%(Comma, ptype, pname))
+ Comma=", "
+ else:
+ self.outFile.write("void")
-#
-# now emit the wrappers
-# for GL 1.0 and 1.1 functions, generate stdcall wrappers which call the function directly
-# for GL 1.2+ functions, generate wrappers which use wglGetProcAddress()
-#
+ self.outFile.write(")\n{\n")
-for w in sorted(wrappers.keys()) :
+ # for GL 1.0 and 1.1 functions, generate stdcall wrappers which call the function directly
+ if self.OldVersion:
+ if not nodebug:
+ self.outFile.write(' if (glxWinDebugSettings.enable%scallTrace) ErrorF("%s\\n");\n'%(prefix.upper(), name))
+ self.outFile.write(" glWinDirectProcCalls++;\n")
+ self.outFile.write("\n")
- funcname = prefix + w
- returntype = wrappers[w]['return']
- if returntype != 'void' :
- returntype = typemap[returntype]
+ if rettype.lower()=="void":
+ self.outFile.write(" %s( "%(name))
+ else:
+ self.outFile.write(" return %s( "%(name))
- # Avoid generating wrappers which aren't referenced by the dispatch table
- if dispatchheader and not dispatch.has_key(w) :
- print '/* No wrapper for ' + funcname + ', not in dispatch table */'
- continue
+ Comma=""
+ for ptype, pname in plist:
+ self.outFile.write("%s%s_"%(Comma, pname))
+ Comma=", "
- # manufacture arglist
- # if no param attributes were found, it should be 'void'
- al = []
- for k in sorted(wrappers[w].keys()) :
- if k.startswith('param') :
- l = wrappers[w][k].split()
+ # for GL 1.2+ functions, generate stdcall wrappers which use wglGetProcAddress()
+ else:
+ if rettype.lower()=="void":
+ self.outFile.write(' RESOLVE(PFN%sPROC, "%s");\n'%(name.upper(), name))
+
+ if not nodebug:
+ self.outFile.write("\n")
+ self.outFile.write(' if (glxWinDebugSettings.enable%scallTrace) ErrorF("%s\\n");\n'%(prefix.upper(), name))
+ self.outFile.write("\n")
+
+ self.outFile.write(" RESOLVED_PROC(PFN%sPROC)( """%(name.upper()))
+ else:
+ self.outFile.write(' RESOLVE_RET(PFN%sPROC, "%s", FALSE);\n'%(name.upper(), name))
+
+ if not nodebug:
+ self.outFile.write("\n")
+ self.outFile.write(' if (glxWinDebugSettings.enable%scallTrace) ErrorF("%s\\n");\n'%(prefix.upper(), name))
+ self.outFile.write("\n")
+
+ self.outFile.write(" return RESOLVED_PROC(PFN%sPROC)("%(name.upper()))
+
+ Comma=""
+ for ptype, pname in plist:
+ self.outFile.write("%s%s_"%(Comma, pname))
+ Comma=", "
+ self.outFile.write(" );\n}\n\n")
+
+class ThunkOutputGenerator(OutputGenerator):
+ def __init__(self,
+ errFile = sys.stderr,
+ warnFile = sys.stderr,
+ diagFile = sys.stdout):
+ OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+ def beginFile(self, genOpts):
+ self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+ def endFile(self):
+ pass
+ def beginFeature(self, interface, emit):
+ OutputGenerator.beginFeature(self, interface, emit)
+ self.OldVersion = self.featureName.startswith('GL_VERSION_1_0') or self.featureName.startswith('GL_VERSION_1_1')
+ def endFeature(self):
+ OutputGenerator.endFeature(self)
+ def genType(self, typeinfo, name):
+ OutputGenerator.genType(self, typeinfo, name)
+ def genEnum(self, enuminfo, name):
+ OutputGenerator.genEnum(self, enuminfo, name)
+ def genCmd(self, cmd, name):
+ OutputGenerator.genCmd(self, cmd, name)
+
+ proto=noneStr(cmd.elem.find('proto'))
+ rettype=noneStr(proto.text)
+ if rettype.lower()!="void ":
+ plist = ([t for t in proto.itertext()])
+ rettype = ''.join(plist[:-1])
+ rettype=rettype.strip()
+ self.outFile.write("%s %sWrapper("%(rettype, name))
+ params = cmd.elem.findall('param')
+ plist=[]
+ for param in params:
+ paramlist = ([t for t in param.itertext()])
+ paramtype = ''.join(paramlist[:-1])
+ paramname = paramlist[-1]
+ plist.append((paramtype, paramname))
+ Comma=""
+ if len(plist):
+ for ptype, pname in plist:
+ self.outFile.write("%s%s%s_"%(Comma, ptype, pname))
+ Comma=", "
+ else:
+ self.outFile.write("void")
- # ensure formal parameter names don't collide with reserved names or shadow global declarations
- l[0] = l[0] + '_'
+ self.outFile.write(")\n{\n")
- if l[2] == 'in' :
- if l[3] == 'array' :
- arg = 'const ' + typemap[l[1]] + ' *' + l[0]
- else :
- arg = typemap[l[1]] + ' ' + l[0]
- elif l[2] == 'out' :
- arg = typemap[l[1]] + ' *' + l[0]
+ # for GL 1.0 and 1.1 functions, generate stdcall thunk wrappers which call the function directly
+ if self.OldVersion:
+ if rettype.lower()=="void":
+ self.outFile.write(" %s( "%(name))
+ else:
+ self.outFile.write(" return %s( "%(name))
- al.append(arg)
+ Comma=""
+ for ptype, pname in plist:
+ self.outFile.write("%s%s_"%(Comma, pname))
+ Comma=", "
- if len(al) == 0 :
- arglist = 'void'
+ # for GL 1.2+ functions, generate wrappers which use wglGetProcAddress()
else:
- arglist = ', '.join(al)
-
- if wrappers[w]['category'].startswith('VERSION_1_0') or wrappers[w]['category'].startswith('VERSION_1_1') :
- if staticwrappers :
- print 'static',
- print returntype + ' ' + funcname + 'Wrapper(' + arglist + ')'
- print '{'
- print ' if (glxWinDebugSettings.enable' + prefix.upper() + 'callTrace) ErrorF("'+ funcname + '\\n");'
- print ' glWinDirectProcCalls++;'
- if returntype.lower() == 'void' :
- print ' ' + funcname + '(',
- else :
- print ' /* returntype was ' + returntype.lower() + '*/'
- print ' return ' + funcname + '(',
-
- if arglist != 'void' :
- print wrappers[w]['arglist_use'],
-
- print ');'
- print "}\n"
+ if rettype.lower()=="void":
+ self.outFile.write(' RESOLVE(PFN%sPROC, "%s");\n'%(name.upper(), name))
+ self.outFile.write(" RESOLVED_PROC(PFN%sPROC)( """%(name.upper()))
+ else:
+ self.outFile.write(' RESOLVE_RET(PFN%sPROC, "%s", FALSE);\n'%(name.upper(), name))
+ self.outFile.write(" return RESOLVED_PROC(PFN%sPROC)("%(name.upper()))
+
+ Comma=""
+ for ptype, pname in plist:
+ self.outFile.write("%s%s_"%(Comma, pname))
+ Comma=", "
+ self.outFile.write(" );\n}\n\n")
+
+class ThunkDefsOutputGenerator(OutputGenerator):
+ def __init__(self,
+ errFile = sys.stderr,
+ warnFile = sys.stderr,
+ diagFile = sys.stdout):
+ OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+ def beginFile(self, genOpts):
+ self.outFile.write("EXPORTS\n"); # this must be the first line for libtool to realize this is a .def file
+ self.outFile.write('; Automatically generated from %s - DO NOT EDIT\n\n'%regFilename)
+ def endFile(self):
+ pass
+ def beginFeature(self, interface, emit):
+ OutputGenerator.beginFeature(self, interface, emit)
+ def endFeature(self):
+ OutputGenerator.endFeature(self)
+ def genType(self, typeinfo, name):
+ OutputGenerator.genType(self, typeinfo, name)
+ def genEnum(self, enuminfo, name):
+ OutputGenerator.genEnum(self, enuminfo, name)
+ def genCmd(self, cmd, name):
+ OutputGenerator.genCmd(self, cmd, name)
+
+ # export the wrapper function with the name of the function it wraps
+ self.outFile.write("%s = %sWrapper\n"%(name, name))
+
+class ShimOutputGenerator(OutputGenerator):
+ def __init__(self,
+ errFile = sys.stderr,
+ warnFile = sys.stderr,
+ diagFile = sys.stdout):
+ OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+ def beginFile(self, genOpts):
+ self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+ def endFile(self):
+ pass
+ def beginFeature(self, interface, emit):
+ OutputGenerator.beginFeature(self, interface, emit)
+ self.OldVersion = self.featureName.startswith('GL_VERSION_1_0') or self.featureName.startswith('GL_VERSION_1_1') or self.featureName.startswith('GL_VERSION_1_2') or self.featureName.startswith('GL_ARB_imaging') or self.featureName.startswith('GL_ARB_multitexture') or self.featureName.startswith('GL_ARB_texture_compression')
+ def endFeature(self):
+ OutputGenerator.endFeature(self)
+ def genType(self, typeinfo, name):
+ OutputGenerator.genType(self, typeinfo, name)
+ def genEnum(self, enuminfo, name):
+ OutputGenerator.genEnum(self, enuminfo, name)
+ def genCmd(self, cmd, name):
+ OutputGenerator.genCmd(self, cmd, name)
+
+ if not self.OldVersion:
+ return
+
+ # for GL functions which are in the ABI, generate a shim which calls the function via GetProcAddress
+ proto=noneStr(cmd.elem.find('proto'))
+ rettype=noneStr(proto.text)
+ if rettype.lower()!="void ":
+ plist = ([t for t in proto.itertext()])
+ rettype = ''.join(plist[:-1])
+ rettype=rettype.strip()
+ self.outFile.write("%s %s("%(rettype, name))
+ params = cmd.elem.findall('param')
+ plist=[]
+ for param in params:
+ paramlist = ([t for t in param.itertext()])
+ paramtype = ''.join(paramlist[:-1])
+ paramname = paramlist[-1]
+ plist.append((paramtype, paramname))
+ Comma=""
+ if len(plist):
+ for ptype, pname in plist:
+ self.outFile.write("%s%s%s_"%(Comma, ptype, pname))
+ Comma=", "
else:
- if staticwrappers :
- print 'static',
- print returntype + ' ' + funcname + 'Wrapper(' + arglist + ')'
- print '{'
+ self.outFile.write("void")
- stringname = funcname
+ self.outFile.write(")\n{\n")
-#
-# special case: Windows OpenGL implementations are far more likely to have GL_ARB_window_pos than GL_MESA_window_pos,
-# so arrange for the wrapper to use the ARB strings to find functions...
-#
+ self.outFile.write(' typedef %s (* PFN%sPROC)(' % (rettype, name.upper()))
- m2 = r3.search(funcname)
- if m2 :
- stringname = stringname.replace('MESA','ARB')
+ if len(plist):
+ Comma=""
+ for ptype, pname in plist:
+ self.outFile.write("%s %s %s_"%(Comma, ptype, pname))
+ Comma=", "
+ else:
+ self.outFile.write("void")
-#
-# special case: likewise, implementations are more likely to have GL_ARB_vertex_program than GL_NV_vertex_program,
-# especially if they are not NV implementations, so arrange for the wrapper to use ARB strings to find functions
-#
+ self.outFile.write(');\n')
- m3 = r4.search(funcname)
- if m3 :
- stringname = stringname.replace('NV','ARB')
- m4 = r5.search(funcname)
- if m4 :
- stringname = stringname.replace('NV','ARB')
-
- pfntypename = 'PFN' + funcname.upper() + 'PROC'
-
- if returntype.lower() == 'void' :
- print ' RESOLVE(' + pfntypename + ', "' + stringname + '");'
- print ' if (glxWinDebugSettings.enable' + prefix.upper() + 'callTrace) ErrorF("'+ funcname + '\\n");'
- print ' RESOLVED_PROC(' + pfntypename + ')(',
- else :
- print ' RESOLVE_RET(' + pfntypename + ', "' + stringname + '", FALSE);'
- print ' if (glxWinDebugSettings.enable' + prefix.upper() + 'callTrace) ErrorF("'+ funcname + '\\n");'
- print ' return RESOLVED_PROC(' + pfntypename + ')(',
-
- if arglist != 'void' :
- print wrappers[w]['arglist_use'],
-
- print ');'
- print "}\n"
-
-
-# generate function to setup the dispatch table, which sets each
-# dispatch table entry to point to it's wrapper function
-# (assuming we were able to make one)
-
-if dispatchheader :
- print 'void glWinSetupDispatchTable(void)'
- print '{'
- print ' static struct _glapi_table *disp = NULL;'
- print ''
- print ' if (!disp)'
- print ' {'
- print ' disp = calloc(sizeof(void *), _glapi_get_dispatch_table_size());'
- print ' assert(disp);'
-
- for d in sorted(dispatch.keys()) :
- if wrappers.has_key(d) :
- print ' SET_'+ d + '(disp, (void *)' + prefix + d + 'Wrapper);'
- else :
- print '#warning No wrapper for ' + prefix + d + ' !'
-
- print ' }'
- print ''
- print ' _glapi_set_dispatch(disp);'
- print '}'
+ if rettype.lower()=="void":
+ self.outFile.write(' RESOLVE(PFN%sPROC, "%s");\n'%(name.upper(), name))
+ self.outFile.write(' RESOLVED_PROC(')
+ else:
+ self.outFile.write(' RESOLVE_RET(PFN%sPROC, "%s", 0);\n'%(name.upper(), name))
+ self.outFile.write(' return RESOLVED_PROC(')
+
+ Comma=""
+ for ptype, pname in plist:
+ self.outFile.write("%s%s_"%(Comma, pname))
+ Comma=", "
+
+ self.outFile.write(" );\n}\n\n")
+
+def genHeaders():
+ outFile = open(outFilename,"w")
+
+ if preresolve:
+ gen = PreResolveOutputGenerator(errFile=errWarn,
+ warnFile=errWarn,
+ diagFile=diag)
+ gen.outFile=outFile
+ reg.setGenerator(gen)
+ reg.apiGen(genOpts)
+
+ if wrapper:
+ gen = WrapperOutputGenerator(errFile=errWarn,
+ warnFile=errWarn,
+ diagFile=diag)
+ gen.outFile=outFile
+ reg.setGenerator(gen)
+ reg.apiGen(genOpts)
+
+ if shim:
+ gen = ShimOutputGenerator(errFile=errWarn,
+ warnFile=errWarn,
+ diagFile=diag)
+ gen.outFile=outFile
+ reg.setGenerator(gen)
+ reg.apiGen(genOpts)
+
+ if thunk:
+ gen = ThunkOutputGenerator(errFile=errWarn,
+ warnFile=errWarn,
+ diagFile=diag)
+ gen.outFile=outFile
+ reg.setGenerator(gen)
+ reg.apiGen(genOpts)
+
+
+ if thunkdefs:
+ gen = ThunkDefsOutputGenerator(errFile=errWarn,
+ warnFile=errWarn,
+ diagFile=diag)
+ gen.outFile=outFile
+ reg.setGenerator(gen)
+ reg.apiGen(genOpts)
+
+ outFile.close()
+
+genHeaders()