FileDocCategorySizeDatePackage
FieldPacker.javaAPI DocAndroid 5.1 API15198Thu Mar 12 22:22:42 GMT 2015android.renderscript

FieldPacker

public class FieldPacker extends Object
Utility class for packing arguments and structures from Android system objects to RenderScript objects. This class is only intended to be used to support the reflected code generated by the RS tool chain. It should not be called directly.

Fields Summary
private final byte[]
mData
private int
mPos
private int
mLen
private BitSet
mAlignment
Constructors Summary
public FieldPacker(int len)

        mPos = 0;
        mLen = len;
        mData = new byte[len];
        mAlignment = new BitSet();
    
public FieldPacker(byte[] data)

        // Advance mPos to the end of the buffer, since we are copying in the
        // full data input.
        mPos = data.length;
        mLen = data.length;
        mData = data;
        mAlignment = new BitSet();
        // TODO: We should either have an actual FieldPacker copy constructor
        // or drop support for computing alignment like this. As it stands,
        // subAlign() can never work correctly for copied FieldPacker objects.
    
Methods Summary
public voidaddBoolean(boolean v)

        addI8((byte)(v ? 1 : 0));
    
public voidaddF32(float v)

        addI32(Float.floatToRawIntBits(v));
    
public voidaddF32(Float2 v)

        addF32(v.x);
        addF32(v.y);
    
public voidaddF32(Float3 v)

        addF32(v.x);
        addF32(v.y);
        addF32(v.z);
    
public voidaddF32(Float4 v)

        addF32(v.x);
        addF32(v.y);
        addF32(v.z);
        addF32(v.w);
    
public voidaddF64(double v)

        addI64(Double.doubleToRawLongBits(v));
    
public voidaddF64(Double2 v)

        addF64(v.x);
        addF64(v.y);
    
public voidaddF64(Double3 v)

        addF64(v.x);
        addF64(v.y);
        addF64(v.z);
    
public voidaddF64(Double4 v)

        addF64(v.x);
        addF64(v.y);
        addF64(v.z);
        addF64(v.w);
    
public voidaddI16(short v)

        align(2);
        mData[mPos++] = (byte)(v & 0xff);
        mData[mPos++] = (byte)(v >> 8);
    
public voidaddI16(Short2 v)

        addI16(v.x);
        addI16(v.y);
    
public voidaddI16(Short3 v)

        addI16(v.x);
        addI16(v.y);
        addI16(v.z);
    
public voidaddI16(Short4 v)

        addI16(v.x);
        addI16(v.y);
        addI16(v.z);
        addI16(v.w);
    
public voidaddI32(int v)

        align(4);
        mData[mPos++] = (byte)(v & 0xff);
        mData[mPos++] = (byte)((v >> 8) & 0xff);
        mData[mPos++] = (byte)((v >> 16) & 0xff);
        mData[mPos++] = (byte)((v >> 24) & 0xff);
    
public voidaddI32(Int2 v)

        addI32(v.x);
        addI32(v.y);
    
public voidaddI32(Int3 v)

        addI32(v.x);
        addI32(v.y);
        addI32(v.z);
    
public voidaddI32(Int4 v)

        addI32(v.x);
        addI32(v.y);
        addI32(v.z);
        addI32(v.w);
    
public voidaddI64(long v)

        align(8);
        mData[mPos++] = (byte)(v & 0xff);
        mData[mPos++] = (byte)((v >> 8) & 0xff);
        mData[mPos++] = (byte)((v >> 16) & 0xff);
        mData[mPos++] = (byte)((v >> 24) & 0xff);
        mData[mPos++] = (byte)((v >> 32) & 0xff);
        mData[mPos++] = (byte)((v >> 40) & 0xff);
        mData[mPos++] = (byte)((v >> 48) & 0xff);
        mData[mPos++] = (byte)((v >> 56) & 0xff);
    
public voidaddI64(Long2 v)

        addI64(v.x);
        addI64(v.y);
    
public voidaddI64(Long3 v)

        addI64(v.x);
        addI64(v.y);
        addI64(v.z);
    
public voidaddI64(Long4 v)

        addI64(v.x);
        addI64(v.y);
        addI64(v.z);
        addI64(v.w);
    
public voidaddI8(Byte2 v)

        addI8(v.x);
        addI8(v.y);
    
public voidaddI8(Byte3 v)

        addI8(v.x);
        addI8(v.y);
        addI8(v.z);
    
public voidaddI8(Byte4 v)

        addI8(v.x);
        addI8(v.y);
        addI8(v.z);
        addI8(v.w);
    
public voidaddI8(byte v)

        mData[mPos++] = v;
    
public voidaddMatrix(Matrix4f v)

        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
        }
    
public voidaddMatrix(Matrix3f v)

        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
        }
    
public voidaddMatrix(Matrix2f v)

        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
        }
    
public voidaddObj(BaseObj obj)

        if (obj != null) {
            if (RenderScript.sPointerSize == 8) {
                addI64(obj.getID(null));
                addI64(0);
                addI64(0);
                addI64(0);
            }
            else {
                addI32((int)obj.getID(null));
            }
        } else {
            if (RenderScript.sPointerSize == 8) {
                addI64(0);
                addI64(0);
                addI64(0);
                addI64(0);
            } else {
                addI32(0);
            }
        }
    
public voidaddU16(int v)

        if ((v < 0) || (v > 0xffff)) {
            android.util.Log.e("rs", "FieldPacker.addU16( " + v + " )");
            throw new IllegalArgumentException("Saving value out of range for type");
        }
        align(2);
        mData[mPos++] = (byte)(v & 0xff);
        mData[mPos++] = (byte)(v >> 8);
    
public voidaddU16(Int2 v)

        addU16(v.x);
        addU16(v.y);
    
public voidaddU16(Int3 v)

        addU16(v.x);
        addU16(v.y);
        addU16(v.z);
    
public voidaddU16(Int4 v)

        addU16(v.x);
        addU16(v.y);
        addU16(v.z);
        addU16(v.w);
    
public voidaddU32(long v)

        if ((v < 0) || (v > 0xffffffffL)) {
            android.util.Log.e("rs", "FieldPacker.addU32( " + v + " )");
            throw new IllegalArgumentException("Saving value out of range for type");
        }
        align(4);
        mData[mPos++] = (byte)(v & 0xff);
        mData[mPos++] = (byte)((v >> 8) & 0xff);
        mData[mPos++] = (byte)((v >> 16) & 0xff);
        mData[mPos++] = (byte)((v >> 24) & 0xff);
    
public voidaddU32(Long2 v)

        addU32(v.x);
        addU32(v.y);
    
public voidaddU32(Long3 v)

        addU32(v.x);
        addU32(v.y);
        addU32(v.z);
    
public voidaddU32(Long4 v)

        addU32(v.x);
        addU32(v.y);
        addU32(v.z);
        addU32(v.w);
    
public voidaddU64(long v)

        if (v < 0) {
            android.util.Log.e("rs", "FieldPacker.addU64( " + v + " )");
            throw new IllegalArgumentException("Saving value out of range for type");
        }
        align(8);
        mData[mPos++] = (byte)(v & 0xff);
        mData[mPos++] = (byte)((v >> 8) & 0xff);
        mData[mPos++] = (byte)((v >> 16) & 0xff);
        mData[mPos++] = (byte)((v >> 24) & 0xff);
        mData[mPos++] = (byte)((v >> 32) & 0xff);
        mData[mPos++] = (byte)((v >> 40) & 0xff);
        mData[mPos++] = (byte)((v >> 48) & 0xff);
        mData[mPos++] = (byte)((v >> 56) & 0xff);
    
public voidaddU64(Long2 v)

        addU64(v.x);
        addU64(v.y);
    
public voidaddU64(Long3 v)

        addU64(v.x);
        addU64(v.y);
        addU64(v.z);
    
public voidaddU64(Long4 v)

        addU64(v.x);
        addU64(v.y);
        addU64(v.z);
        addU64(v.w);
    
public voidaddU8(short v)

        if ((v < 0) || (v > 0xff)) {
            android.util.Log.e("rs", "FieldPacker.addU8( " + v + " )");
            throw new IllegalArgumentException("Saving value out of range for type");
        }
        mData[mPos++] = (byte)v;
    
public voidaddU8(Short2 v)

        addU8(v.x);
        addU8(v.y);
    
public voidaddU8(Short3 v)

        addU8(v.x);
        addU8(v.y);
        addU8(v.z);
    
public voidaddU8(Short4 v)

        addU8(v.x);
        addU8(v.y);
        addU8(v.z);
        addU8(v.w);
    
public voidalign(int v)

        if ((v <= 0) || ((v & (v - 1)) != 0)) {
            throw new RSIllegalArgumentException("argument must be a non-negative non-zero power of 2: " + v);
        }

        while ((mPos & (v - 1)) != 0) {
            mAlignment.flip(mPos);
            mData[mPos++] = 0;
        }
    
public final byte[]getData()

        return mData;
    
public intgetPos()
Get the actual length used for the FieldPacker.

hide

        return mPos;
    
public voidreset()

        mPos = 0;
    
public voidreset(int i)

        if ((i < 0) || (i > mLen)) {
            throw new RSIllegalArgumentException("out of range argument: " + i);
        }
        mPos = i;
    
public voidskip(int i)

        int res = mPos + i;
        if ((res < 0) || (res > mLen)) {
            throw new RSIllegalArgumentException("out of range argument: " + i);
        }
        mPos = res;
    
public booleansubBoolean()

        byte v = subI8();
        if (v == 1) {
            return true;
        }
        return false;
    
public Byte2subByte2()

        Byte2 v = new Byte2();
        v.y = subI8();
        v.x = subI8();
        return v;
    
public Byte3subByte3()

        Byte3 v = new Byte3();
        v.z = subI8();
        v.y = subI8();
        v.x = subI8();
        return v;
    
public Byte4subByte4()

        Byte4 v = new Byte4();
        v.w = subI8();
        v.z = subI8();
        v.y = subI8();
        v.x = subI8();
        return v;
    
public Double2subDouble2()

        Double2 v = new Double2();
        v.y = subF64();
        v.x = subF64();
        return v;
    
public Double3subDouble3()

        Double3 v = new Double3();
        v.z = subF64();
        v.y = subF64();
        v.x = subF64();
        return v;
    
public Double4subDouble4()

        Double4 v = new Double4();
        v.w = subF64();
        v.z = subF64();
        v.y = subF64();
        v.x = subF64();
        return v;
    
public floatsubF32()

        return Float.intBitsToFloat(subI32());
    
public doublesubF64()

        return Double.longBitsToDouble(subI64());
    
public Float2subFloat2()

        Float2 v = new Float2();
        v.y = subF32();
        v.x = subF32();
        return v;
    
public Float3subFloat3()

        Float3 v = new Float3();
        v.z = subF32();
        v.y = subF32();
        v.x = subF32();
        return v;
    
public Float4subFloat4()

        Float4 v = new Float4();
        v.w = subF32();
        v.z = subF32();
        v.y = subF32();
        v.x = subF32();
        return v;
    
public shortsubI16()

        subalign(2);
        short v = 0;
        v = (short)((mData[--mPos] & 0xff) << 8);
        v = (short)(v | (short)(mData[--mPos] & 0xff));
        return v;
    
public intsubI32()

        subalign(4);
        int v = 0;
        v = ((mData[--mPos] & 0xff) << 24);
        v = v | ((mData[--mPos] & 0xff) << 16);
        v = v | ((mData[--mPos] & 0xff) << 8);
        v = v | ((mData[--mPos] & 0xff));
        return v;
    
public longsubI64()

        subalign(8);
        long v = 0;
        byte x = 0;
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 56l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 48l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 40l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 32l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 24l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 16l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff) << 8l);
        x = ((mData[--mPos]));
        v = (long)(v | (((long)x) & 0xff));
        return v;
    
public bytesubI8()

        subalign(1);
        return mData[--mPos];
    
public Int2subInt2()

        Int2 v = new Int2();
        v.y = subI32();
        v.x = subI32();
        return v;
    
public Int3subInt3()

        Int3 v = new Int3();
        v.z = subI32();
        v.y = subI32();
        v.x = subI32();
        return v;
    
public Int4subInt4()

        Int4 v = new Int4();
        v.w = subI32();
        v.z = subI32();
        v.y = subI32();
        v.x = subI32();
        return v;
    
public Long2subLong2()

        Long2 v = new Long2();
        v.y = subI64();
        v.x = subI64();
        return v;
    
public Long3subLong3()

        Long3 v = new Long3();
        v.z = subI64();
        v.y = subI64();
        v.x = subI64();
        return v;
    
public Long4subLong4()

        Long4 v = new Long4();
        v.w = subI64();
        v.z = subI64();
        v.y = subI64();
        v.x = subI64();
        return v;
    
public Matrix2fsubMatrix2f()

        Matrix2f v = new Matrix2f();
        for (int i = v.mMat.length - 1; i >= 0; i--) {
            v.mMat[i] = subF32();
        }
        return v;
    
public Matrix3fsubMatrix3f()

        Matrix3f v = new Matrix3f();
        for (int i = v.mMat.length - 1; i >= 0; i--) {
            v.mMat[i] = subF32();
        }
        return v;
    
public Matrix4fsubMatrix4f()

        Matrix4f v = new Matrix4f();
        for (int i = v.mMat.length - 1; i >= 0; i--) {
            v.mMat[i] = subF32();
        }
        return v;
    
public Short2subShort2()

        Short2 v = new Short2();
        v.y = subI16();
        v.x = subI16();
        return v;
    
public Short3subShort3()

        Short3 v = new Short3();
        v.z = subI16();
        v.y = subI16();
        v.x = subI16();
        return v;
    
public Short4subShort4()

        Short4 v = new Short4();
        v.w = subI16();
        v.z = subI16();
        v.y = subI16();
        v.x = subI16();
        return v;
    
public voidsubalign(int v)

        if ((v & (v - 1)) != 0) {
            throw new RSIllegalArgumentException("argument must be a non-negative non-zero power of 2: " + v);
        }

        while ((mPos & (v - 1)) != 0) {
            mPos--;
        }

        if (mPos > 0) {
            while (mAlignment.get(mPos - 1) == true) {
                mPos--;
                mAlignment.flip(mPos);
            }
        }