am 411473de: am caa8a8fb: Merge "[Renderscript] JAVA API update for Allocation.CopyTo add the following functions to make it more symmetric to copyFrom()."

* commit '411473de4a558747b003f27190f61c75bf9e12c7':
  [Renderscript] JAVA API update for Allocation.CopyTo add the following functions to make it more symmetric to copyFrom().
This commit is contained in:
Miao Wang
2015-03-03 01:36:16 +00:00
committed by Android Git Automerger
3 changed files with 443 additions and 14 deletions

View File

@ -794,12 +794,47 @@ public class Allocation extends BaseObj {
* @param fp
*/
public void setFromFieldPacker(int xoff, int component_number, FieldPacker fp) {
setFromFieldPacker(xoff, 0, 0, component_number, fp);
}
/**
* @hide
* This is only intended to be used by auto-generated code reflected from
* the RenderScript script files.
*
* @param xoff
* @param yoff
* @param component_number
* @param fp
*/
public void setFromFieldPacker(int xoff, int yoff, int component_number, FieldPacker fp) {
setFromFieldPacker(xoff, yoff, 0, component_number, fp);
}
/**
* @hide
* This is only intended to be used by auto-generated code reflected from
* the RenderScript script files.
*
* @param xoff
* @param yoff
* @param zoff
* @param component_number
* @param fp
*/
public void setFromFieldPacker(int xoff, int yoff, int zoff, int component_number, FieldPacker fp) {
mRS.validate();
if (component_number >= mType.mElement.mElements.length) {
throw new RSIllegalArgumentException("Component_number " + component_number + " out of range.");
}
if(xoff < 0) {
throw new RSIllegalArgumentException("Offset must be >= 0.");
throw new RSIllegalArgumentException("Offset x must be >= 0.");
}
if(yoff < 0) {
throw new RSIllegalArgumentException("Offset y must be >= 0.");
}
if(zoff < 0) {
throw new RSIllegalArgumentException("Offset z must be >= 0.");
}
final byte[] data = fp.getData();
@ -812,8 +847,8 @@ public class Allocation extends BaseObj {
" does not match component size " + eSize + ".");
}
mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD,
component_number, data, data_length);
mRS.nAllocationElementData(getIDSafe(), xoff, yoff, zoff, mSelectedLOD,
component_number, data, data_length);
}
private void data1DChecks(int off, int count, int len, int dataSize) {
@ -1330,6 +1365,74 @@ public class Allocation extends BaseObj {
copyTo(d, Element.DataType.FLOAT_32, d.length);
}
/**
* @hide
* Copy subelement from the Allocation into an object array.
* This is intended to be used with user defined structs
*
* @param xoff
* @param component_number
* @param array
*/
public void copyElementTo(int xoff, int component_number, Object array) {
copyElementTo(xoff, 0, 0, component_number, array);
}
/**
* @hide
* Copy subelement from the Allocation into an object array.
* This is intended to be used with user defined structs
*
* @param xoff
* @param yoff
* @param component_number
* @param array
*/
public void copyElementTo(int xoff, int yoff, int component_number, Object array) {
copyElementTo(xoff, yoff, 0, component_number, array);
}
/**
* @hide
* Copy subelement from the Allocation into an object array.
* This is intended to be used with user defined structs
*
* @param xoff
* @param yoff
* @param zoff
* @param component_number
* @param array
*/
public void copyElementTo(int xoff, int yoff, int zoff, int component_number, Object array) {
Trace.traceBegin(RenderScript.TRACE_TAG, "copyElementTo");
mRS.validate();
if (component_number >= mType.mElement.mElements.length) {
throw new RSIllegalArgumentException("Component_number " + component_number + " out of range.");
}
if(xoff < 0) {
throw new RSIllegalArgumentException("Offset x must be >= 0.");
}
if(yoff < 0) {
throw new RSIllegalArgumentException("Offset y must be >= 0.");
}
if(zoff < 0) {
throw new RSIllegalArgumentException("Offset z must be >= 0.");
}
Element.DataType dt = validateObjectIsPrimitiveArray(array, false);
int array_size = java.lang.reflect.Array.getLength(array) * dt.mSize;
int eSize = mType.mElement.mElements[component_number].getBytesSize();
eSize *= mType.mElement.mArraySizes[component_number];
if (array_size < eSize) {
throw new RSIllegalArgumentException("Array Size (bytes)" + array_size +
" is smaller than component size " + eSize + ".");
}
mRS.nAllocationElementRead(getIDSafe(), xoff, yoff, zoff, mSelectedLOD,
component_number, array, eSize, dt);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
/**
* Resize a 1D allocation. The contents of the allocation are preserved.
* If new elements are allocated objects are created with null contents and
@ -1362,6 +1465,282 @@ public class Allocation extends BaseObj {
updateCacheInfo(mType);
}
private void copy1DRangeToUnchecked(int off, int count, Object array,
Element.DataType dt, int arrayLen) {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeToUnchecked");
final int dataSize = mType.mElement.getBytesSize() * count;
data1DChecks(off, count, arrayLen * dt.mSize, dataSize);
mRS.nAllocationRead1D(getIDSafe(), off, mSelectedLOD, count, array, dataSize, dt);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* guarantee that the Allocation is compatible with the input buffer.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param array The dest data array
*/
public void copy1DRangeToUnchecked(int off, int count, Object array) {
copy1DRangeToUnchecked(off, count, array,
validateObjectIsPrimitiveArray(array, false),
java.lang.reflect.Array.getLength(array));
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* guarantee that the Allocation is compatible with the input buffer.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeToUnchecked(int off, int count, int[] d) {
copy1DRangeToUnchecked(off, count, (Object)d, Element.DataType.SIGNED_32, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* guarantee that the Allocation is compatible with the input buffer.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeToUnchecked(int off, int count, short[] d) {
copy1DRangeToUnchecked(off, count, (Object)d, Element.DataType.SIGNED_16, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* guarantee that the Allocation is compatible with the input buffer.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeToUnchecked(int off, int count, byte[] d) {
copy1DRangeToUnchecked(off, count, (Object)d, Element.DataType.SIGNED_8, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* guarantee that the Allocation is compatible with the input buffer.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeToUnchecked(int off, int count, float[] d) {
copy1DRangeToUnchecked(off, count, (Object)d, Element.DataType.FLOAT_32, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* and will generate exceptions if the Allocation type does not
* match the component type of the array passed in.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param array The source data array.
*/
public void copy1DRangeTo(int off, int count, Object array) {
copy1DRangeToUnchecked(off, count, array,
validateObjectIsPrimitiveArray(array, true),
java.lang.reflect.Array.getLength(array));
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* and will generate exceptions if the Allocation type is not a 32 bit
* integer type.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeTo(int off, int count, int[] d) {
validateIsInt32();
copy1DRangeToUnchecked(off, count, d, Element.DataType.SIGNED_32, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* and will generate exceptions if the Allocation type is not a 16 bit
* integer type.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeTo(int off, int count, short[] d) {
validateIsInt16();
copy1DRangeToUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* and will generate exceptions if the Allocation type is not an 8 bit
* integer type.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array
*/
public void copy1DRangeTo(int off, int count, byte[] d) {
validateIsInt8();
copy1DRangeToUnchecked(off, count, d, Element.DataType.SIGNED_8, d.length);
}
/**
* @hide
* Copy part of this Allocation into an array. This method does not
* and will generate exceptions if the Allocation type is not a 32 bit float
* type.
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
* @param d the source data array.
*/
public void copy1DRangeTo(int off, int count, float[] d) {
validateIsFloat32();
copy1DRangeToUnchecked(off, count, d, Element.DataType.FLOAT_32, d.length);
}
void copy2DRangeToUnchecked(int xoff, int yoff, int w, int h, Object array,
Element.DataType dt, int arrayLen) {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeToUnchecked");
mRS.validate();
validate2DRange(xoff, yoff, w, h);
mRS.nAllocationRead2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
array, arrayLen * dt.mSize, dt);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
/**
* @hide
* Copy from a rectangular region in this Allocation into an array.
*
* @param xoff X offset of the region to copy in this Allocation
* @param yoff Y offset of the region to copy in this Allocation
* @param w Width of the region to copy
* @param h Height of the region to copy
* @param array Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, Object array) {
copy2DRangeToUnchecked(xoff, yoff, w, h, array,
validateObjectIsPrimitiveArray(array, true),
java.lang.reflect.Array.getLength(array));
}
/**
* @hide
* Copy from a rectangular region in this Allocation into an array.
*
* @param xoff X offset of the region to copy in this Allocation
* @param yoff Y offset of the region to copy in this Allocation
* @param w Width of the region to copy
* @param h Height of the region to copy
* @param array Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, byte[] data) {
validateIsInt8();
copy2DRangeToUnchecked(xoff, yoff, w, h, data,
Element.DataType.SIGNED_8, data.length);
}
/**
* @hide
* Copy from a rectangular region in this Allocation into an array.
*
* @param xoff X offset of the region to copy in this Allocation
* @param yoff Y offset of the region to copy in this Allocation
* @param w Width of the region to copy
* @param h Height of the region to copy
* @param array Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, short[] data) {
validateIsInt16();
copy2DRangeToUnchecked(xoff, yoff, w, h, data,
Element.DataType.SIGNED_16, data.length);
}
/**
* @hide
* Copy from a rectangular region in this Allocation into an array.
*
* @param xoff X offset of the region to copy in this Allocation
* @param yoff Y offset of the region to copy in this Allocation
* @param w Width of the region to copy
* @param h Height of the region to copy
* @param array Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, int[] data) {
validateIsInt32();
copy2DRangeToUnchecked(xoff, yoff, w, h, data,
Element.DataType.SIGNED_32, data.length);
}
/**
* @hide
* Copy from a rectangular region in this Allocation into an array.
*
* @param xoff X offset of the region to copy in this Allocation
* @param yoff Y offset of the region to copy in this Allocation
* @param w Width of the region to copy
* @param h Height of the region to copy
* @param array Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, float[] data) {
validateIsFloat32();
copy2DRangeToUnchecked(xoff, yoff, w, h, data,
Element.DataType.FLOAT_32, data.length);
}
/**
* @hide
*
*/
private void copy3DRangeToUnchecked(int xoff, int yoff, int zoff, int w, int h, int d,
Object array, Element.DataType dt, int arrayLen) {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeToUnchecked");
mRS.validate();
validate3DRange(xoff, yoff, zoff, w, h, d);
mRS.nAllocationRead3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
array, arrayLen * dt.mSize, dt);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
/**
* @hide
* Copy from a rectangular region in this Allocation into an array.
*
* @param xoff X offset of the region to copy in this Allocation
* @param yoff Y offset of the region to copy in this Allocation
* @param zoff Z offset of the region to copy in this Allocation
* @param w Width of the region to copy
* @param h Height of the region to copy
* @param d Depth of the region to copy
* @param array Dest Array to be copied into
*/
public void copy3DRangeTo(int xoff, int yoff, int zoff, int w, int h, int d, Object array) {
copy3DRangeToUnchecked(xoff, yoff, zoff, w, h, d, array,
validateObjectIsPrimitiveArray(array, true),
java.lang.reflect.Array.getLength(array));
}
// creation

View File

@ -491,10 +491,10 @@ public class RenderScript {
rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID);
}
native void rsnAllocationElementData1D(long con,long id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes);
synchronized void nAllocationElementData1D(long id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) {
native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
synchronized void nAllocationElementData(long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes) {
validate();
rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
}
native void rsnAllocationData2D(long con,
@ -571,6 +571,15 @@ public class RenderScript {
rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID);
}
native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
int mip, int compIdx, Object d, int sizeBytes, int dt);
synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
int mip, int compIdx, Object d, int sizeBytes,
Element.DataType dt) {
validate();
rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes, dt.mID);
}
native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
int w, int h, Object d, int sizeBytes, int dt);
synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
@ -579,6 +588,14 @@ public class RenderScript {
rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID);
}
native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
int w, int h, int depth, Object d, int sizeBytes, int dt);
synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt) {
validate();
rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID);
}
native long rsnAllocationGetType(long con, long id);
synchronized long nAllocationGetType(long id) {
validate();

View File

@ -1026,23 +1026,25 @@ nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint off
ptr, sizeBytes);
}
// Copies from the Java array data into the Allocation pointed to by alloc.
static void
// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod,
jint compIdx, jbyteArray data, jint sizeBytes)
nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
jint xoff, jint yoff, jint zoff,
jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
{
jint len = _env->GetArrayLength(data);
if (kLogApi) {
ALOGD("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), "
"sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len,
ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
"sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
sizeBytes);
}
jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
xoff, yoff, zoff,
lod, ptr, sizeBytes, compIdx);
_env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
}
// Copies from the Java object data into the Allocation pointed to by _alloc.
static void
nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
@ -1150,6 +1152,21 @@ nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint off
PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
}
// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
static void
nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc,
jint xoff, jint yoff, jint zoff,
jint lod, jint compIdx, jobject data, jint sizeBytes, int dataType)
{
RsAllocation *alloc = (RsAllocation *)_alloc;
if (kLogApi) {
ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), "
"sizeBytes(%i)", (RsContext)con, alloc, xoff, yoff, zoff, compIdx, sizeBytes);
}
PER_ARRAY_TYPE(0, rsAllocationElementRead, false, (RsContext)con, alloc,
xoff, yoff, zoff, lod, ptr, sizeBytes, compIdx);
}
// Copies from the Allocation pointed to by _alloc into the Java object data.
static void
nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
@ -1164,6 +1181,20 @@ nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xof
PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
ptr, sizeBytes, 0);
}
// Copies from the Allocation pointed to by _alloc into the Java object data.
static void
nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
{
RsAllocation *alloc = (RsAllocation *)_alloc;
if (kLogApi) {
ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
" h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
lod, w, h, d, sizeBytes);
}
PER_ARRAY_TYPE(0, rsAllocation3DRead, false, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d,
ptr, sizeBytes, 0);
}
static jlong
nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
@ -2184,14 +2215,16 @@ static JNINativeMethod methods[] = {
{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
{"rsnAllocationElementRead", "(JJIIIIILjava/lang/Object;II)V", (void*)nAllocationElementRead },
{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead3D },
{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },