java.lang.Object | ||
↳ | android.renderscript.BaseObj | |
↳ | android.renderscript.Allocation |
Known Direct Subclasses |
This class provides the primary method through which data is passed to
and from RenderScript kernels. An Allocation provides the backing store for
a given Type
.
An Allocation also contains a set of usage flags that denote how the
Allocation could be used. For example, an Allocation may have usage flags
specifying that it can be used from a script as well as input to a Sampler
. A developer must synchronize across these
different usages using syncAll(int)
in
order to ensure that different users of the Allocation have a consistent view
of memory. For example, in the case where an Allocation is used as the output
of one kernel and as Sampler input in a later kernel, a developer must call
syncAll(Allocation.USAGE_SCRIPT)
prior to launching the
second kernel to ensure correctness.
An Allocation can be populated with the copyFrom(Bitmap)
routines. For
more complex Element types, the copyFromUnchecked(byte[])
methods can be
used to copy from byte arrays or similar constructs.
For more information about creating an application that uses RenderScript, read the RenderScript developer guide.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Allocation.MipmapControl | Controls mipmap behavior when using the bitmap creation and update functions. | ||||||||||
Allocation.OnBufferAvailableListener | Interface to handle notification when new buffers are available via
USAGE_IO_INPUT . |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | USAGE_GRAPHICS_CONSTANTS | The Allocation will be used as the source of shader constants by one or more programs. | |||||||||
int | USAGE_GRAPHICS_RENDER_TARGET | The Allocation will be used as a target for offscreen rendering This was deprecated in API level 16. | |||||||||
int | USAGE_GRAPHICS_TEXTURE | The Allocation will be used as a texture source by one or more graphics programs. | |||||||||
int | USAGE_GRAPHICS_VERTEX | The Allocation will be used as a graphics mesh. | |||||||||
int | USAGE_IO_INPUT | The Allocation will be used as a Surface
consumer. |
|||||||||
int | USAGE_IO_OUTPUT | The Allocation will be used as a Surface
producer. |
|||||||||
int | USAGE_SCRIPT | The Allocation will be bound to and accessed by scripts. | |||||||||
int | USAGE_SHARED | The Allocation's backing store will be inherited from another object
(usually a Bitmap ); copying to or from the
original source Bitmap will cause a synchronization rather than a full
copy. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Copy an array into part of this Allocation.
| |||||||||||
Copy part of an Allocation into this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy an array into part of this Allocation.
| |||||||||||
Copy from an array into a rectangular region in this Allocation.
| |||||||||||
Copy from an array into a rectangular region in this Allocation.
| |||||||||||
Copy from an array into a rectangular region in this Allocation.
| |||||||||||
Copy from an array into a rectangular region in this Allocation.
| |||||||||||
Copy from an array into a rectangular region in this Allocation.
| |||||||||||
Copy a
Bitmap into an Allocation. | |||||||||||
Copy a rectangular region from an Allocation into a rectangular region in
this Allocation.
| |||||||||||
Copy an array of RS objects to the Allocation.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy an Allocation from an Allocation.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into an Allocation from a
Bitmap . | |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy into this Allocation from an array.
| |||||||||||
Copy from the Allocation into a byte array.
| |||||||||||
Copy from the Allocation into a int array.
| |||||||||||
Copy from the Allocation into a float array.
| |||||||||||
Copy from the Allocation into a short array.
| |||||||||||
Copy from the Allocation into a
Bitmap . | |||||||||||
Copy from the Allocation into an array.
| |||||||||||
Creates a cubemap Allocation from a
Bitmap
containing the horizontal list of cube faces. | |||||||||||
Creates a non-mipmapped cubemap Allocation for use as a graphics texture
from a
Bitmap containing the horizontal list of
cube faces. | |||||||||||
Creates a non-mipmapped cubemap Allocation for use as a sampler input
from 6
Bitmap objects containing the cube
faces. | |||||||||||
Creates a cubemap Allocation from 6
Bitmap
objects containing the cube faces. | |||||||||||
Creates an Allocation from a
Bitmap . | |||||||||||
Creates an Allocation from a
Bitmap . | |||||||||||
Creates a non-mipmapped Allocation to use as a graphics texture from the
Bitmap referenced by resource ID. | |||||||||||
Creates an Allocation from the Bitmap referenced
by resource ID.
| |||||||||||
Creates an Allocation containing string data encoded in UTF-8 format.
| |||||||||||
Creates an Allocation with a specified number of given elements
| |||||||||||
Creates an Allocation with a specified number of given elements
| |||||||||||
Creates an Allocation for use by scripts with a given
Type and no mipmaps | |||||||||||
Creates an Allocation with the size specified by the type and no mipmaps
generated by default
| |||||||||||
Creates a new Allocation with the given
Type , mipmap flag, and usage flags. | |||||||||||
Generate a mipmap chain.
| |||||||||||
Get the size of the Allocation in bytes.
| |||||||||||
Returns the handle to a raw buffer that is being managed by the screen
compositor.
| |||||||||||
Get the
Type of the Allocation. | |||||||||||
Get the usage flags of the Allocation.
| |||||||||||
Receive the latest input into the Allocation.
| |||||||||||
Send a buffer to the output stream.
| |||||||||||
This method was deprecated
in API level 18.
RenderScript objects should be immutable once created. The
replacement is to create a new allocation and copy the contents.
| |||||||||||
This is only intended to be used by auto-generated code reflected from
the RenderScript script files and should not be used by developers.
| |||||||||||
This is only intended to be used by auto-generated code reflected from
the RenderScript script files.
| |||||||||||
Set a notification handler for
USAGE_IO_INPUT . | |||||||||||
Associate a
Surface with this Allocation. | |||||||||||
Propagate changes from one usage of the Allocation to the
other usages of the Allocation.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.renderscript.BaseObj
| |||||||||||
From class
java.lang.Object
|
The Allocation will be used as the source of shader constants by one or more programs. This was deprecated in API level 16.
The Allocation will be used as a target for offscreen rendering This was deprecated in API level 16.
The Allocation will be used as a texture source by one or more graphics programs.
The Allocation will be used as a graphics mesh. This was deprecated in API level 16.
The Allocation will be used as a Surface
consumer. This usage will cause the Allocation to be created
as read-only.
The Allocation will be bound to and accessed by scripts.
The Allocation's backing store will be inherited from another object
(usually a Bitmap
); copying to or from the
original source Bitmap will cause a synchronization rather than a full
copy. syncAll(int)
may also be used to synchronize the Allocation
and the source Bitmap.
This is set by default for allocations created with createFromBitmap(RenderScript, Bitmap)
in API version 18 and higher.
Copy an array into part of this Allocation. This variant is type checked and will generate exceptions if the Allocation type is not a 32 bit float type.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array. |
Copy part of an Allocation into this Allocation.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
data | the source data allocation. |
dataOff | off The offset of the first element in data to be copied. |
Copy an array into part of this Allocation. This variant is type checked and will generate exceptions if the Allocation type is not a 16 bit integer type.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This variant is type checked and will generate exceptions if the Allocation type is not a 32 bit integer type.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This variant is type checked and will generate exceptions if the Allocation type does not match the component type of the array passed in.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
array | The source data array. |
Copy an array into part of this Allocation. This variant is type checked and will generate exceptions if the Allocation type is not an 8 bit integer type.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This method does not guarantee that the Allocation is compatible with the input buffer.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This method does not guarantee that the Allocation is compatible with the input buffer.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This method does not guarantee that the Allocation is compatible with the input buffer.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This method does not guarantee that the Allocation is compatible with the input buffer.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
d | the source data array |
Copy an array into part of this Allocation. This method does not guarantee that the Allocation is compatible with the input buffer.
off | The offset of the first element to be copied. |
---|---|
count | The number of elements to be copied. |
array | The source data array |
Copy from an array into a rectangular region in this Allocation. The array is assumed to be tightly packed.
xoff | X offset of the region to update in this Allocation |
---|---|
yoff | Y offset of the region to update in this Allocation |
w | Width of the region to update |
h | Height of the region to update |
data | to be placed into the Allocation |
Copy from an array into a rectangular region in this Allocation. The array is assumed to be tightly packed.
xoff | X offset of the region to update in this Allocation |
---|---|
yoff | Y offset of the region to update in this Allocation |
w | Width of the region to update |
h | Height of the region to update |
data | to be placed into the Allocation |
Copy from an array into a rectangular region in this Allocation. The array is assumed to be tightly packed.
xoff | X offset of the region to update in this Allocation |
---|---|
yoff | Y offset of the region to update in this Allocation |
w | Width of the region to update |
h | Height of the region to update |
array | Data to be placed into the Allocation |
Copy from an array into a rectangular region in this Allocation. The array is assumed to be tightly packed.
xoff | X offset of the region to update in this Allocation |
---|---|
yoff | Y offset of the region to update in this Allocation |
w | Width of the region to update |
h | Height of the region to update |
data | to be placed into the Allocation |
Copy from an array into a rectangular region in this Allocation. The array is assumed to be tightly packed.
xoff | X offset of the region to update in this Allocation |
---|---|
yoff | Y offset of the region to update in this Allocation |
w | Width of the region to update |
h | Height of the region to update |
data | to be placed into the Allocation |
Copy a rectangular region from an Allocation into a rectangular region in this Allocation.
xoff | X offset of the region in this Allocation |
---|---|
yoff | Y offset of the region in this Allocation |
w | Width of the region to update. |
h | Height of the region to update. |
data | source Allocation. |
dataXoff | X offset in source Allocation |
dataYoff | Y offset in source Allocation |
Copy an array of RS objects to the Allocation.
d | Source array. |
---|
Copy into this Allocation from an array. This variant is type checked
and will generate exceptions if the Allocation's Element
is not an 8 bit integer type.
d | the source data array |
---|
Copy an Allocation from an Allocation. The types of both allocations must be identical.
a | the source allocation |
---|
Copy into this Allocation from an array. This variant is type checked
and will generate exceptions if the Allocation's Element
is not a 32 bit integer type.
d | the source data array |
---|
Copy into this Allocation from an array. This variant is type checked
and will generate exceptions if the Allocation's Element
is not a 32 bit float type.
d | the source data array |
---|
Copy into this Allocation from an array. This variant is type checked
and will generate exceptions if the Allocation's Element
does not match the array's
primitive type.
array | The source data array |
---|
Copy into an Allocation from a Bitmap
. The
height, width, and format of the bitmap must match the existing
allocation.
If the Bitmap
is the same as the Bitmap
used to create the Allocation with createFromBitmap(RenderScript, Bitmap)
and USAGE_SHARED
is set on the Allocation,
this will synchronize the Allocation with the latest data from the Bitmap
, potentially avoiding the actual copy.
b | the source bitmap |
---|
Copy into this Allocation from an array. This variant is type checked
and will generate exceptions if the Allocation's Element
is not a 16 bit integer type.
d | the source data array |
---|
Copy into this Allocation from an array. This method does not guarantee that the Allocation is compatible with the input buffer; it copies memory without reinterpretation.
d | the source data array |
---|
Copy into this Allocation from an array. This method does not guarantee that the Allocation is compatible with the input buffer; it copies memory without reinterpretation.
d | the source data array |
---|
Copy into this Allocation from an array. This method does not guarantee that the Allocation is compatible with the input buffer; it copies memory without reinterpretation.
d | the source data array |
---|
Copy into this Allocation from an array. This method does not guarantee that the Allocation is compatible with the input buffer; it copies memory without reinterpretation.
array | The source data array |
---|
Copy into this Allocation from an array. This method does not guarantee that the Allocation is compatible with the input buffer; it copies memory without reinterpretation.
d | the source data array |
---|
Copy from the Allocation into a byte array. The array must be at least
as large as the Allocation. The allocation must be of an 8 bit integer
Element
type.
d | The array to be set from the Allocation. |
---|
Copy from the Allocation into a int array. The array must be at least as
large as the Allocation. The allocation must be of an 32 bit integer
Element
type.
d | The array to be set from the Allocation. |
---|
Copy from the Allocation into a float array. The array must be at least
as large as the Allocation. The allocation must be of an 32 bit float
Element
type.
d | The array to be set from the Allocation. |
---|
Copy from the Allocation into a short array. The array must be at least
as large as the Allocation. The allocation must be of an 16 bit integer
Element
type.
d | The array to be set from the Allocation. |
---|
Copy from the Allocation into a Bitmap
. The
bitmap must match the dimensions of the Allocation.
b | The bitmap to be set from the Allocation. |
---|
Copy from the Allocation into an array. The array must be at
least as large as the Allocation. The
Element
must match the component
type of the array passed in.
array | The array to be set from the Allocation. |
---|
Creates a cubemap Allocation from a Bitmap
containing the horizontal list of cube faces. Each face must be a square,
have the same size as all other faces, and have a width that is a power
of 2.
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 |
Creates a non-mipmapped cubemap Allocation for use as a graphics texture
from a Bitmap
containing the horizontal list of
cube faces. Each face must be a square, have the same size as all other
faces, and have a width that is a power of 2.
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 |
Creates a non-mipmapped cubemap Allocation for use as a sampler input
from 6 Bitmap
objects containing the cube
faces. Each face must be a square, have the same size as all other faces,
and have a width that is a power of 2.
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 |
Creates a cubemap Allocation from 6 Bitmap
objects containing the cube faces. Each face must be a square, have the
same size as all other faces, and have a width that is a power of 2.
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 |
Creates an Allocation from a Bitmap
.
With target API version 18 or greater, this Allocation will be created
with USAGE_SHARED
, USAGE_SCRIPT
, and USAGE_GRAPHICS_TEXTURE
. With target API version 17 or lower, this
Allocation will be created with USAGE_GRAPHICS_TEXTURE
.
rs | Context to which the allocation will belong. |
---|---|
b | bitmap source for the allocation data |
Creates an Allocation from a Bitmap
.
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 |
Creates a non-mipmapped Allocation to use as a graphics texture from the
Bitmap
referenced by resource ID.
With target API version 18 or greater, this allocation will be created
with USAGE_SCRIPT
and USAGE_GRAPHICS_TEXTURE
. With
target API version 17 or lower, this allocation will be created with
USAGE_GRAPHICS_TEXTURE
.
rs | Context to which the allocation will belong. |
---|---|
res | application resources |
id | resource id to load the data from |
Creates an Allocation from the Bitmap referenced by resource ID.
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 |
Creates an Allocation containing string data encoded in UTF-8 format.
rs | Context to which the allocation will belong. |
---|---|
str | string to create the allocation from |
usage | bit field specifying how the allocaiton is utilized |
Creates an Allocation with a specified number of given elements
rs | Context to which the Allocation will belong. |
---|---|
e | Element to use in the Allocation |
count | the number of Elements in the Allocation |
Creates an Allocation with a specified number of given elements
rs | Context to which the Allocation will belong. |
---|---|
e | Element to use in the Allocation |
count | the number of Elements in the Allocation |
usage | bit field specifying how the Allocation is utilized |
Creates an Allocation for use by scripts with a given Type
and no mipmaps
rs | Context to which the Allocation will belong. |
---|---|
type | RenderScript Type describing data layout |
Creates an Allocation with the size specified by the type and no mipmaps generated by default
rs | Context to which the allocation will belong. |
---|---|
type | renderscript type describing data layout |
usage | bit field specifying how the allocation is utilized |
Creates a new Allocation with the given Type
, mipmap flag, and usage flags.
type | RenderScript type describing data layout |
---|---|
mips | specifies desired mipmap behaviour for the allocation |
usage | bit field specifying how the Allocation is utilized |
Generate a mipmap chain. This is only valid if the Type of the Allocation includes mipmaps.
This function will generate a complete set of mipmaps from the top level LOD and place them into the script memory space.
If the Allocation is also using other memory spaces, a call to syncAll(Allocation.USAGE_SCRIPT)
is required.
Get the size of the Allocation in bytes.
Returns the handle to a raw buffer that is being managed by the screen
compositor. This operation is only valid for Allocations with USAGE_IO_INPUT
.
Get the usage flags of the Allocation.
Receive the latest input into the Allocation. This operation
is only valid if USAGE_IO_INPUT
is set on the Allocation.
Send a buffer to the output stream. The contents of the Allocation will
be undefined after this operation. This operation is only valid if USAGE_IO_OUTPUT
is set on the Allocation.
This method was deprecated
in API level 18.
RenderScript objects should be immutable once created. The
replacement is to create a new allocation and copy the contents.
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.
dimX | The new size of the allocation. |
---|
This is only intended to be used by auto-generated code reflected from the RenderScript script files and should not be used by developers.
This is only intended to be used by auto-generated code reflected from the RenderScript script files.
Set a notification handler for USAGE_IO_INPUT
.
callback | instance of the OnBufferAvailableListener class to be called when buffer arrive. |
---|
Associate a Surface
with this Allocation. This
operation is only valid for Allocations with USAGE_IO_OUTPUT
.
sur | Surface to associate with allocation |
---|
Propagate changes from one usage of the Allocation to the other usages of the Allocation.
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
Throwable |
---|