示例#1
0
def wrap_struct(functionName):
    params = apiutil.Parameters(functionName)
    argstring = apiutil.MakeDeclarationString(params)
    extendedArgstring = argstring
    props = apiutil.Properties(functionName)
    if "useclient" in props or "pixelstore" in props:
        extendedArgstring += ", CRClientState *c"

    # We'll keep track of all the parameters that require pointers.
    # They'll require special handling later.
    (pointers, pointername, pointerarg, pointertype, pointersize,
     pointercomment) = GetPointerInfo(functionName)

    # Start writing the header
    print 'struct instance%s {' % (functionName)
    print '	DLMInstanceList *next;'
    print '	DLMInstanceList *stateNext;'
    print '	int cbInstance;'
    print '	VBoxDLOpCode iVBoxOpCode;'
    print '	void (DLM_APIENTRY *execute)(DLMInstanceList *instance, SPUDispatchTable *dispatchTable);'
    for (name, type, vecSize) in params:
        # Watch out for the word "const" (which should be ignored)
        # and for types that end in "*" (which are pointers and need
        # special treatment)
        words = type.split()
        if words[0] == 'const':
            words = words[1:]
        if words[0] != "void":
            print '	%s %s;' % (' '.join(words), name)

    # If any argument was a pointer, we need a special pointer data
    # array.  The pointer data will be stored into this array, and
    # references to the array will be generated as parameters.
    if len(pointers) == 1:
        if pointersize == None:
            print "	/* Oh no - pointer parameter %s found, but no pointer class specified and can't guess */" % pointername
        else:
            if pointersize == 'special':
                print '	%s %s[1];%s' % (pointertype, pointerarg,
                                        pointercomment)
            else:
                print '	%s %s[%s];%s' % (pointertype, pointerarg, pointersize,
                                         pointercomment)
    elif len(pointers) > 1:
        print '	%s %s[1];%s' % (pointertype, pointerarg, pointercomment)

    print '};'

    # Pointers only happen with instances
    if len(pointers) > 1 or (len(pointers) == 1 and pointersize == 'special'):
        print 'int crdlm_pointers_%s(struct instance%s *instance, %s);' % (
            functionName, functionName, extendedArgstring)

    # See if the GL function must sometimes allow passthrough even
    # if the display list is open
    if "checklist" in apiutil.ChromiumProps(functionName):
        print 'int crdlm_checklist_%s(%s);' % (functionName, argstring)

    return
示例#2
0
def wrap_compile(functionName):
    params = apiutil.Parameters(functionName)
    return_type = apiutil.ReturnType(functionName)
    # Make sure the return type is void.  It's nonsensical to compile
    # an element with any other return type.
    if return_type != 'void':
        print '/* Nonsense: DL function %s has a %s return type?!? */' % (
            functionName, return_type)

    # Define a structure to hold all the parameters.  Note that the
    # top parameters must exactly match the DLMInstanceList structure
    # in include/cr_dlm.h, or everything will break horribly.
    # Start off by getting all the pointer info we could ever use
    # from the parameters
    (pointers, pointername, pointerarg, pointertype, pointersize,
     pointercomment) = GetPointerInfo(functionName)

    # Finally, the compile wrapper.  This one will diverge strongly
    # depending on whether or not there are pointer parameters.
    callstring = apiutil.MakeCallString(params)
    argstring = apiutil.MakeDeclarationString(params)
    props = apiutil.Properties(functionName)
    if "useclient" in props or "pixelstore" in props:
        callstring += ", c"
        argstring += ", CRClientState *c"
    print 'void DLM_APIENTRY crDLMCompile%s(%s)' % (functionName, argstring)
    print '{'
    print '    CRDLMContextState *state = CURRENT_STATE();'
    print '    struct instance%s *instance;' % (functionName)

    # The calling SPU is supposed to verify that the element is supposed to be
    # compiled before it is actually compiled; typically, this is done based
    # on whether a glNewList has been executed more recently than a glEndList.
    # But some functions are dual-natured, sometimes being compiled, and sometimes
    # being executed immediately.  We can check for this here.
    if "checklist" in apiutil.ChromiumProps(functionName):
        print '    if (crDLMCheckList%s(%s))' % (
            functionName, apiutil.MakeCallString(params))
        print '    {'
        print '        crdlm_error(__LINE__, __FILE__, GL_INVALID_OPERATION,'
        print '            "this instance of function %s should not be compiled");' % functionName
        print '        return;'
        print '    }'

    if len(pointers) > 1 or pointersize == 'special':
        # Pass NULL, to just allocate space
        print '    instance = crCalloc(sizeof(struct instance%s) + crdlm_pointers_%s(NULL, %s));' % (
            functionName, functionName, callstring)
    else:
        print '    instance = crCalloc(sizeof(struct instance%s));' % (
            functionName)
    print '    if (!instance)'
    print '    {'
    print '        crdlm_error(__LINE__, __FILE__, GL_OUT_OF_MEMORY,'
    print '            "out of memory adding %s to display list");' % (
        functionName)
    print '        return;'
    print '    }'

    # Put in the fields that must always exist
    print '    instance->execute = execute%s;' % functionName

    # Apply all the simple (i.e. non-pointer) parameters
    for index in range(len(params)):
        if index not in pointers:
            name = params[index][0]
            print '    instance->%s = %s;' % (name, name)

    # We need to know instance size in bytes in order to save its state later.
    print '    instance->cbInstance = sizeof(struct instance%s);' % functionName

    # Set OPCODE.
    print '    instance->iVBoxOpCode = VBOX_DL_OPCODE_%s;' % functionName

    # If there's a pointer parameter, apply it.
    if len(pointers) == 1:

        print '    if (%s == NULL)' % (params[pointers[0]][0])
        print '        instance->%s = NULL;' % (params[pointers[0]][0])
        print '    else'
        print '        instance->%s = instance->%s;' % (params[pointers[0]][0],
                                                        pointerarg)

        if pointersize == 'special':
            print '    instance->cbInstance += crdlm_pointers_%s(instance, %s);' % (
                functionName, callstring)
        else:
            print '    crMemcpy((void *)instance->%s, (void *) %s, %s*sizeof(%s));' % (
                params[pointers[0]][0], params[pointers[0]][0], pointersize,
                pointertype)
    elif len(pointers) == 2:
        # this seems to work
        print '    instance->cbInstance += crdlm_pointers_%s(instance, %s);' % (
            functionName, callstring)
    elif len(pointers) > 2:
        print "#error don't know how to handle pointer parameters for %s" % (
            functionName)

    # Add the element to the current display list
    AddInstanceToList('    ')
    # If the element is a state-changing element, add it to the current state list
    if apiutil.SetsTrackedState(functionName):
        AddInstanceToStateList('    ')
    print '}'
示例#3
0
            if index != vecSize - 1:
                print(",", end=" ")
        print(");")
        print("#endif")
    else:
        print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" %
              (vec_func, vecType))


keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")

#
# Generate unpack functions for all the simple functions.
#
for func_name in keys:
    if (not "pack" in apiutil.ChromiumProps(func_name)
            or apiutil.FindSpecial("unpacker", func_name)):
        continue

    params = apiutil.Parameters(func_name)
    return_type = apiutil.ReturnType(func_name)

    packet_length = apiutil.PacketLength(params)
    print("static void crUnpack%s(PCrUnpackerState pState)" % func_name)
    print("{")
    if ("get" in apiutil.Properties(func_name)):
        print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" %
              getWritebackPointerOffset(return_type, params))
    elif packet_length != 0:
        print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % packet_length)
示例#4
0
if mode == 'header':
    print """
/* auto-generated CheckList functions begin here.  There is one for each
 * function that has a dual nature: even when there's an active glNewList,
 * sometimes they are compiled into the display list, and sometimes they
 * are treated like a control function.  The CheckList function will
 * return TRUE if the function should really be compiled into a display
 * list.  The calling SPU is responsible for checking this; but the
 * DLM will also print an error if it detects an invalid use.
 */
"""
elif mode == 'defs':
    pass

for func_name in keys:
    if "checklist" in apiutil.ChromiumProps(func_name):
        params = apiutil.Parameters(func_name)
        argstring = apiutil.MakeDeclarationString(params)
        if mode == 'header':
            print 'int DLM_APIENTRY crDLMCheckList%s(%s);' % (func_name,
                                                              argstring)
        elif mode == 'defs':
            print "crDLMCheckList%s" % func_name

if mode == 'header':
    print """
#ifdef __cplusplus
}
#endif

#endif /* CR_DLM_H */"""
示例#5
0
apiutil.CopyrightC()

print("""
#include "cr_debugopcodes.h"
#include <stdio.h>
""")

print("""void crDebugOpcodes( FILE *fp, unsigned char *ptr, unsigned int num_opcodes )
{
\tunsigned int i;
\tfor (i = 0; i < num_opcodes; i++)
\t{
\t\tswitch(*(ptr--))
\t\t{
""")

keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
keys.sort()

for func_name in keys:
	if "pack" in apiutil.ChromiumProps(func_name):
		print('\t\tcase %s:' % apiutil.OpcodeName( func_name ))
		print('\t\t\tfprintf(fp, "%s\\n"); ' % apiutil.OpcodeName( func_name ))
		print( '\t\t\tbreak;')

print("""
\t\t}
\t}
}
""")
示例#6
0
def GenerateEntrypoints():

    #apiutil.CopyrightC()

    # Get sorted list of dispatched functions.
    # The order is very important - it must match cr_opcodes.h
    # and spu_dispatch_table.h
    print '%include "iprt/asmdefs.mac"'
    print ""
    print "%ifdef RT_ARCH_AMD64"
    print "extern glim"
    print "%else ; X86"
    print "extern glim"
    print "%endif"
    print ""

    keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")

    for index in range(len(keys)):
        func_name = keys[index]
        if apiutil.Category(func_name) == "Chromium":
            continue
        if apiutil.Category(func_name) == "VBox":
            continue

        print "BEGINPROC_EXPORTED gl%s" % func_name
        print "%ifdef RT_ARCH_AMD64"
        print "\tmov \trax, qword glim+%d" % (8 * index)
        print "\tjmp \t[rax]"
        print "%else ; X86"
        print "\tmov \teax, dword glim+%d" % (4 * index)
        print "\tjmp \t[eax]"
        print "%endif"
        print "ENDPROC gl%s" % func_name
        print ""

    print ';'
    print '; Aliases'
    print ';'

    # Now loop over all the functions and take care of any aliases
    allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt")
    for func_name in allkeys:
        if "omit" in apiutil.ChromiumProps(func_name):
            continue

        if func_name in keys:
            # we already processed this function earlier
            continue

        # alias is the function we're aliasing
        alias = apiutil.Alias(func_name)
        if alias:
            # this dict lookup should never fail (raise an exception)!
            index = keys.index(alias)
            print "BEGINPROC_EXPORTED gl%s" % func_name
            print "%ifdef RT_ARCH_AMD64"
            print "\tmov \trax, qword glim+%d" % (8 * index)
            print "\tjmp \t[rax]"
            print "%else ; X86"
            print "\tmov \teax, dword glim+%d" % (4 * index)
            print "\tjmp \t[eax]"
            print "%endif"
            print "ENDPROC gl%s" % func_name
            print ""

    print ';'
    print '; No-op stubs'
    print ';'

    # Now generate no-op stub functions
    for func_name in allkeys:
        if "stub" in apiutil.ChromiumProps(func_name):
            print "BEGINPROC_EXPORTED gl%s" % func_name
            print "\tleave"
            print "\tret"
            print "ENDPROC gl%s" % func_name
            print ""
示例#7
0
generatedFunctions = []

for func_name in apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt"):
    if apiutil.FindSpecial("expando", func_name):
        allFunctions.append(func_name)
    elif apiutil.CanCompile(func_name) or apiutil.SetsClientState(func_name):
        generatedFunctions.append(func_name)
        allFunctions.append(func_name)

for func_name in generatedFunctions:
    params = apiutil.Parameters(func_name)
    return_type = apiutil.ReturnType(func_name)
    basicCallString = apiutil.MakeCallString(params)
    declarationString = apiutil.MakeDeclarationString(params)
    dlmCallString = basicCallString
    chromiumProps = apiutil.ChromiumProps(func_name)

    needClientState = 0
    if apiutil.UsesClientState(func_name):
        dlmCallString = basicCallString + ", clientState"
        needClientState = 1

    needDL = 0
    if apiutil.CanCompile(func_name):
        needDL = 1

    print 'static %s EXPANDOSPU_APIENTRY expando%s(%s)' % (
        return_type, func_name, declarationString)
    print '{'
    if needDL:
        print '\tGLenum dlMode = crDLMGetCurrentMode();'
def GenerateEntrypoints(hacks=[]):
    """Emit code for all the OpenGL/Chromium entrypoints.
    hacks is an optional list of functions which are special cased.
    """

    apiutil.CopyrightC()

    print('#define GL_GLEXT_PROTOTYPES')
    print('#include <stdio.h>')
    print('#include <stdlib.h>')
    print('#include <GL/gl.h>')
    print('#include "chromium.h"')
    print('#include "stub.h"')
    print('#include "dri_glx.h"')
    print('')
    print('#ifdef __GNUC__')
    print('# if (__GNUC__ << 16) + __GNUC_MINOR__ >= 0x40002')
    print('#  pragma GCC diagnostic ignored "-Wunused-parameter"')
    print('# endif')
    print('#endif')

    # Get sorted list of dispatched functions.
    # The order is very important - it must match cr_opcodes.h
    # and spu_dispatch_table.h
    keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")

    for index in range(len(keys)):
        func_name = keys[index]
        if apiutil.Category(func_name) == "Chromium":
            # this function is defined in stub.c
            continue

        return_type = apiutil.ReturnType(func_name)
        params = apiutil.Parameters(func_name)

        if func_name in hacks:
            print("/* hacked entrypoint: %s */" % func_name)
            if func_name == "TexImage3D":
                # Pretty common: internalformat is GLenum, not GLint
                print(
                    "void glTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )"
                )
                print("{")
                print(
                    "\tglim.TexImage3D( target, level, (GLint) internalformat, width, height, depth, border, format, type, pixels );"
                )
                print("}")
            elif func_name == "TexImage2D":
                # Pretty common: internalformat is GLenum, not GLint
                print(
                    "void glTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )"
                )
                print("{")
                print(
                    "\tglim.TexImage2D( target, level, (GLint) internalformat, width, height, border, format, type, pixels );"
                )
                print("}")
            elif func_name == "TexImage1D":
                # Pretty common: internalformat is GLenum, not GLint
                print(
                    "void glTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )"
                )
                print("{")
                print(
                    "\tglim.TexImage1D( target, level, (GLint) internalformat, width, border, format, type, pixels );"
                )
                print("}")
            elif func_name == "EdgeFlagPointer":
                # second arg is GLboolean instead of GLvoid
                print(
                    "void glEdgeFlagPointer( GLsizei stride, const GLboolean *pointer )"
                )
                print("{")
                print("\tglim.EdgeFlagPointer( stride, pointer );")
                print("}")
            elif func_name == "ProgramParameters4fvNV":
                print(
                    "void glProgramParameters4fvNV( GLenum target, GLuint index, GLuint num, const GLfloat *params )"
                )
                print("{")
                print(
                    "\tglim.ProgramParameters4fvNV( target, index, num, params );"
                )
                print("}")
            elif func_name == "MultiDrawElementsEXT":
                print(
                    "void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)"
                )
                print("{")
                print(
                    "\tglim.MultiDrawElementsEXT(mode, count,type, indices, primcount);"
                )
                print("}")
            elif func_name == "ProgramParameters4dvNV":
                print(
                    "void glProgramParameters4dvNV( GLenum target, GLuint index, GLuint num, const GLdouble *params )"
                )
                print("{")
                print(
                    "\tglim.ProgramParameters4dvNV( target, index, num, params );"
                )
                print("}")
        else:
            # the usual path
            print("%s VBOXGLTAG(gl%s)(%s);" %
                  (return_type, func_name,
                   apiutil.MakeDeclarationString(params)))
            print("")
            print("%s VBOXGLTAG(gl%s)(%s)" %
                  (return_type, func_name,
                   apiutil.MakeDeclarationString(params)))
            print("{")
            print("\t", end="")
            if return_type != "void":
                print("return ", end=" ")
            print("glim.%s(%s);" % (func_name, apiutil.MakeCallString(params)))
            print("}")
            print("")

    print('/*')
    print('* Aliases')
    print('*/')

    # Now loop over all the functions and take care of any aliases
    allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt")
    for func_name in allkeys:
        if "omit" in apiutil.ChromiumProps(func_name):
            continue

        if func_name in keys:
            # we already processed this function earlier
            continue

        # alias is the function we're aliasing
        alias = apiutil.Alias(func_name)
        if alias:
            if func_name in hacks:
                print("/* hacked entrypoint: %s */" % func_name)
                if func_name == "MultiDrawArrays":
                    print(
                        "void glMultiDrawArrays( GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount )"
                    )
                    print("{")
                    print(
                        "\tglim.MultiDrawArraysEXT( mode, (GLint*)first, (GLsizei*)count, primcount );"
                    )
                    print("}")
                elif func_name == "BufferData":
                    print(
                        "void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)"
                    )
                    print("{")
                    print("\tglim.BufferDataARB(target, size, data, usage);")
                    print("}")
                elif func_name == "BufferSubData":
                    print(
                        "void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)"
                    )
                    print("{")
                    print(
                        "\tglim.BufferSubDataARB(target, offset, size, data);")
                    print("}")
                elif func_name == "GetBufferSubData":
                    print(
                        "void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data)"
                    )
                    print("{")
                    print(
                        "\tglim.GetBufferSubDataARB(target, offset, size, data);"
                    )
                    print("}")
            else:
                return_type = apiutil.ReturnType(func_name)
                params = apiutil.Parameters(func_name)
                print("%s VBOXGLTAG(gl%s)(%s);" %
                      (return_type, func_name,
                       apiutil.MakeDeclarationString(params)))
                print("")
                print("%s VBOXGLTAG(gl%s)(%s)" %
                      (return_type, func_name,
                       apiutil.MakeDeclarationString(params)))
                print("{")
                print("\t", end="")
                if return_type != "void":
                    print("return ", end=" ")
                print("glim.%s(%s);" % (alias, apiutil.MakeCallString(params)))
                print("}")
                print("")

    print('/*')
    print('* No-op stubs')
    print('*/')

    # Now generate no-op stub functions
    for func_name in allkeys:
        if "stub" in apiutil.ChromiumProps(func_name):
            return_type = apiutil.ReturnType(func_name)
            params = apiutil.Parameters(func_name)

            print("%s VBOXGLTAG(gl%s)(%s);" %
                  (return_type, func_name,
                   apiutil.MakeDeclarationString(params)))
            print("")
            print("%s VBOXGLTAG(gl%s)(%s)" %
                  (return_type, func_name,
                   apiutil.MakeDeclarationString(params)))
            print("{")
            if return_type != "void":
                print("return (%s) 0" % return_type)
            print("}")
            print("")
示例#9
0
def GenerateEntrypoints():

    apiutil.CopyrightC()

    print '#include "chromium.h"'
    print '#include "stub.h"'
    print ''
    print '#define NAKED __declspec(naked)'
    print '#define UNUSED(x) ((void)(x))'
    print ''

    # Get sorted list of dispatched functions.
    # The order is very important - it must match cr_opcodes.h
    # and spu_dispatch_table.h
    keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")

    for index in range(len(keys)):
        func_name = keys[index]
        if apiutil.Category(func_name) == "Chromium":
            continue
        if apiutil.Category(func_name) == "VBox":
            continue

        return_type = apiutil.ReturnType(func_name)
        params = apiutil.Parameters(func_name)

        print "NAKED %s cr_gl%s( %s )" % (
            return_type, func_name, apiutil.MakeDeclarationString(params))
        print "{"
        print "\t__asm jmp [glim.%s]" % func_name
        for (name, type, vecSize) in params:
            print "\tUNUSED( %s );" % name
        print "}"
        print ""

    print '/*'
    print '* Aliases'
    print '*/'

    # Now loop over all the functions and take care of any aliases
    allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt")
    for func_name in allkeys:
        if "omit" in apiutil.ChromiumProps(func_name):
            continue

        if func_name in keys:
            # we already processed this function earlier
            continue

        # alias is the function we're aliasing
        alias = apiutil.Alias(func_name)
        if alias:
            return_type = apiutil.ReturnType(func_name)
            params = apiutil.Parameters(func_name)
            print "NAKED %s cr_gl%s( %s )" % (
                return_type, func_name, apiutil.MakeDeclarationString(params))
            print "{"
            print "\t__asm jmp [glim.%s]" % alias
            for (name, type, vecSize) in params:
                print "\tUNUSED( %s );" % name
            print "}"
            print ""

    print '/*'
    print '* No-op stubs'
    print '*/'

    # Now generate no-op stub functions
    for func_name in allkeys:
        if "stub" in apiutil.ChromiumProps(func_name):
            return_type = apiutil.ReturnType(func_name)
            params = apiutil.Parameters(func_name)
            print "NAKED %s cr_gl%s( %s )" % (
                return_type, func_name, apiutil.MakeDeclarationString(params))
            print "{"
            if return_type != "void":
                print "return (%s) 0" % return_type
            print "}"
            print ""

keys = apiutil.GetAllFunctionsAndOmittedAliases(sys.argv[1]+"/APIspec.txt")
for func_name in keys:
    if "Chromium" == apiutil.Category(func_name):
        continue
    if "VBox" == apiutil.Category(func_name):
        continue
    if func_name == "BoundsInfoCR":
        continue
    if "GL_chromium" == apiutil.Category(func_name):
        pass #continue

    # alias is the function we're aliasing
    proc_name = func_name
    if "omit" in apiutil.ChromiumProps(func_name):
        alias = apiutil.Alias(func_name)
        if alias:
            proc_name = alias

    wrap = apiutil.GetCategoryWrapper(func_name)
    name = "gl" + func_name
    address = "cr_gl" + proc_name
    if wrap:
        print('#ifdef CR_%s' % wrap)
    print('\t{ "%s", (CR_PROC) %s },' % (name, address))
    if wrap:
        print('#endif')


print("\t/* Chromium binding/glue functions */")
示例#11
0
#ifdef WINDOWS
#define PACK_APIENTRY __stdcall
#else
#define PACK_APIENTRY
#endif

#ifdef __cplusplus
extern "C" {
#endif
"""

keys = apiutil.GetDispatchedFunctions()

for func_name in keys:
    if ("pack" in apiutil.ChromiumProps(func_name)
            or "extpack" in apiutil.ChromiumProps(func_name)
            or apiutil.NonVectorFunction(func_name) != ''
            or apiutil.FindSpecial('packer', func_name)):

        # OK, generate a crPackFooBar() prototype for this function
        return_type = apiutil.ReturnType(func_name)
        args = apiutil.Parameters(func_name)
        if return_type != 'void':
            if apiutil.IsPointer(return_type):
                args.append(("return_value", return_type, 0))
            else:
                args.append(("return_value", return_type + "*", 0))
        elif "pixelstore" in apiutil.Properties(func_name):
            args.append(("packstate", "const CRPixelPackState *", 0))
示例#12
0
def GenerateEntrypoints():

	apiutil.CopyrightC()

	# Get sorted list of dispatched functions.
	# The order is very important - it must match cr_opcodes.h
	# and spu_dispatch_table.h
	keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt")

	for index in range(len(keys)):
		func_name = keys[index]
		if apiutil.Category(func_name) == "Chromium":
			continue

		print "\t.align 4"
		print ".globl gl%s" % func_name
		print "\t.type gl%s,@function" % func_name
		print "gl%s:" % func_name
		print "\tmovl glim+%d, %%eax" % (4*index)
		print "\tjmp *%eax"
		print ""


	print '/*'
	print '* Aliases'
	print '*/'

	# Now loop over all the functions and take care of any aliases
	allkeys = apiutil.GetAllFunctions("../glapi_parser/APIspec.txt")
	for func_name in allkeys:
		if "omit" in apiutil.ChromiumProps(func_name):
			continue

		if func_name in keys:
			# we already processed this function earlier
			continue

		# alias is the function we're aliasing
		alias = apiutil.Alias(func_name)
		if alias:
			# this dict lookup should never fail (raise an exception)!
			index = keys.index(alias)
			print "\t.align 4"
			print ".globl gl%s" % func_name
			print "\t.type gl%s,@function" % func_name
			print "gl%s:" % func_name
			print "\tmovl glim+%d, %%eax" % (4*index)
			print "\tjmp *%eax"
			print ""


	print '/*'
	print '* No-op stubs'
	print '*/'

	# Now generate no-op stub functions
	for func_name in allkeys:
		if "stub" in apiutil.ChromiumProps(func_name):
			print "\t.align 4"
			print ".globl gl%s" % func_name
			print "\t.type gl%s,@function" % func_name
			print "gl%s:" % func_name
			print "\tleave"
			print "\tret"
			print ""
示例#13
0
def PrintFunc(func_name, params, is_swapped, can_have_pointers):
    """Emit a packer function."""
    if is_swapped:
        print('void PACK_APIENTRY crPack%sSWAP(%s)' %
              (func_name,
               apiutil.MakeDeclarationStringWithContext(
                   'CR_PACKER_CONTEXT', params)))
    else:
        print('void PACK_APIENTRY crPack%s(%s)' %
              (func_name,
               apiutil.MakeDeclarationStringWithContext(
                   'CR_PACKER_CONTEXT', params)))
    print('{')
    print('\tCR_GET_PACKER_CONTEXT(pc);')

    # Save original function name
    orig_func_name = func_name

    # Convert to a non-vector version of the function if possible
    func_name = apiutil.NonVectorFunction(func_name)
    if not func_name:
        func_name = orig_func_name

    # Check if there are any pointer parameters.
    # That's usually a problem so we'll emit an error function.
    nonVecParams = apiutil.Parameters(func_name)
    bail_out = 0
    for (name, type, vecSize) in nonVecParams:
        if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers:
            bail_out = 1
    if bail_out:
        for (name, type, vecSize) in nonVecParams:
            print('\t(void)%s;' % (name))
        print('\tcrError ( "%s needs to be special cased %d %d!");' %
              (func_name, vecSize, can_have_pointers))
        print('\t(void) pc;')
        print('}')
        # XXX we should really abort here
        return

    if "extpack" in apiutil.ChromiumProps(func_name):
        is_extended = 1
    else:
        is_extended = 0

    print("\tunsigned char *data_ptr;")
    print('\t(void) pc;')
    #if func_name == "Enable" or func_name == "Disable":
    #   print "\tCRASSERT(!pc->buffer.geometry_only); /* sanity check */"

    for index in range(0, len(params)):
        (name, type, vecSize) = params[index]
        if vecSize > 0 and func_name != orig_func_name:
            print("    if (!%s) {" % name)
            # Know the reason for this one, so avoid the spam.
            if orig_func_name != "SecondaryColor3fvEXT":
                print("        crDebug(\"App passed NULL as %s for %s\");" %
                      (name, orig_func_name))
            print("        return;")
            print("    }")

    packet_length = apiutil.PacketLength(nonVecParams)

    if packet_length == 0 and not is_extended:
        print("\tCR_GET_BUFFERED_POINTER_NO_ARGS(pc);")
    elif func_name[:9] == "Translate" or func_name[:5] == "Color":
        # XXX WTF is the purpose of this?
        if is_extended:
            packet_length += 8
        print("\tCR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, %d, GL_TRUE);" %
              packet_length)
    else:
        if is_extended:
            packet_length += 8
        print("\tCR_GET_BUFFERED_POINTER(pc, %d);" % packet_length)
    UpdateCurrentPointer(func_name)

    if is_extended:
        counter = 8
        print(WriteData(0, 'GLint', packet_length, is_swapped))
        print(
            WriteData(4, 'GLenum', apiutil.ExtendedOpcodeName(func_name),
                      is_swapped))
    else:
        counter = 0

    # Now emit the WRITE_() macros for all parameters
    for index in range(0, len(params)):
        (name, type, vecSize) = params[index]
        # if we're converting a vector-valued function to a non-vector func:
        if vecSize > 0 and func_name != orig_func_name:
            ptrType = apiutil.PointerType(type)
            for i in range(0, vecSize):
                print(
                    WriteData(counter + i * apiutil.sizeof(ptrType), ptrType,
                              "%s[%d]" % (name, i), is_swapped))
            # XXX increment counter here?
        else:
            print(WriteData(counter, type, name, is_swapped))
            if apiutil.IsPointer(type):
                counter += apiutil.PointerSize()
            else:
                counter += apiutil.sizeof(type)

    # finish up
    if is_extended:
        print("\tWRITE_OPCODE(pc, CR_EXTEND_OPCODE);")
    else:
        print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName(func_name))

    if "get" in apiutil.Properties(func_name):
        print('\tCR_CMDBLOCK_CHECK_FLUSH(pc);')

    print('\tCR_UNLOCK_PACKER_CONTEXT(pc);')
    print('}\n')
示例#14
0
print ""
print "/* DO NOT EDIT - THIS FILE GENERATED BY THE opcodes.py SCRIPT */"
print ""
print "#ifndef CR_OPCODES_H"
print "#define CR_OPCODES_H"
print ""

keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")
assert len(keys) > 0

print "/* Functions with no return value and input-only parameters */"
print "typedef enum {"

enum_index = 0
for func in keys:
    if "pack" in apiutil.ChromiumProps(func):
        print "\t%s = %d," % (apiutil.OpcodeName(func), enum_index)
        enum_index = enum_index + 1

if enum_index > 255:
    # This would have saved Mike some grief if it had been here earlier.
    print >> sys.stderr, "You have more than 255 opcodes!  You've been adding functions to"
    print >> sys.stderr, "glapi_parser/APIspec!  Each new function you add"
    print >> sys.stderr, "gets an opcode assigned to it.  Fortunately for you, we have"
    print >> sys.stderr, "an ``extend'' opcode.  Please mark the function as"
    print >> sys.stderr, "'extpack' in APIspec so as to keep the main opcode pool"
    print >> sys.stderr, "less than 255!  THIS IS A CATASTROPHIC FAILURE, and I WILL NOT CONTINUE!"
    print >> sys.stderr, "I'm putting an error in the generated header file so you won't miss"
    print >> sys.stderr, "this even if you're doing a 'make -k.'"
    print "#error -- more than 255 opcodes!"
    sys.exit(-1)
示例#15
0
def PrintFunc( func_name, params,  can_have_pointers,f):
	f.write( 'void crPackTest%s(void)\n' % (func_name))
	f.write( '{\n')

	# Save original function name
	orig_func_name = func_name

	# Convert to a non-vector version of the function if possible
	#func_name = apiutil.NonVectorFunction( func_name )
	if not func_name:
		func_name = orig_func_name

	# Check if there are any pointer parameters.
	# That's usually a problem so we'll emit an error function.
	nonVecParams = apiutil.Parameters(func_name)
	return_type = apiutil.ReturnType(func_name)

	bail_out = 0
	for (name, type, vecSize) in nonVecParams:
		if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers:
			if vecSize == 0:
				if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *"  or type == "const GLubyte *":
					f.write( "\t%s %s[100000];/* VECP7b (%s,%s)*/\n" % (type,name,type,name))
				elif   type == "GLfloat *" or type == "GLint *"  or type == "GLdouble *" or type == "GLuint *"  or  type == "GLushort *":
					f.write( "\t%s %s[100000];/* VECP7a (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name))
				elif  type == "const GLfloat *" or type == "const GLint *"  or type == "const GLdouble *" or type == "const GLuint *" or type == "const GLushort *":
					f.write( "\t%s %s[100000];/* VECP7b (%s,%s)*/\n" % (type[6:type.index('*')],name,type,name))
					#f.write( "\t%s %s[100000];/* VECP7a */\n" % (type,name))
			bail_out = 1
		elif apiutil.IsPointer(type) :
			if vecSize == 0:
				if  type == "GLsizei *" or  type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *" or type == "GLint *" or type == "const GLint *" or type == "const GLfloat *" or type == "GLfloat *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *":
					f.write( "\t%s %s[100000];/* VECP5a (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name))
				else:
					f.write( "\t%s %s[100000];/* VECP5 */\n" % (type,name))
	PerformAction(func_name,f)

#	if bail_out:
#		for (name, type, vecSize) in nonVecParams:
#			print '\t(void)%s;' % (name)
		#
		# Special casing indicates that some arbitrary data appropriate to
		# the call must be supplied
#		f.write( '\tcrDebug ( "%s needs to be special cased %d %d!");\n' % (func_name, vecSize, can_have_pointers))

	if "extpack" in apiutil.ChromiumProps(func_name):
		is_extended = 1
	else:
		is_extended = 0

	counter = 0

	# generate the calls

	if len(params) == 0:
		argstr = ""
	else:
		argstr = ", "

	printfstr = ""
	argstr = ""
	
	if return_type != 'void':
		# Yet another gross hack for glGetString
		if string.find( return_type, '*' ) == 1:
			return_type = return_type + " *"
		f.write( '\t%s return_val;\n' % return_type)


	# At this point all of the declarations have been generated
	# The argument lists with the various parameter values have to
	# be permuted

	# Generate the lists to be permuted
	argLists  = GenParmLists(func_name,f)

	#print argLists
	#print len(argLists)

	# 
	# Now iterate over the permuted argument lists generating gl calls with
	# the permuted arguments
	#

	for ki in range(len(argLists)):
		argList = argLists[ki]
		if len(argList) > 0:
			allargstr = ""
			for i in range(len(argList)):
				#print argList[i]
				q = argList[i]

				if return_type != 'void':
					f.write( '\treturn_val = gl%s(' % func_name)
				else:
					f.write( '\tgl%s(' % func_name)
				ll = 0
				nparms = len(params)
				if len(q) > nparms:
					nparms = len(q)
				#for k in range(len(q)):
				for k in range(nparms):
					(name, type, vecSize) = params[k]

					# ordinary typed parameter, or vector of unknown size
					#
					# TODO Vector arg
					#
					if vecSize >= 1:
						f.write("%s /* VEC2a */" %  name)
					elif apiutil.IsPointer ( type ):
						# POINTER
						f.write( "\t(%s)%s /* VEC3a */\n" % (type,name))
#						(format_str, cast) = printf_mapping[type]
#						printfstr += format_str
#						cast_str = ''
#						if cast != '':
#							cast_str = '(%s)' % cast
#						if type == 'GLenum':
#							argstr += "%s" % q[k]
#						elif type == 'GLboolean':
#							argstr += "%s" % q[k]
#						else:
#							argstr += '%s %s' % (cast_str,q[k])
					elif printf_mapping.has_key( type ):
						(format_str, cast) = printf_mapping[type]
						printfstr += format_str
						cast_str = ''
						if cast != '':
							cast_str = '(%s)' % cast
						if type == 'GLenum':
							argstr += "%s" % q[k]
						elif type == 'GLboolean':
							argstr += "%s" % q[k]
						else:
							argstr += '%s %s' % (cast_str,q[k])
					elif type.find( "*" ):
						printfstr += "%p"
						argstr += "(void *)"
						argstr += '%s' % q[k]
					else:
						argstr = ""
						printfstr = "???"
						break;
				

					if ll != len(params) - 1:
						printfstr += ", "
						argstr += ", "

					ll += 1

					f.write( '%s' % argstr)
					allargstr = allargstr + argstr
					argstr = ""
					printfstr = ""

				f.write( ');\n\tif(errChk)\n\t\tprintError(\"gl%s(%s)\");\n' % (func_name,allargstr))
				if verbose:
					f.write('\tif (verbose)\n\t\tcrDebug(\"gl%s( %s )\");\n'  % (func_name,allargstr))
				allargstr = ""
				#f.write( ');\n')
		else:
			if return_type != 'void':
				f.write( '\treturn_val = gl%s();\n\tif(errChk)\n\t\tprintError(\"gl(%s)\");\n' % (func_name,func_name))
			else:
				f.write( '\tgl%s();\n\tif(errChk)\n\t\tprintError(\"gl(%s)\");\n' % (func_name,func_name))
				if verbose:
					f.write('\tif (verbose)\n\t\tcrDebug(\"gl%s( )\");\n'  % (func_name))
		
	# finish up
	f.write( '}\n' )