print('\tGLenum extend_opcode = %s;' % ReadData(4, 'GLenum')) print('') print('#ifdef CR_UNPACK_DEBUG_PREV_OPCODES') print('\tg_VBoxDbgCrPrevExtendOpcode = extend_opcode;') print('#endif') print('') print('\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/') print('\tswitch( extend_opcode )') print('\t{') # # Emit switch statement for extended opcodes # for func_name in keys: if "extpack" in apiutil.ChromiumProps(func_name): print('\t\tcase %s:' % apiutil.ExtendedOpcodeName(func_name)) # print('\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name ))) print('\t\t\tcrUnpackExtend%s(pState);' % func_name) print('\t\t\tbreak;') print(""" default: crError( "Unknown extended opcode: %d", (int) extend_opcode ); break; } INCR_VAR_PTR(pState); }""") print('static void crUnpackExtendDbg(PCrUnpackerState pState)') print('{') print('\tCHECK_BUFFER_SIZE_STATIC_LAST(pState, 4, GLenum);') print('\tGLenum extend_opcode = %s;' % ReadData(4, 'GLenum'))
print '}\n' print 'static void crUnpackExtend(void)' print '{' print '\tGLenum extend_opcode = %s;' % ReadData(4, 'GLenum') print '' print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/' print '\tswitch( extend_opcode )' print '\t{' # # Emit switch statement for extended opcodes # for func_name in keys: if "extpack" in apiutil.ChromiumProps(func_name): print '\t\tcase %s:' % apiutil.ExtendedOpcodeName(func_name) # print '\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name ) print '\t\t\tcrUnpackExtend%s( );' % func_name print '\t\t\tbreak;' print """ default: crError( "Unknown extended opcode: %d", (int) extend_opcode ); break; } INCR_VAR_PTR(); }""" print 'static void crUnpackExtendDbg(void)' print '{' print '\tGLenum extend_opcode = %s;' % ReadData(4, 'GLenum') print ''
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')
return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print 'static void crUnpackExtend%s(void)' % func_name print '{' MakeNormalCall(return_type, func_name, params, 8) print '}\n' print 'static void crUnpackExtend(void)' print '{' print '\tGLenum extend_opcode = %s;' % ReadData(4, 'GLenum') print '' print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/' print '\tswitch( extend_opcode )' print '\t{' # # Emit switch statement for extended opcodes # for func_name in keys: if "extpack" in apiutil.ChromiumProps(func_name): print '\t\tcase %s:' % apiutil.ExtendedOpcodeName(func_name) print '\t\t\tcrUnpackExtend%s( );' % func_name print '\t\t\tbreak;' print """ default: crError( "Unknown extended opcode: %d", (int) extend_opcode ); break; } INCR_VAR_PTR(); }"""
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) print "\tCR_EXTEND_OPCODE=%d" % enum_index print "} CROpcode;\n" # count up number of extended opcode commands num_extends = 0 for func in keys: if "extpack" in apiutil.ChromiumProps(func): num_extends += 1 print "/* Functions with a return value or output parameters */" print "typedef enum {" enum_index = 0 for func in keys: if "extpack" in apiutil.ChromiumProps(func): opcodeName = apiutil.ExtendedOpcodeName(func) if enum_index != num_extends - 1: print "\t%s = %d," % (opcodeName, enum_index) else: print "\t%s = %d" % (opcodeName, enum_index) enum_index = enum_index + 1 print "} CRExtendOpcode;\n" print "#endif /* CR_OPCODES_H */"