Exemplo n.º 1
0
def MakeNormalCall(return_type, func_name, params, counter_init=0):
    counter = counter_init
    copy_of_params = params[:]

    for i in range(0, len(params)):
        (name, type, vecSize) = params[i]
        if apiutil.IsPointer(copy_of_params[i][1]):
            params[i] = ('NULL', type, vecSize)
            copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
            if not "get" in apiutil.Properties(func_name):
                print('\tcrError( "%s needs to be special cased!" );' %
                      func_name)
        else:
            print("\t%s %s = %s;" % (copy_of_params[i][1], name,
                                     ReadData(counter, copy_of_params[i][1])))
        counter += apiutil.sizeof(copy_of_params[i][1])

    if ("get" in apiutil.Properties(func_name)):
        FindReturnPointer(return_type, params)
        FindWritebackPointer(return_type, params)

    if return_type != "void":
        print("\t(void)", end=" ")
    else:
        print("\t", end="")
    print("pState->pDispatchTbl->%s(%s);" %
          (func_name, apiutil.MakeCallStringForDispatcher(params)))
Exemplo n.º 2
0
def WriteData(offset, arg_type, arg_name, is_swapped):
    """Return a string to write a variable to the packing buffer."""
    retval = 9
    if apiutil.IsPointer(arg_type):
        retval = "\tWRITE_NETWORK_POINTER(%d, (void *) %s);" % (offset,
                                                                arg_name)
    else:
        if is_swapped:
            if arg_type == "GLfloat" or arg_type == "GLclampf":
                retval = "\tWRITE_DATA(%d, GLuint, SWAPFLOAT(%s));" % (
                    offset, arg_name)
            elif arg_type == "GLdouble" or arg_type == "GLclampd":
                retval = "\tWRITE_SWAPPED_DOUBLE(%d, %s);" % (offset, arg_name)
            elif apiutil.sizeof(arg_type) == 1:
                retval = "\tWRITE_DATA(%d, %s, %s);" % (offset, arg_type,
                                                        arg_name)
            elif apiutil.sizeof(arg_type) == 2:
                retval = "\tWRITE_DATA(%d, %s, SWAP16(%s));" % (
                    offset, arg_type, arg_name)
            elif apiutil.sizeof(arg_type) == 4:
                retval = "\tWRITE_DATA(%d, %s, SWAP32(%s));" % (
                    offset, arg_type, arg_name)
        else:
            if arg_type == "GLdouble" or arg_type == "GLclampd":
                retval = "\tWRITE_DOUBLE(%d, %s);" % (offset, arg_name)
            else:
                retval = "\tWRITE_DATA(%d, %s, %s);" % (offset, arg_type,
                                                        arg_name)
    if retval == 9:
        print >> sys.stderr, "no retval for %s %s" % (arg_name, arg_type)
        assert 0
    return retval
Exemplo n.º 3
0
keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")
for func_name in keys:
    #(return_type, arg_names, arg_types) = gl_mapping[func_name]
    if ("get" in apiutil.Properties(func_name)
            and apiutil.ReturnType(func_name) == "void"
            and not apiutil.FindSpecial("server", func_name)):

        params = apiutil.Parameters(func_name)

        print('void SERVER_DISPATCH_APIENTRY crServerDispatch%s(%s)' %
              (func_name, apiutil.MakeDeclarationString(params)))
        print('{')

        lastParam = params[-1]
        assert apiutil.IsPointer(lastParam[1])
        local_argtype = apiutil.PointerType(lastParam[1])
        local_argname = 'local_%s' % lastParam[0]

        if not func_name in no_pnames:
            print('\tunsigned int cComponents = 0;')
        print('\t%s %s[%d] = { 0 };' %
              (local_argtype, local_argname, max_components[func_name]))
        print('\t(void) %s;' % lastParam[0])

        params[-1] = (local_argname, local_argtype, 0)

        print('\tcr_server.head_spu->dispatch_table.%s(%s);' %
              (func_name, apiutil.MakeCallString(params)))

        if func_name in convert_bufferid:
Exemplo n.º 4
0
#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))

# Now generate special BBOX, COUNT, SWAP variations on the glVertex and
Exemplo n.º 5
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')
Exemplo n.º 6
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' )
Exemplo n.º 7
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' )