#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)) if "get" in apiutil.Properties(func_name): args.append(("writeback", "int *", 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')