加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20110312162752/http://developer.android.com:80/reference/android/renderscript/Allocation.html
public class

Allocation

extends Object
java.lang.Object
   ↳ android.renderscript.Allocation
Known Direct Subclasses

Class Overview

Memory allocation class for renderscript. An allocation combines a Type with the memory to provide storage for user data and objects. This implies that all memory in Renderscript is typed.

Allocations are the primary way data moves into and out of scripts. Memory is user synchronized and it's possible for allocations to exist in multiple memory spaces concurrently. Currently those spaces are:

  • Script: accessable by RS scripts.
  • Graphics Texture: accessable as a graphics texture.
  • Graphics Vertex: accessable as graphical vertex data.
  • Graphics Constants: Accessable as constants in user shaders

For example, when creating a allocation for a texture, the user can specify its memory spaces as both script and textures. This means that it can both be used as script binding and as a GPU texture for rendering. To maintain synchronization if a script modifies an allocation used by other targets it must call a synchronizing function to push the updates to the memory, otherwise the results are undefined.

By default, Android system side updates are always applied to the script accessable memory. If this is not present, they are then applied to the various HW memory types. A syncAll() call is necessary after the script data is updated to keep the other memory spaces in sync.

Allocation data is uploaded in one of two primary ways. For simple arrays there are copyFrom() functions that take an array from the control code and copy it to the slave memory store. Both type checked and unchecked copies are provided. The unchecked variants exist to allow apps to copy over arrays of structures from a control language that does not support structures.

Summary

Nested Classes
enum Allocation.MipmapControl Controls mipmap behavior when using the bitmap creation and update functions. 
Constants
int USAGE_GRAPHICS_CONSTANTS GRAPHICS_CONSTANTS The allocation will be used as the source of shader constants by one or more programs.
int USAGE_GRAPHICS_TEXTURE GRAPHICS_TEXTURE The allcation will be used as a texture source by one or more graphcics programs.
int USAGE_GRAPHICS_VERTEX GRAPHICS_VERTEX The allocation will be used as a graphics mesh.
int USAGE_SCRIPT The usage of the allocation.
Public Methods
void copy1DRangeFrom(int off, int count, float[] d)
Copy part of an allocation from an array.
void copy1DRangeFrom(int off, int count, short[] d)
Copy part of an allocation from an array.
void copy1DRangeFrom(int off, int count, int[] d)
Copy part of an allocation from an array.
void copy1DRangeFrom(int off, int count, byte[] d)
Copy part of an allocation from an array.
void copy1DRangeFromUnchecked(int off, int count, byte[] d)
Copy part of an allocation from an array.
void copy1DRangeFromUnchecked(int off, int count, short[] d)
Copy part of an allocation from an array.
void copy1DRangeFromUnchecked(int off, int count, float[] d)
Copy part of an allocation from an array.
void copy1DRangeFromUnchecked(int off, int count, int[] d)
Copy part of an allocation from an array.
void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data)
void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data)
Copy a rectanglular region from the array into the allocation.
void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data)
void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data)
void copy2DRangeFrom(int xoff, int yoff, Bitmap data)
Copy a bitmap into an allocation.
void copyFrom(BaseObj[] d)
void copyFrom(byte[] d)
Copy an allocation from an array.
void copyFrom(int[] d)
Copy an allocation from an array.
void copyFrom(float[] d)
Copy an allocation from an array.
void copyFrom(Bitmap b)
Copy an allocation from a bitmap.
void copyFrom(short[] d)
Copy an allocation from an array.
void copyFromUnchecked(int[] d)
Copy an allocation from an array.
void copyFromUnchecked(short[] d)
Copy an allocation from an array.
void copyFromUnchecked(byte[] d)
Copy an allocation from an array.
void copyFromUnchecked(float[] d)
Copy an allocation from an array.
void copyTo(byte[] d)
void copyTo(int[] d)
void copyTo(float[] d)
void copyTo(short[] d)
void copyTo(Bitmap b)
static Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b, Allocation.MipmapControl mips, int usage)
Creates a cubemap allocation from a bitmap containing the horizontal list of cube faces.
static Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b)
Creates a non-mipmapped cubemap allocation for use as a graphics texture from a bitmap containing the horizontal list of cube faces.
static Allocation createCubemapFromCubeFaces(RenderScript rs, Bitmap xpos, Bitmap xneg, Bitmap ypos, Bitmap yneg, Bitmap zpos, Bitmap zneg)
Creates a non-mipmapped cubemap allocation for use as a graphics texture from 6 bitmaps containing the cube faces.
static Allocation createCubemapFromCubeFaces(RenderScript rs, Bitmap xpos, Bitmap xneg, Bitmap ypos, Bitmap yneg, Bitmap zpos, Bitmap zneg, Allocation.MipmapControl mips, int usage)
Creates a cubemap allocation from 6 bitmaps containing the cube faces.
static Allocation createFromBitmap(RenderScript rs, Bitmap b)
Creates a non-mipmapped renderscript allocation to use as a graphics texture
static Allocation createFromBitmap(RenderScript rs, Bitmap b, Allocation.MipmapControl mips, int usage)
Creates a renderscript allocation from a bitmap
static Allocation createFromBitmapResource(RenderScript rs, Resources res, int id)
Creates a non-mipmapped renderscript allocation to use as a graphics texture from the bitmap referenced by resource id
static Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Allocation.MipmapControl mips, int usage)
Creates a renderscript allocation from the bitmap referenced by resource id
static Allocation createFromString(RenderScript rs, String str, int usage)
Creates a renderscript allocation containing string data encoded in UTF-8 format
static Allocation createSized(RenderScript rs, Element e, int count)
Creates a renderscript allocation with a specified number of given elements
static Allocation createSized(RenderScript rs, Element e, int count, int usage)
Creates a renderscript allocation with a specified number of given elements
static Allocation createTyped(RenderScript rs, Type type)
Creates a renderscript allocation for use by the script with the size specified by the type and no mipmaps generated by default
static Allocation createTyped(RenderScript rs, Type type, int usage)
Creates a renderscript allocation with the size specified by the type and no mipmaps generated by default
static Allocation createTyped(RenderScript rs, Type type, Allocation.MipmapControl mips, int usage)
synchronized void destroy()
destroy disconnects the object from the native object effectivly rendering this java object dead.
void generateMipmaps()
Generate a mipmap chain.
Type getType()
synchronized void resize(int dimX)
Resize a 1D allocation.
void setFromFieldPacker(int xoff, FieldPacker fp)
This is only intended to be used by auto-generate code reflected from the renderscript script files.
void setFromFieldPacker(int xoff, int component_number, FieldPacker fp)
This is only intended to be used by auto-generate code reflected from the renderscript script files.
void setName(String name)
setName assigns a name to an object.
void syncAll(int srcLocation)
Protected Methods
void finalize()
Called before the object's memory is reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int USAGE_GRAPHICS_CONSTANTS

Since: API Level 11

GRAPHICS_CONSTANTS The allocation will be used as the source of shader constants by one or more programs.

Constant Value: 8 (0x00000008)

public static final int USAGE_GRAPHICS_TEXTURE

Since: API Level 11

GRAPHICS_TEXTURE The allcation will be used as a texture source by one or more graphcics programs.

Constant Value: 2 (0x00000002)

public static final int USAGE_GRAPHICS_VERTEX

Since: API Level 11

GRAPHICS_VERTEX The allocation will be used as a graphics mesh.

Constant Value: 4 (0x00000004)

public static final int USAGE_SCRIPT

Since: API Level 11

The usage of the allocation. These signal to renderscript where to place the allocation in memory. SCRIPT The allocation will be bound to and accessed by scripts.

Constant Value: 1 (0x00000001)

Public Methods

public void copy1DRangeFrom (int off, int count, float[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 32 bit float type.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFrom (int off, int count, short[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 16 bit integer type.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFrom (int off, int count, int[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 32 bit integer type.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFrom (int off, int count, byte[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 8 bit integer type.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFromUnchecked (int off, int count, byte[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFromUnchecked (int off, int count, short[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFromUnchecked (int off, int count, float[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy1DRangeFromUnchecked (int off, int count, int[] d)

Since: API Level 11

Copy part of an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
off The offset of the first element to be copied.
count The number of elements to be copied.
d the source data array

public void copy2DRangeFrom (int xoff, int yoff, int w, int h, float[] data)

Since: API Level 11

public void copy2DRangeFrom (int xoff, int yoff, int w, int h, byte[] data)

Since: API Level 11

Copy a rectanglular region from the array into the allocation. The incoming array is assumed to be tightly packed.

Parameters
xoff X offset of the region to update
yoff Y offset of the region to update
w Width of the incoming region to update
h Height of the incoming region to update
data to be placed into the allocation

public void copy2DRangeFrom (int xoff, int yoff, int w, int h, int[] data)

Since: API Level 11

public void copy2DRangeFrom (int xoff, int yoff, int w, int h, short[] data)

Since: API Level 11

public void copy2DRangeFrom (int xoff, int yoff, Bitmap data)

Since: API Level 11

Copy a bitmap into an allocation. The height and width of the update will use the height and width of the incoming bitmap.

Parameters
xoff X offset of the region to update
yoff Y offset of the region to update
data the bitmap to be copied

public void copyFrom (BaseObj[] d)

Since: API Level 11

public void copyFrom (byte[] d)

Since: API Level 11

Copy an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 8 bit integer type.

Parameters
d the source data array

public void copyFrom (int[] d)

Since: API Level 11

Copy an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 32 bit integer type.

Parameters
d the source data array

public void copyFrom (float[] d)

Since: API Level 11

Copy an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 32 bit float type.

Parameters
d the source data array

public void copyFrom (Bitmap b)

Since: API Level 11

Copy an allocation from a bitmap. The height, width, and format of the bitmap must match the existing allocation.

Parameters
b the source bitmap

public void copyFrom (short[] d)

Since: API Level 11

Copy an allocation from an array. This variant is type checked and will generate exceptions if the Allocation type is not a 16 bit integer type.

Parameters
d the source data array

public void copyFromUnchecked (int[] d)

Since: API Level 11

Copy an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
d the source data array

public void copyFromUnchecked (short[] d)

Since: API Level 11

Copy an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
d the source data array

public void copyFromUnchecked (byte[] d)

Since: API Level 11

Copy an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
d the source data array

public void copyFromUnchecked (float[] d)

Since: API Level 11

Copy an allocation from an array. This variant is not type checked which allows an application to fill in structured data from an array.

Parameters
d the source data array

public void copyTo (byte[] d)

Since: API Level 11

public void copyTo (int[] d)

Since: API Level 11

public void copyTo (float[] d)

Since: API Level 11

public void copyTo (short[] d)

Since: API Level 11

public void copyTo (Bitmap b)

Since: API Level 11

public static Allocation createCubemapFromBitmap (RenderScript rs, Bitmap b, Allocation.MipmapControl mips, int usage)

Since: API Level 11

Creates a cubemap allocation from a bitmap containing the horizontal list of cube faces. Each individual face must be the same size and power of 2

Parameters
rs Context to which the allocation will belong.
b bitmap with cubemap faces layed out in the following format: right, left, top, bottom, front, back
mips specifies desired mipmap behaviour for the cubemap
usage bit field specifying how the cubemap is utilized
Returns
  • allocation containing cubemap data

public static Allocation createCubemapFromBitmap (RenderScript rs, Bitmap b)

Since: API Level 11

Creates a non-mipmapped cubemap allocation for use as a graphics texture from a bitmap containing the horizontal list of cube faces. Each individual face must be the same size and power of 2

Parameters
rs Context to which the allocation will belong.
b bitmap with cubemap faces layed out in the following format: right, left, top, bottom, front, back
Returns
  • allocation containing cubemap data

public static Allocation createCubemapFromCubeFaces (RenderScript rs, Bitmap xpos, Bitmap xneg, Bitmap ypos, Bitmap yneg, Bitmap zpos, Bitmap zneg)

Since: API Level 11

Creates a non-mipmapped cubemap allocation for use as a graphics texture from 6 bitmaps containing the cube faces. All the faces must be the same size and power of 2

Parameters
rs Context to which the allocation will belong.
xpos cubemap face in the positive x direction
xneg cubemap face in the negative x direction
ypos cubemap face in the positive y direction
yneg cubemap face in the negative y direction
zpos cubemap face in the positive z direction
zneg cubemap face in the negative z direction
Returns
  • allocation containing cubemap data

public static Allocation createCubemapFromCubeFaces (RenderScript rs, Bitmap xpos, Bitmap xneg, Bitmap ypos, Bitmap yneg, Bitmap zpos, Bitmap zneg, Allocation.MipmapControl mips, int usage)

Since: API Level 11

Creates a cubemap allocation from 6 bitmaps containing the cube faces. All the faces must be the same size and power of 2

Parameters
rs Context to which the allocation will belong.
xpos cubemap face in the positive x direction
xneg cubemap face in the negative x direction
ypos cubemap face in the positive y direction
yneg cubemap face in the negative y direction
zpos cubemap face in the positive z direction
zneg cubemap face in the negative z direction
mips specifies desired mipmap behaviour for the cubemap
usage bit field specifying how the cubemap is utilized
Returns
  • allocation containing cubemap data

public static Allocation createFromBitmap (RenderScript rs, Bitmap b)

Since: API Level 11

Creates a non-mipmapped renderscript allocation to use as a graphics texture

Parameters
rs Context to which the allocation will belong.
b bitmap source for the allocation data
Returns
  • renderscript allocation containing bitmap data

public static Allocation createFromBitmap (RenderScript rs, Bitmap b, Allocation.MipmapControl mips, int usage)

Since: API Level 11

Creates a renderscript allocation from a bitmap

Parameters
rs Context to which the allocation will belong.
b bitmap source for the allocation data
mips specifies desired mipmap behaviour for the allocation
usage bit field specifying how the allocation is utilized
Returns
  • renderscript allocation containing bitmap data

public static Allocation createFromBitmapResource (RenderScript rs, Resources res, int id)

Since: API Level 11

Creates a non-mipmapped renderscript allocation to use as a graphics texture from the bitmap referenced by resource id

Parameters
rs Context to which the allocation will belong.
res application resources
id resource id to load the data from
Returns
  • renderscript allocation containing resource data

public static Allocation createFromBitmapResource (RenderScript rs, Resources res, int id, Allocation.MipmapControl mips, int usage)

Since: API Level 11

Creates a renderscript allocation from the bitmap referenced by resource id

Parameters
rs Context to which the allocation will belong.
res application resources
id resource id to load the data from
mips specifies desired mipmap behaviour for the allocation
usage bit field specifying how the allocation is utilized
Returns
  • renderscript allocation containing resource data

public static Allocation createFromString (RenderScript rs, String str, int usage)

Since: API Level 11

Creates a renderscript allocation containing string data encoded in UTF-8 format

Parameters
rs Context to which the allocation will belong.
str string to create the allocation from
usage bit field specifying how the allocaiton is utilized

public static Allocation createSized (RenderScript rs, Element e, int count)

Since: API Level 11

Creates a renderscript allocation with a specified number of given elements

Parameters
rs Context to which the allocation will belong.
e describes what each element of an allocation is
count specifies the number of element in the allocation
Returns
  • allocation

public static Allocation createSized (RenderScript rs, Element e, int count, int usage)

Since: API Level 11

Creates a renderscript allocation with a specified number of given elements

Parameters
rs Context to which the allocation will belong.
e describes what each element of an allocation is
count specifies the number of element in the allocation
usage bit field specifying how the allocation is utilized
Returns
  • allocation

public static Allocation createTyped (RenderScript rs, Type type)

Since: API Level 11

Creates a renderscript allocation for use by the script with the size specified by the type and no mipmaps generated by default

Parameters
rs Context to which the allocation will belong.
type renderscript type describing data layout
Returns
  • allocation

public static Allocation createTyped (RenderScript rs, Type type, int usage)

Since: API Level 11

Creates a renderscript allocation with the size specified by the type and no mipmaps generated by default

Parameters
rs Context to which the allocation will belong.
type renderscript type describing data layout
usage bit field specifying how the allocation is utilized
Returns
  • allocation

public static Allocation createTyped (RenderScript rs, Type type, Allocation.MipmapControl mips, int usage)

Since: API Level 11

Parameters
type renderscript type describing data layout
mips specifies desired mipmap behaviour for the allocation
usage bit field specifying how the allocation is utilized

public synchronized void destroy ()

Since: API Level 11

destroy disconnects the object from the native object effectivly rendering this java object dead. The primary use is to force immediate cleanup of resources when its believed the GC will not respond quickly enough.

public void generateMipmaps ()

Since: API Level 11

Generate a mipmap chain. Requires the type of the allocation include mipmaps. This function will generate a complete set of mipmaps from the top level lod and place them into the script memoryspace. If the allocation is also using other memory spaces a followup sync will be required.

public Type getType ()

Since: API Level 11

public synchronized void resize (int dimX)

Since: API Level 11

Resize a 1D allocation. The contents of the allocation are preserved. If new elements are allocated objects are created with null contents and the new region is otherwise undefined. If the new region is smaller the references of any objects outside the new region will be released. A new type will be created with the new dimension.

Parameters
dimX The new size of the allocation.

public void setFromFieldPacker (int xoff, FieldPacker fp)

Since: API Level 11

This is only intended to be used by auto-generate code reflected from the renderscript script files.

public void setFromFieldPacker (int xoff, int component_number, FieldPacker fp)

Since: API Level 11

This is only intended to be used by auto-generate code reflected from the renderscript script files.

public void setName (String name)

Since: API Level 11

setName assigns a name to an object. This object can later be looked up by this name. This name will also be retained if the object is written to an A3D file.

Parameters
name The name to assign to the object.

public void syncAll (int srcLocation)

Since: API Level 11

Protected Methods

protected void finalize ()

Since: API Level 11

Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable