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')
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: print('\tif (pname==GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB){')
printfstr = "" if len(params) == 0: argstr = "" else: argstr = ", " i = 0 for (name, type, vecSize) in params: if vecSize > 0: # The parameter is a vector of known size, show it as a list # of values between brackets. printfstr += '[' for index in range(vecSize): type = apiutil.PointerType(type) assert printf_mapping.has_key(type) if printf_mapping.has_key(type): (format, cast) = printf_mapping[type] printfstr += format cast_str = '' if cast != '': cast_str = '(%s)' % cast arg = '%s %s[%d]' % (cast_str, name, index) if type == 'GLboolean': argstr += '%s ? "GL_TRUE" : "GL_FALSE"' % arg else: argstr += arg if index != vecSize - 1: printfstr += ", " argstr += ", "