FileDocCategorySizeDatePackage
Type.javaAPI DocAndroid 5.1 API11721Thu Mar 12 22:22:42 GMT 2015android.renderscript

Type

public class Type extends BaseObj

A Type describes the {@link android.renderscript.Element} and dimensions used for an {@link android.renderscript.Allocation} or a parallel operation. Types are created through {@link android.renderscript.Type.Builder}.

A Type always includes an {@link android.renderscript.Element} and an X dimension. A Type may be multidimensional, up to three dimensions. A nonzero value in the Y or Z dimensions indicates that the dimension is present. Note that a Type with only a given X dimension and a Type with the same X dimension but Y = 1 are not equivalent.

A Type also supports inclusion of level of detail (LOD) or cube map faces. LOD and cube map faces are booleans to indicate present or not present.

A Type also supports YUV format information to support an {@link android.renderscript.Allocation} in a YUV format. The YUV formats supported are {@link android.graphics.ImageFormat#YV12}, {@link android.graphics.ImageFormat#NV21}, and {@link android.graphics.ImageFormat#YUV_420_888}

Developer Guides

For more information about creating an application that uses RenderScript, read the RenderScript developer guide.

Fields Summary
int
mDimX
int
mDimY
int
mDimZ
boolean
mDimMipmaps
boolean
mDimFaces
int
mDimYuv
int
mElementCount
Element
mElement
Constructors Summary
Type(long id, RenderScript rs)

        super(id, rs);
    
Methods Summary
voidcalcElementCount()

        boolean hasLod = hasMipmaps();
        int x = getX();
        int y = getY();
        int z = getZ();
        int faces = 1;
        if (hasFaces()) {
            faces = 6;
        }
        if (x == 0) {
            x = 1;
        }
        if (y == 0) {
            y = 1;
        }
        if (z == 0) {
            z = 1;
        }

        int count = x * y * z * faces;

        while (hasLod && ((x > 1) || (y > 1) || (z > 1))) {
            if(x > 1) {
                x >>= 1;
            }
            if(y > 1) {
                y >>= 1;
            }
            if(z > 1) {
                z >>= 1;
            }

            count += x * y * z * faces;
        }
        mElementCount = count;
    
public static android.renderscript.TypecreateX(RenderScript rs, Element e, int dimX)
Utility function for creating basic 1D types. The type is created without mipmaps enabled.

param
rs The RenderScript context
param
e The Element for the Type
param
dimX The X dimension, must be > 0
return
Type

        if (dimX < 1) {
            throw new RSInvalidStateException("Dimension must be >= 1.");
        }

        long id = rs.nTypeCreate(e.getID(rs), dimX, 0, 0, false, false, 0);
        Type t = new Type(id, rs);
        t.mElement = e;
        t.mDimX = dimX;
        t.calcElementCount();
        return t;
    
public static android.renderscript.TypecreateXY(RenderScript rs, Element e, int dimX, int dimY)
Utility function for creating basic 2D types. The type is created without mipmaps or cubemaps.

param
rs The RenderScript context
param
e The Element for the Type
param
dimX The X dimension, must be > 0
param
dimY The Y dimension, must be > 0
return
Type

        if ((dimX < 1) || (dimY < 1)) {
            throw new RSInvalidStateException("Dimension must be >= 1.");
        }

        long id = rs.nTypeCreate(e.getID(rs), dimX, dimY, 0, false, false, 0);
        Type t = new Type(id, rs);
        t.mElement = e;
        t.mDimX = dimX;
        t.mDimY = dimY;
        t.calcElementCount();
        return t;
    
public static android.renderscript.TypecreateXYZ(RenderScript rs, Element e, int dimX, int dimY, int dimZ)
Utility function for creating basic 3D types. The type is created without mipmaps.

param
rs The RenderScript context
param
e The Element for the Type
param
dimX The X dimension, must be > 0
param
dimY The Y dimension, must be > 0
param
dimZ The Z dimension, must be > 0
return
Type

        if ((dimX < 1) || (dimY < 1) || (dimZ < 1)) {
            throw new RSInvalidStateException("Dimension must be >= 1.");
        }

        long id = rs.nTypeCreate(e.getID(rs), dimX, dimY, dimZ, false, false, 0);
        Type t = new Type(id, rs);
        t.mElement = e;
        t.mDimX = dimX;
        t.mDimY = dimY;
        t.mDimZ = dimZ;
        t.calcElementCount();
        return t;
    
public intgetCount()
Return the total number of accessable cells in the Type.

return
int

        return mElementCount;
    
public ElementgetElement()
Return the element associated with this Type.

return
Element

        return mElement;
    
public intgetX()
Return the value of the X dimension.

return
int

        return mDimX;
    
public intgetY()
Return the value of the Y dimension or 0 for a 1D allocation.

return
int

        return mDimY;
    
public intgetYuv()
Get the YUV format

return
int

        return mDimYuv;
    
public intgetZ()
Return the value of the Z dimension or 0 for a 1D or 2D allocation.

return
int

        return mDimZ;
    
public booleanhasFaces()
Return if the Type is a cube map.

return
boolean

        return mDimFaces;
    
public booleanhasMipmaps()
Return if the Type has a mipmap chain.

return
boolean

        return mDimMipmaps;
    
voidupdateFromNative()

        // We have 6 integer/long to obtain mDimX; mDimY; mDimZ;
        // mDimLOD; mDimFaces; mElement;
        long[] dataBuffer = new long[6];
        mRS.nTypeGetNativeData(getID(mRS), dataBuffer);

        mDimX = (int)dataBuffer[0];
        mDimY = (int)dataBuffer[1];
        mDimZ = (int)dataBuffer[2];
        mDimMipmaps = dataBuffer[3] == 1 ? true : false;
        mDimFaces = dataBuffer[4] == 1 ? true : false;

        long elementID = dataBuffer[5];
        if(elementID != 0) {
            mElement = new Element(elementID, mRS);
            mElement.updateFromNative();
        }
        calcElementCount();