Added in API level 11
Deprecated in API level 31

Element


public class Element
extends BaseObj

java.lang.Object
   ↳ android.renderscript.BaseObj
     ↳ android.renderscript.Element


This class was deprecated in API level 31.
Renderscript has been deprecated in API level 31. Please refer to the migration guide for the proposed alternatives.

An Element represents one item within an Allocation. An Element is roughly equivalent to a C type in a RenderScript kernel. Elements may be basic or complex. Some basic elements are

  • A single float value (equivalent to a float in a kernel)
  • A four-element float vector (equivalent to a float4 in a kernel)
  • An unsigned 32-bit integer (equivalent to an unsigned int in a kernel)
  • A single signed 8-bit integer (equivalent to a char in a kernel)

A complex element is roughly equivalent to a C struct and contains a number of basic or complex Elements. From Java code, a complex element contains a list of sub-elements and names that represents a particular data structure. Structs used in RS scripts are available to Java code by using the ScriptField_structname class that is reflected from a particular script.

Basic Elements are comprised of a Element.DataType and a Element.DataKind. The DataType encodes C type information of an Element, while the DataKind encodes how that Element should be interpreted by a Sampler. Note that Allocation objects with DataKind Element.DataKind.USER cannot be used as input for a Sampler. In general, Allocation objects that are intended for use with a Sampler should use bitmap-derived Elements such as RGBA_8888(RenderScript) or android.renderscript.

Developer Guides

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

Summary

Nested classes

class Element.Builder

Builder class for producing complex elements with matching field and name pairs. 

Public methods

static Element ALLOCATION(RenderScript rs)
static Element A_8(RenderScript rs)
static Element BOOLEAN(RenderScript rs)

Utility function for returning an Element containing a single Boolean.

static Element ELEMENT(RenderScript rs)
static Element F16(RenderScript rs)
static Element F16_2(RenderScript rs)
static Element F16_3(RenderScript rs)
static Element F16_4(RenderScript rs)
static Element F32(RenderScript rs)
static Element F32_2(RenderScript rs)
static Element F32_3(RenderScript rs)
static Element F32_4(RenderScript rs)
static Element F64(RenderScript rs)
static Element F64_2(RenderScript rs)
static Element F64_3(RenderScript rs)
static Element F64_4(RenderScript rs)
static Element FONT(RenderScript rs)
static Element I16(RenderScript rs)
static Element I16_2(RenderScript rs)
static Element I16_3(RenderScript rs)
static Element I16_4(RenderScript rs)
static Element I32(RenderScript rs)
static Element I32_2(RenderScript rs)
static Element I32_3(RenderScript rs)
static Element I32_4(RenderScript rs)
static Element I64(RenderScript rs)
static Element I64_2(RenderScript rs)
static Element I64_3(RenderScript rs)
static Element I64_4(RenderScript rs)
static Element I8(RenderScript rs)

Utility function for returning an Element containing a single SIGNED_8.

static Element I8_2(RenderScript rs)
static Element I8_3(RenderScript rs)
static Element I8_4(RenderScript rs)
static Element MATRIX4X4(RenderScript rs)

This method was deprecated in API level 16. use MATRIX_4X4

static Element MATRIX_2X2(RenderScript rs)
static Element MATRIX_3X3(RenderScript rs)
static Element MATRIX_4X4(RenderScript rs)
static Element MESH(RenderScript rs)
static Element PROGRAM_FRAGMENT(RenderScript rs)
static Element PROGRAM_RASTER(RenderScript rs)
static Element PROGRAM_STORE(RenderScript rs)
static Element PROGRAM_VERTEX(RenderScript rs)
static Element RGBA_4444(RenderScript rs)
static Element RGBA_5551(RenderScript rs)
static Element RGBA_8888(RenderScript rs)
static Element RGB_565(RenderScript rs)
static Element RGB_888(RenderScript rs)
static Element SAMPLER(RenderScript rs)
static Element SCRIPT(RenderScript rs)
static Element TYPE(RenderScript rs)
static Element U16(RenderScript rs)
static Element U16_2(RenderScript rs)
static Element U16_3(RenderScript rs)
static Element U16_4(RenderScript rs)
static Element U32(RenderScript rs)
static Element U32_2(RenderScript rs)
static Element U32_3(RenderScript rs)
static Element U32_4(RenderScript rs)
static Element U64(RenderScript rs)
static Element U64_2(RenderScript rs)
static Element U64_3(RenderScript rs)
static Element U64_4(RenderScript rs)
static Element U8(RenderScript rs)

Utility function for returning an Element containing a single UNSIGNED_8.

static Element U8_2(RenderScript rs)
static Element U8_3(RenderScript rs)
static Element U8_4(RenderScript rs)
static Element YUV(RenderScript rs)
static Element createPixel(RenderScript rs, Element.DataType dt, Element.DataKind dk)

Create a new pixel Element type.

static Element createVector(RenderScript rs, Element.DataType dt, int size)

Create a custom vector element of the specified DataType and vector size.

int getBytesSize()
Element.DataKind getDataKind()
Element.DataType getDataType()
Element getSubElement(int index)

For complex elements, this function will return the sub-element at index

int getSubElementArraySize(int index)

For complex elements, some sub-elements could be statically sized arrays.

int getSubElementCount()

Elements could be simple, such as an int or a float, or a structure with multiple sub elements, such as a collection of floats, float2, float4.

String getSubElementName(int index)

For complex elements, this function will return the sub-element name at index

int getSubElementOffsetBytes(int index)

This function specifies the location of a sub-element within the element

int getVectorSize()

Returns the number of vector components.

boolean isCompatible(Element e)

Check if the current Element is compatible with another Element.

boolean isComplex()

Return if a element is too complex for use as a data source for a Mesh or a Program.

Inherited methods

Public methods

ALLOCATION

Added in API level 11
public static Element ALLOCATION (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

A_8

Added in API level 11
public static Element A_8 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

BOOLEAN

Added in API level 11
public static Element BOOLEAN (RenderScript rs)

Utility function for returning an Element containing a single Boolean.

Parameters
rs RenderScript: Context to which the element will belong.

Returns
Element Element

ELEMENT

Added in API level 11
public static Element ELEMENT (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F16

Added in API level 23
Deprecated in API level 31
public static Element F16 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F16_2

Added in API level 23
Deprecated in API level 31
public static Element F16_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F16_3

Added in API level 23
Deprecated in API level 31
public static Element F16_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F16_4

Added in API level 23
Deprecated in API level 31
public static Element F16_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F32

Added in API level 11
public static Element F32 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F32_2

Added in API level 11
public static Element F32_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F32_3

Added in API level 11
public static Element F32_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F32_4

Added in API level 11
public static Element F32_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F64

Added in API level 11
public static Element F64 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F64_2

Added in API level 14
Deprecated in API level 31
public static Element F64_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F64_3

Added in API level 14
Deprecated in API level 31
public static Element F64_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

F64_4

Added in API level 14
Deprecated in API level 31
public static Element F64_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

FONT

Added in API level 16
Deprecated in API level 31
public static Element FONT (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I16

Added in API level 11
public static Element I16 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I16_2

Added in API level 14
Deprecated in API level 31
public static Element I16_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I16_3

Added in API level 14
Deprecated in API level 31
public static Element I16_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I16_4

Added in API level 14
Deprecated in API level 31
public static Element I16_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I32

Added in API level 11
public static Element I32 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I32_2

Added in API level 14
Deprecated in API level 31
public static Element I32_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I32_3

Added in API level 14
Deprecated in API level 31
public static Element I32_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I32_4

Added in API level 14
Deprecated in API level 31
public static Element I32_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I64

Added in API level 11
public static Element I64 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I64_2

Added in API level 14
Deprecated in API level 31
public static Element I64_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I64_3

Added in API level 14
Deprecated in API level 31
public static Element I64_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I64_4

Added in API level 14
Deprecated in API level 31
public static Element I64_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I8

Added in API level 11
public static Element I8 (RenderScript rs)

Utility function for returning an Element containing a single SIGNED_8.

Parameters
rs RenderScript: Context to which the element will belong.

Returns
Element Element

I8_2

Added in API level 14
Deprecated in API level 31
public static Element I8_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I8_3

Added in API level 14
Deprecated in API level 31
public static Element I8_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

I8_4

Added in API level 14
Deprecated in API level 31
public static Element I8_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

MATRIX4X4

Added in API level 11
Deprecated in API level 16
public static Element MATRIX4X4 (RenderScript rs)

This method was deprecated in API level 16.
use MATRIX_4X4

Parameters
rs RenderScript

Returns
Element

MATRIX_2X2

Added in API level 11
public static Element MATRIX_2X2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

MATRIX_3X3

Added in API level 11
public static Element MATRIX_3X3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

MATRIX_4X4

Added in API level 11
public static Element MATRIX_4X4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

MESH

Added in API level 11
public static Element MESH (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

PROGRAM_FRAGMENT

Added in API level 11
public static Element PROGRAM_FRAGMENT (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

PROGRAM_RASTER

Added in API level 11
public static Element PROGRAM_RASTER (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

PROGRAM_STORE

Added in API level 11
public static Element PROGRAM_STORE (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

PROGRAM_VERTEX

Added in API level 11
public static Element PROGRAM_VERTEX (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

RGBA_4444

Added in API level 11
public static Element RGBA_4444 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

RGBA_5551

Added in API level 11
public static Element RGBA_5551 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

RGBA_8888

Added in API level 11
public static Element RGBA_8888 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

RGB_565

Added in API level 11
public static Element RGB_565 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

RGB_888

Added in API level 11
public static Element RGB_888 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

SAMPLER

Added in API level 11
public static Element SAMPLER (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

SCRIPT

Added in API level 11
public static Element SCRIPT (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

TYPE

Added in API level 11
public static Element TYPE (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U16

Added in API level 11
public static Element U16 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U16_2

Added in API level 14
Deprecated in API level 31
public static Element U16_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U16_3

Added in API level 14
Deprecated in API level 31
public static Element U16_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U16_4

Added in API level 14
Deprecated in API level 31
public static Element U16_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U32

Added in API level 11
public static Element U32 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U32_2

Added in API level 14
Deprecated in API level 31
public static Element U32_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U32_3

Added in API level 14
Deprecated in API level 31
public static Element U32_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U32_4

Added in API level 14
Deprecated in API level 31
public static Element U32_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U64

Added in API level 11
public static Element U64 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U64_2

Added in API level 14
Deprecated in API level 31
public static Element U64_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U64_3

Added in API level 14
Deprecated in API level 31
public static Element U64_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U64_4

Added in API level 14
Deprecated in API level 31
public static Element U64_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U8

Added in API level 11
public static Element U8 (RenderScript rs)

Utility function for returning an Element containing a single UNSIGNED_8.

Parameters
rs RenderScript: Context to which the element will belong.

Returns
Element Element

U8_2

Added in API level 14
Deprecated in API level 31
public static Element U8_2 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U8_3

Added in API level 14
Deprecated in API level 31
public static Element U8_3 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

U8_4

Added in API level 11
public static Element U8_4 (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

YUV

Added in API level 19
Deprecated in API level 31
public static Element YUV (RenderScript rs)

Parameters
rs RenderScript

Returns
Element

createPixel

Added in API level 11
public static Element createPixel (RenderScript rs, 
                Element.DataType dt, 
                Element.DataKind dk)

Create a new pixel Element type. A matching DataType and DataKind must be provided. The DataType and DataKind must contain the same number of components. Vector size will be set to 1.

Parameters
rs RenderScript: The context associated with the new Element.

dt Element.DataType: The DataType for the new element.

dk Element.DataKind: The DataKind to specify the mapping of each component in the DataType.

Returns
Element Element

createVector

Added in API level 11
public static Element createVector (RenderScript rs, 
                Element.DataType dt, 
                int size)

Create a custom vector element of the specified DataType and vector size. DataKind will be set to USER. Only primitive types (FLOAT_32, FLOAT_64, SIGNED_8, SIGNED_16, SIGNED_32, SIGNED_64, UNSIGNED_8, UNSIGNED_16, UNSIGNED_32, UNSIGNED_64, BOOLEAN) are supported.

Parameters
rs RenderScript: The context associated with the new Element.

dt Element.DataType: The DataType for the new Element.

size int: Vector size for the new Element. Range 2-4 inclusive supported.

Returns
Element Element

getBytesSize

Added in API level 16
Deprecated in API level 31
public int getBytesSize ()

Returns
int element size in bytes

getDataKind

Added in API level 16
Deprecated in API level 31
public Element.DataKind getDataKind ()

Returns
Element.DataKind element data kind

getDataType

Added in API level 16
Deprecated in API level 31
public Element.DataType getDataType ()

Returns
Element.DataType element data type

getSubElement

Added in API level 16
Deprecated in API level 31
public Element getSubElement (int index)

For complex elements, this function will return the sub-element at index

Parameters
index int: index of the sub-element to return

Returns
Element sub-element in this element at given index

getSubElementArraySize

Added in API level 16
Deprecated in API level 31
public int getSubElementArraySize (int index)

For complex elements, some sub-elements could be statically sized arrays. This function will return the array size for sub-element at index

Parameters
index int: index of the sub-element

Returns
int array size of sub-element in this element at given index

getSubElementCount

Added in API level 16
Deprecated in API level 31
public int getSubElementCount ()

Elements could be simple, such as an int or a float, or a structure with multiple sub elements, such as a collection of floats, float2, float4. This function returns zero for simple elements or the number of sub-elements otherwise.

Returns
int number of sub-elements in this element

getSubElementName

Added in API level 16
Deprecated in API level 31
public String getSubElementName (int index)

For complex elements, this function will return the sub-element name at index

Parameters
index int: index of the sub-element

Returns
String sub-element in this element at given index

getSubElementOffsetBytes

Added in API level 16
Deprecated in API level 31
public int getSubElementOffsetBytes (int index)

This function specifies the location of a sub-element within the element

Parameters
index int: index of the sub-element

Returns
int offset in bytes of sub-element in this element at given index

getVectorSize

Added in API level 16
Deprecated in API level 31
public int getVectorSize ()

Returns the number of vector components. 2 for float2, 4 for float4, etc.

Returns
int element vector size

isCompatible

Added in API level 14
Deprecated in API level 31
public boolean isCompatible (Element e)

Check if the current Element is compatible with another Element. Primitive Elements are compatible if they share the same underlying size and type (i.e. U8 is compatible with A_8). User-defined Elements must be equal in order to be compatible. This requires strict name equivalence for all sub-Elements (in addition to structural equivalence).

Parameters
e Element: The Element to check compatibility with.

Returns
boolean boolean true if the Elements are compatible, otherwise false.

isComplex

Added in API level 11
public boolean isComplex ()

Return if a element is too complex for use as a data source for a Mesh or a Program.

Returns
boolean boolean