コード例 #1
0
def getWritebackPointerOffset(return_type, params):
    """Returns the offset of the writeback pointer"""
    arg_len = apiutil.PacketLength(params)
    if return_type != 'void':
        paramList = [('foo', 'void *', 0)]
        arg_len += apiutil.PacketLength(paramList)

    return arg_len + 8  # extended opcode plus packet length
コード例 #2
0
ファイル: unpack.py プロジェクト: sailfishos/virtualbox
def FindWritebackPointer( return_type, params ):
    """Emit a SET_WRITEBACK_PTR call."""
    arg_len = apiutil.PacketLength( params )
    if return_type != 'void':
        paramList = [ ('foo', 'void *', 0) ]
        arg_len += apiutil.PacketLength( paramList )

    print('\tSET_WRITEBACK_PTR(%d);' % (arg_len + 8)) # extended opcode plus packet length
コード例 #3
0
ファイル: unpack.py プロジェクト: sailfishos/virtualbox
def FindReturnPointer( return_type, params ):
    """For GL functions that return values (either as the return value or
    through a pointer parameter) emit a SET_RETURN_PTR call."""
    arg_len = apiutil.PacketLength( params )
    if (return_type != 'void'):
        print('\tSET_RETURN_PTR(%d);' % (arg_len + 8)) # extended opcode plus packet length
    else:
        paramList = [ ('foo', 'void *', 0) ]
        print('\tSET_RETURN_PTR(%d);' % (arg_len + 8 - apiutil.PacketLength(paramList)))
コード例 #4
0

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:
        MakeNormalCall(return_type, func_name, params)
    if packet_length == 0:
        print("\tINCR_DATA_PTR_NO_ARGS(pState);")
コード例 #5
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'
コード例 #6
0
ファイル: unpack.py プロジェクト: sailfishos/virtualbox
#
# 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)
    
    print("static void crUnpack%s(void)" % func_name)
    print("{")

    # Verify that the provided buffer length is what we expect.
    packet_length = apiutil.PacketLength( params )
    if packet_length > 0:
        print("\tif(!DATA_POINTER_CHECK(%d))" % packet_length);
        print("\t{");
        print("\t\tcrError(\"crUnpack%s: parameters out of range\");" % func_name);
        print("\t\treturn;");
        print("\t}");

    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:
        MakeNormalCall( return_type, func_name, params )
    if packet_length == 0:
        print("\tINCR_DATA_PTR_NO_ARGS( );")
    else:
コード例 #7
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')
コード例 #8
0
ファイル: length_table.py プロジェクト: raptoravis/cr19
    'VertexAttrib4NusvARB': 8 + 4
}

apiutil.CopyrightC()

# Generate a table, indexed by packer opcode, which indicates the size
# (in bytes) of the packed commands.  We only care about the per-vertex
# commands like glColor, glNormal, glMaterial, etc.  For functions we
# don't care about, we set the size to -1.  In the pincher we assert that
# the size isn't -1.  If any of those assertions fail then an unexpected
# command is in the geometry buffer.

print """
static const int __cr_packet_length_table[] = {
"""

for func_name in keys:
    if "pack" in apiutil.ChromiumProps(func_name):

        if func_name in things_pinch_cares_about:
            if func_name in special_sizes.keys():
                size = special_sizes[func_name]
            else:
                params = apiutil.Parameters(func_name)
                size = apiutil.PacketLength(params)
            print "\t%2d, /* %s */" % (size, func_name)
        else:
            print '\t-1, /* %s */' % func_name
print '\t0 /* crap */'
print "};"