Пример #1
0
def PrintBodies(func_name,f,no_special, gentables):
	#print "func_name = %s  no_special = %d" % (func_name, no_special)
	if no_special == 1:
		if apiutil.FindSpecial( "packertest", func_name ):
			return

	if not allfuncs:
		if not apiutil.HasPackOpcode(func_name):
			return

	pointers_ok = 0

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

	if "get" in apiutil.Properties(func_name):
		pointers_ok = 1

	if func_name == 'Writeback':
		pointers_ok = 1

	#print "func_name = %s pointers_ok = %d no_special = %d" % (func_name, pointers_ok,no_special)
	#print params
	if gentables == 1:
		PrintTableFunc( func_name, params, pointers_ok ,f)
	else:
		PrintFunc( func_name, params, pointers_ok ,f)
Пример #2
0
def MakeVectorCall(return_type, func_name, arg_type):
    """Convert a call like glVertex3f to glVertex3fv."""
    vec_func = apiutil.VectorFunction(func_name)
    params = apiutil.Parameters(vec_func)
    assert len(params) == 1
    (arg_name, vecType, vecSize) = params[0]

    if arg_type == "GLdouble" or arg_type == "GLclampd":
        print "#ifdef CR_UNALIGNED_ACCESS_OKAY"
        print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func,
                                                               vecType)
        print "#else"
        for index in range(0, vecSize):
            print "\tGLdouble v" + ` index ` + " = READ_DOUBLE(", ` index * 8 `, ");"
        if return_type != "void":
            print "\t(void) cr_unpackDispatch.%s(" % func_name,
        else:
            print "\tcr_unpackDispatch.%s(" % func_name,
        for index in range(0, vecSize):
            print "v" + ` index `,
            if index != vecSize - 1:
                print ",",
        print ");"
        print "#endif"
    else:
        print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func,
                                                               vecType)
Пример #3
0
def MakeVectorCall(return_type, func_name, arg_type):
    """Convert a call like glVertex3f to glVertex3fv."""
    vec_func = apiutil.VectorFunction(func_name)
    params = apiutil.Parameters(vec_func)
    assert len(params) == 1
    (arg_name, vecType, vecSize) = params[0]

    if arg_type == "GLdouble" or arg_type == "GLclampd":
        print("#ifdef CR_UNALIGNED_ACCESS_OKAY")
        print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" %
              (vec_func, vecType))
        print("#else")
        for index in range(0, vecSize):
            print("\tGLdouble v" + repr(index) + " = READ_DOUBLE(pState, " +
                  repr(index * 8) + ");")
        if return_type != "void":
            print("\t(void) pState->pDispatchTbl->%s(" % func_name, end="")
        else:
            print("\tpState->pDispatchTbl->%s(" % func_name, end="")
        for index in range(0, vecSize):
            print("v" + repr(index), end="")
            if index != vecSize - 1:
                print(",", end=" ")
        print(");")
        print("#endif")
    else:
        print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" %
              (vec_func, vecType))
Пример #4
0
def PrintProto(func_name,f,no_special):
	if no_special == 1:
		if apiutil.FindSpecial( "packertest", func_name ):
			return

	if not allfuncs:
		if not apiutil.HasPackOpcode(func_name):
			return

	pointers_ok = 0

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

	if "Chromium" == apiutil.Category(func_name):
		is_extended = 1
	else:
		is_extended = 0

	if is_extended:
		f.write( "gl%s gl%s_func = (gl%s_t)crGetProcAddress(\"gl%s\");\n" % (func_name,func_name,func_name,func_name))

	if return_type != 'void':
		# Yet another gross hack for glGetString
		if string.find( return_type, '*' ) == -1:
			return_type = return_type + " *"

	#if "get" in apiutil.Properties(func_name):
			#pointers_ok = 1

	if func_name == 'Writeback':
		pointers_ok = 1

	f.write( 'void crPackTest%s (void);\n' % func_name)
Пример #5
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
Пример #6
0
def GenerateNop(func_name):
	return_type = apiutil.ReturnType(func_name);
	params = apiutil.Parameters(func_name)
	print 'static %s GLLOADER_APIENTRY Nop%s(%s)' % (return_type, func_name, apiutil.MakeDeclarationString(params))
	print '{'
	for (name, type, vecSize) in params:
		if name != "":
			print '\t(void) %s;' % name
	if apiutil.ReturnType(func_name) != 'void':
		print '\treturn 0;'
	print '}'
	print ''
Пример #7
0
def wrap_execute(functionName):
    params = apiutil.Parameters(functionName)
    print 'static void execute%s(DLMInstanceList *x, SPUDispatchTable *dispatchTable)' % functionName
    print '{'
    if len(params) > 0:
        print '\tstruct instance%s *instance = (struct instance%s *)x;' % (
            functionName, functionName)
    print '\tif (dispatchTable->%s != NULL) {' % (functionName)
    print '\t\tdispatchTable->%s(%s);' % (functionName,
                                          InstanceCallString(params))
    print '\t}'
    print '\telse {'
    print '\t\tcrWarning("DLM warning: execute%s called with NULL dispatch entry");' % (
        functionName)
    print '\t}'
    print '}'
Пример #8
0
def EmitFunctions():
    offset = 0
    for func_name in keys:
        retType = apiutil.ReturnType(func_name)
        params = apiutil.Parameters(func_name)
        print 'static ' + retType + ' APIHISTOGRAMSPU_APIENTRY'
        print 'histo' + func_name + '(' + apiutil.MakeDeclarationString(
            params) + ')'
        print '{'
        print '\tHistogram[' + str(offset) + '].count++;'
        if retType != 'void':
            print '\treturn '
        print '\tapihistogram_spu.super.' + func_name + '(' + apiutil.MakeCallString(
            params) + ');'
        print '}'
        print ''
        offset += 1
    return
Пример #9
0
def wrap_execute(functionName):

    params = apiutil.Parameters(functionName)
    (pointers, _, pointerarg, _, _, _) = GetPointerInfo(functionName)

    print 'static void execute%s(DLMInstanceList *x, SPUDispatchTable *dispatchTable)' % functionName
    print '{'
    if len(params) > 0:
        print '    struct instance%s *instance = (struct instance%s *)x;' % (functionName, functionName)

    if len(pointers) == 1:
        print '    instance->%s = instance->%s;' % (params[pointers[0]][0], pointerarg)

    print '    if (dispatchTable->%s != NULL)' % (functionName)
    print '        dispatchTable->%s(%s);' % (functionName, InstanceCallString(params))
    print '    else'
    print '        crWarning("DLM warning: execute%s called with NULL dispatch entry");' % (functionName)
    print '}'
Пример #10
0
def PrintDynProto(func_name, f):
	if apiutil.FindSpecial( "packertest", func_name ):
		return

	if not allfuncs:
		if not apiutil.HasPackOpcode(func_name):
			return

	pointers_ok = 0
	params = apiutil.Parameters(func_name)

	if "Chromium" ==  apiutil.Category(func_name):
		is_extended = 1
	else:
		is_extended = 0

	if is_extended:
		f.write( "typedef %s (APIENTRY *gl%s_t) (%s);\n" % (return_type,func_name,apiutil.MakeDeclarationString(params)))
		f.write( "static gl%s_t %s_func;\n" % (func_name,func_name))
Пример #11
0
def GenParmSetLists(func_name):
	pset = apiutil.ParamSet(func_name)
	params = apiutil.Parameters(func_name)
	for index in range(len(params)):
		(name, type, vecSize) = params[index]
	
	returnlist = []
	rlist = []
	if pset != []:
		# number of disjoint sets
			
		for i in range(len(pset)):
			parset = pset[i]
			namelist = parset[0]
			setlist = parset[1:]
			for j in range(len(namelist)):
				returnlist.append((namelist[j],setlist[j]))
			rlist.append(returnlist)
	return rlist
Пример #12
0
def GetPointerInfo(functionName):
    # We'll keep track of all the parameters that require pointers.
    # They'll require special handling later.
    params = apiutil.Parameters(functionName)
    pointers = []
    pointername = ''
    pointerarg = ''
    pointertype = ''
    pointersize = 0
    pointercomment = ''

    index = 0
    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[-1].endswith('*'):
            pointers.append(index)
        index += 1

    # 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:
        index = pointers[0]
        pointername = params[index][0]
        pointerarg = pointername + 'Data'
        pointertype = GetPointerType(params[index][1])
        pointersize = params[index][2]
        if pointersize == 0:
            pointersize = "special"
    elif len(pointers) > 1:
        pointerarg = 'data'
        pointertype = GetPointerType(params[pointers[0]][1])
        for index in range(1, len(pointers)):
            if GetPointerType(params[pointers[index]][1]) != pointertype:
                pointertype = 'GLvoid *'

    return (pointers, pointername, pointerarg, pointertype, pointersize,
            pointercomment)
Пример #13
0
#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))

        if "get" in apiutil.Properties(func_name):
            args.append(("writeback", "int *", 0))

        print 'void PACK_APIENTRY crPack%s( %s );' % (
            func_name, apiutil.MakeDeclarationString(args))
        print 'void PACK_APIENTRY crPack%sSWAP( %s );' % (
            func_name, apiutil.MakeDeclarationString(args))
Пример #14
0
def GenParmLists(func_name,f):

	# Fetch the parameter properties
	params = apiutil.Parameters(func_name)
	return_type = apiutil.ReturnType(func_name)
	if return_type != 'void':
		# Yet another gross hack for glGetString
		if string.find( return_type, '*' ) == -1:
			return_type = return_type + " *"


	#print ""
	#print "FUNC_NAME %s PARAMS %s" %  (func_name,params)
	
	pvec = []
	tvec = []
	rlist = GenParmSetLists(func_name)
	#print "RETURNLIST"
	#print rlist
	#
	# At this point rlist is constructed as
	# 
	#
	#

	fvec = copy.deepcopy(apiutil.ParamProps(func_name))
	vallist = copy.deepcopy(apiutil.ParamList(func_name))
	valinit = copy.deepcopy(apiutil.ParamVec(func_name))
	multiList = []
	if rlist != []:
		for kk in range(len(rlist)):
			#print "RLIST-KK"
			pvec = []
			#print rlist[kk]
			rvec = rlist[kk]
			params = apiutil.Parameters(func_name)
			for index in range(len(params)):
				(name, type, vecSize) = params[index]
				action = apiutil.ParamAction(func_name)

				#print "name = %s type = %s" % (name,type)

				if vecSize >= 1:
					#
					#  Vector arg
					#
					#print "/* VECTOR */"
					f.write( "\t%s %s[%d]; /* VECTOR1 */\n" % (type[0:type.index('*')],name, vecSize))
					# TODO: Add dummy vars to vector/matrix
					tvec = name

				if type == "GLenum":
					#print "name = %s type = %s" % (name,type)
					if rvec != []:
						fvec = rvec
					else:
						fvec = copy.deepcopy(apiutil.ParamProps(func_name))
					#print "fvec = %s" % fvec
					for k in range(len(fvec)):
						d = fvec.pop(0)
						if d[0] == name:
							tvec = d[1]
							break
				elif vallist != []:
					#print "name = %s type = %s" % (name,type)
					vallist = copy.deepcopy(apiutil.ParamList(func_name))
					#print "vallist = %s" % vallist
					for k in range(len(vallist)):
						d = vallist[k]
						(dname,vec) = d
						#print d[0]
						if d[0] == name :
							#print "name = %s (dname,vec) = (%s) %s" % (name,dname,vec)
							tvec = vec
							break;
				elif valinit != []:
					#print "name = %s type = %s" % (name,type)
					valinit = copy.deepcopy(apiutil.ParamVec(func_name))
					#print "valinit = %s" % valinit
					cnt = 0
					d = valinit[k]
					(dname,vec) = d
					#print d[0]
					if d[0] == name :
						#print "name = %s (dname,vec) = (%s) %s" % (name,dname,vec)
						for nint in range(len(vec)):
							f.write("\t%s[%d] = %s;/* VA1 */\n" % (name,nint,vec[nint]))
							#print "\t%s[%d] = %s;\n" % (name,nint,vec[nint])
						break;
				elif range_mapping.has_key( type ):
					#print "name = %s type = %s" % (name,type)
					if rvec != []:
						#print "rvec = %s" % rvec
						fvec = rvec
						#print "fvec = %s" % fvec
						for k in range(len(fvec)):
							d = fvec.pop(0)
							if d[0] == name:
								tvec = d[1]
								break
						else:
							fvec = copy.deepcopy(apiutil.ParamProps(func_name))
					else:
						tvec = range_mapping[type]
				else:
					tvec = [0]
				pvec.append(tvec)
				#print "PVEC.APPEND(%s)" % tvec

			#print "PVEC %s" % pvec
			#print "PVECLEN = %d" % len(pvec)

			#for i in range(len(pvec)):
				#print  pvec[i]

			argLists = permute2(pvec)

			#print argLists
			#print "ARGLIST = %d" % len(argLists)

			#for i in range(len(argLists)):
				#print argLists[i]
			multiList.append(argLists)

	else:
		for index in range(len(params)):
			(name, type, vecSize) = params[index]
			action = apiutil.ParamAction(func_name)

			#print "name = %s type = %s" % (name,type)
			#print valinit

			if vecSize >= 1:
				#
				#  Vector arg
				#
				#print "/* VECTOR */"
				if type[0:5] == "const" :
					f.write( "\t%s %s[%d]; /* VECTOR2a */\n" % (type[6:type.index('*')],name, vecSize))
				else:
					f.write( "\t%s %s[%d]; /* VECTOR2 */\n" % (type[0:type.index('*')],name, vecSize))
				# TODO: Add dummy vars to vector/matrix
				tvec = name

		for index in range(len(params)):
			(name, type, vecSize) = params[index]
			action = apiutil.ParamAction(func_name)

			if type == "GLenum":
				fvec = copy.deepcopy(apiutil.ParamProps(func_name))
				for k in range(len(fvec)):
					d = fvec.pop(0)
					if d[0] == name:
						tvec = d[1]
						break
			elif vallist != []:
				vallist = copy.deepcopy(apiutil.ParamList(func_name))
				for k in range(len(vallist)):
					d = vallist.pop(0)
					if d[0] == name:
						tvec = d[1]
						break;
			elif valinit != []:
				#print "name = %s type = %s" % (name,type)
				valinit = copy.deepcopy(apiutil.ParamVec(func_name))
				#print "valinit = %s" % valinit
				cnt = 0
				for k in range(len(valinit)):
					d = valinit[k]
					(dname,vec) = d
					#print d[0]
					if d[0] == name :
						#print "name = %s (dname,vec) = (%s) %s" % (name,dname,vec)
						for nint in range(len(vec)):
							f.write("\t%s[%d] = (%s)%s;/* VA2 */\n" % (name,nint,type[0:type.index('*')],vec[nint]))
							#print "\t%s[%d] = %s;\n" % (name,nint,vec[nint])
						break;
			elif range_mapping.has_key( type ):
				tvec = range_mapping[type]
			else:
				tvec = [0]
			pvec.append(tvec)
			#print tvec
			#print "PVEC %s" % pvec

		#print "PVEC %s" % pvec
		#print "PVECLEN = %d" % len(pvec)

		#for i in range(len(pvec)):
			#print  pvec[i]

		argLists = permute2(pvec)

		#print argLists
		#print "ARGLIST = %d" % len(argLists)

		#for i in range(len(argLists)):
			#print argLists[i]
		multiList.append(argLists)
	return multiList
Пример #15
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 '}'
Пример #16
0
    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)

    vector_func = apiutil.VectorFunction(func_name)
    if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
        MakeVectorCall(return_type, func_name, params[0][1])
    else:
Пример #17
0
def PrintTableFunc( func_name, params,  can_have_pointers,f):
	"""Emit a packer test function."""
	#print "PrintTableFunc (%s,%s,%d,f)" % (func_name,str(params),can_have_pointers)

	# 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)

	f.write("\nstruct %s_params {\n" % func_name)

	for (name, type, vecSize) in nonVecParams:
		if not apiutil.IsPointer(type) :
			f.write("\t%s %s_%s;\n" % (type,func_name,name))

	if verbose:
		f.write( '\tchar *prgstr;\n')
	f.write( '} %s_tab[] = {\n' % 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


	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]
		ncount = 0
		if len(argList) > 0:
			allargstr = ""
			for i in range(len(argList)):
				#print argList[i]
				q = argList[i]

				ll = 0
				f.write("{ ")
				ncount = ncount + 1
				for k in range(len(q)):
					(name, type, vecSize) = params[k]
					#
					# ordinary typed parameter, or vector of unknown size
					#
					# TODO Vector arg
					#
					#if vecSize >= 1:
						#f.write('%s /* VEC1 */' %  name)
						#f.write( "\t%s %s[%d]; /* VECTOR1 */\n" % (type[0:type.index('*')],name, vecSize))
					#if apiutil.IsPointer ( type ):
						# POINTER
						#f.write( "\t(%s)%s /* VEC3 */" % (type,name))
					if 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):
						printfstr += ", "
						argstr += ", "

					ll += 1

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

				if verbose:
					f.write( '\n\t\"%s\"' % (allargstr))
					#f.write( '\n\t\"%s_tab.%s\"' % (func_name,allargstr))
				allargstr = ""
				f.write( '},\n')
		
	# finish up
	f.write( '};\n\n' )
	f.write( '/* COUNT = %d */\n' % ncount)
	f.write( 'void crPackTest%s(void)\n' % (func_name))
	f.write( '{\n')
	f.write( '\tint i;\n')
	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];/* VECP2b (%s,%s)*/\n" % (type,name,type,name))
				elif  type == "const GLfloat *"  or type == "GLfloat *" or type == "const GLint *" or type == "GLint *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *" or type == "const GLushort *" or type == "GLushort *":
					f.write( "\t%s %s[100000];/* VECP2a (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name))
					#f.write( "\t%s %s[100000];/* VECP2a */\n" % (type,name))
			bail_out = 1
		elif apiutil.IsPointer(type) :
			if vecSize == 0:
				if type == "GLvoid *" or type == "GLvoid **" 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 *"  or type == "const GLushort *" or type == "GLushort *":
					f.write( "\t%s %s[100000];/* VECP9 (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name))
				else:
					f.write( "\tGLubyte %s[100000];/* VECP7 */\n" % name)

	PerformAction(func_name,f)

	f.write('\tfor ( i = 0; i < %d; i++) {\n' % ncount)

	if verbose:
		f.write('\tif (verbose)\n\tcrDebug(\"gl%s( %%s )\",%s_tab[i].prgstr);\n'  % (func_name,func_name))
	if return_type != 'void':
		f.write( '\t\treturn_val = gl%s(' % func_name)
	else:
		f.write( '\t\tgl%s(' % func_name)

	ll = 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( "%s /* VECS2 */\n" % name)
			bail_out = 1
		elif apiutil.IsPointer(type) :
			if vecSize == 0:
				if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *" or type == "GLint *" or type == "const GLint *" or type == "GLfloat *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *":
					f.write( "\t%s/* VECS4 */\n" % name)
				else:
					f.write( "\t%s/* VECS5 */\n" % name)
		else:
			f.write("\t%s_tab[i].%s_%s" % (func_name,func_name,name))
		if ll != len(nonVecParams) -1:
			f.write(', ')
		ll = ll + 1
		
#
	f.write(');\n')
	if return_type != 'void':
		f.write('\n\t\tif(errChk) {\n')
		f.write('\t\t\tchar buf[1024];\n')
		f.write('\t\t\tsprintf(buf,\"gl%s( %%s )\",%s_tab[i].prgstr);\n'  % (func_name,func_name))
		f.write('\t\t\tprintError(buf);\n')
		f.write( '\t}\n')
	else:
		f.write('\n\t\tif(errChk) {\n')
		f.write('\t\t\tchar buf[1024];\n')
		f.write('\t\t\tsprintf(buf,\"gl%s( %%s )\",%s_tab[i].prgstr);\n'  % (func_name,func_name))
		f.write('\t\t\tprintError(buf);\n')
		f.write( '\t}\n')
	f.write( '\t}\n' )
	f.write( '}\n' )
Пример #18
0
"""

keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt")

## We will use the state tracker diff infrastructure to push OpenGL
## state to the new GL stub upon resume. Once computedd differences,
## the Diff Dispatch Table is invoked to perform whatever action you
## want on the diffed state. In our case, we simply want to send
## the state to new GL stub. This script generates s Diff Dispatch
## Table that does just that. It's exceedingly simple for non-pixel
## functions. We need to hack a default packing when shipping pixel 
## functions calls.

for func_name in apiutil.AllSpecials( "packspu_diffpixel" ):
	return_type = apiutil.ReturnType(func_name)
	decl = apiutil.MakeDeclarationString(apiutil.Parameters(func_name))
	print 'extern %s PACKSPU_APIENTRY packspu_Diff%s( %s );' % ( return_type, func_name, decl )

print '\n'

for func_name in apiutil.AllSpecials( "packspu_diffpixel" ):
	return_type = apiutil.ReturnType(func_name)
	params = apiutil.Parameters(func_name)
	print '%s PACKSPU_APIENTRY packspu_Diff%s( %s )' % (return_type, func_name, apiutil.MakeDeclarationString( params ) )
	print '{'
	params.append( ('&defaultPacking', 'blah', 0) )
	print '\tif (pack_spu.swap)'
	print '\t{'
	print '\t\tcrPack%sSWAP( %s );' % (func_name, apiutil.MakeCallString( params ) )
	print '\t}'
	print '\telse'
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("")
Пример #20
0
def PrintFunction(func_name, extSuffix, num_coords, argtype, do_swapped,
                  do_count, do_vector):
    """
	Generate all the functions named crPackVertex[234][dfis][v]BBOX() and
	crPackVertex[234][dfis][v]BBOX_COUNT().
	We also handle glVertexAttrib*ARB.
	Note: func_name should not have an ARB suffix.
	"""

    if do_count:
        countSuffix = "_COUNT"
    else:
        countSuffix = ""

    if do_swapped:
        swapSuffix = "SWAP"
    else:
        swapSuffix = ""

    if func_name[0:12] == "VertexAttrib":
        isVertexAttrib = 1
    else:
        isVertexAttrib = 0

    if argtype[0] == "N":
        normalized = 1
    else:
        normalized = 0

    if argtype == "b" or argtype == "Nb":
        vector_type = "GLbyte"
    elif argtype == "ub" or argtype == "Nub":
        vector_type = "GLubyte"
    elif argtype == "s" or argtype == "Ns":
        vector_type = "GLshort"
    elif argtype == "us" or argtype == "Nus":
        vector_type = "GLushort"
    elif argtype == "i" or argtype == "Ni":
        vector_type = "GLint"
    elif argtype == "ui" or argtype == "Nui":
        vector_type = "GLuint"
    elif argtype == "f":
        vector_type = "GLfloat"
    elif argtype == "d":
        vector_type = "GLdouble"
    else:
        print "type is %s" % argtype
        abort()

    if do_vector:
        if isVertexAttrib:
            func_name = 'VertexAttrib%d%sv' % (num_coords, argtype)
        else:
            func_name = 'Vertex%d%sv' % (num_coords, argtype)

    params = apiutil.Parameters(func_name + extSuffix)

    print 'void PACK_APIENTRY crPack%sBBOX%s%s( %s )' % (
        func_name + extSuffix, countSuffix, swapSuffix,
        apiutil.MakeDeclarationString(params))
    print '{'

    if do_vector:
        # vector version
        packet_length = num_coords * apiutil.sizeof(vector_type)
        if isVertexAttrib:
            packet_length += 4  # for index
        if packet_length % 4 != 0:
            packet_length += 2

    else:
        # non-vector
        packet_length = apiutil.PacketLength(params)
        if isVertexAttrib:
            packet_length += 0  # for index
        if packet_length % 4 != 0:
            packet_length += 2

    print "\tGET_PACKER_CONTEXT(pc);"
    print "\tunsigned char *data_ptr;"

    if normalized:
        if argtype == "Nb":
            t = "B"
        elif argtype == "Ni":
            t = "I"
        elif argtype == "Nui":
            t = "UI"
        elif argtype == "Nub":
            t = "UB"
        elif argtype == "Ns":
            t = "S"
        elif argtype == "Nus":
            t = "US"
        else:
            abort()
        if do_vector:
            print "\tCREATE_%dD_VFLOATS_%s_NORMALIZED();" % (num_coords, t)
        else:
            print "\tCREATE_%dD_FLOATS_%s_NORMALIZED();" % (num_coords, t)
    else:
        if do_vector:
            print "\tCREATE_%dD_VFLOATS();" % num_coords
        else:
            print "\tCREATE_%dD_FLOATS();" % num_coords

    print "\tGET_BUFFERED%s_POINTER( pc, %d );" % (countSuffix, packet_length)

    # Bounding box code
    if isVertexAttrib:
        print "\tif (pc->updateBBOX && index == 0)"
    else:
        print "\tif (pc->updateBBOX)"
    print "\t{"
    if num_coords < 4:
        print "\t\tUPDATE_%dD_BBOX();" % num_coords
    else:
        print "\t\tUPDATE_3D_BBOX();"
    print "\t}"

    if isVertexAttrib:
        print "\tif (index > 0) {"
        t = argtype
        print "\t\tpc->current.c.vertexAttrib.%s%d[index] = data_ptr + 4;" % (
            t, num_coords)
        print "\t\tpc->current.attribsUsedMask |= (1 << index);"
        if do_count:
            print "\t\tpc->current.vtx_count--;"

        print "\t}"

        fname = func_name + extSuffix
        if do_vector:
            # use non-vector opcode
            opcode = apiutil.OpcodeName(func_name[:-1] + extSuffix)
        else:
            opcode = apiutil.OpcodeName(func_name + extSuffix)
    counter = 0

    if do_vector:
        if isVertexAttrib:
            if do_swapped:
                print "\tWRITE_DATA( 0, GLuint, SWAP32(index) );"
            else:
                print "\tWRITE_DATA( 0, GLuint, index );"
            counter += 4
            argname = params[1][0]  # skip 'index' parameter
        else:
            argname = params[0][0]

        for index in range(num_coords):
            print WriteData(counter, vector_type, "%s[%d]" % (argname, index),
                            do_swapped)
            counter += apiutil.sizeof(vector_type)

        if isVertexAttrib:
            if do_vector == 2:
                # this is a bit of a hack
                print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(
                    func_name + "ARB")
            else:
                print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(
                    func_name[:-1] + "ARB")
        else:
            print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(
                func_name[:-1])
    else:
        for index in range(0, len(params)):
            (name, type, vecSize) = params[index]
            print WriteData(counter, type, name, do_swapped)
            counter += apiutil.sizeof(type)

        if isVertexAttrib:
            print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name +
                                                                   "ARB")
        else:
            print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name)

    print '}\n'
Пример #21
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 ""
Пример #22
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')
Пример #23
0
#include "cr_error.h"
#include "cr_mem.h"
#include "cr_net.h"
#include "server_dispatch.h"
#include "server.h"
"""

from get_sizes import *;


funcs = [ 'GetIntegerv', 'GetFloatv', 'GetDoublev', 'GetBooleanv' ]
types = [ 'GLint', 'GLfloat', 'GLdouble', 'GLboolean' ]

for index in range(len(funcs)):
    func_name = funcs[index]
    params = apiutil.Parameters(func_name)
    print 'void SERVER_DISPATCH_APIENTRY crServerDispatch%s( %s )' % ( func_name, apiutil.MakeDeclarationString(params))
    print '{'
    print '\t%s *get_values;' % types[index]
    print '\tint tablesize;'
    print """
    #ifdef CR_ARB_texture_compression
    if (GL_COMPRESSED_TEXTURE_FORMATS_ARB == pname)
    {
        GLint numtexfmts = 0;
        cr_server.head_spu->dispatch_table.GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &numtexfmts);
        tablesize = numtexfmts * sizeof(%s);
    }
    else
    #endif
    {
Пример #24
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' )