diff options
author | Miao Wang <miaowang@google.com> | 2015-03-03 01:44:02 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-03 01:44:02 +0000 |
commit | e5ad00d1f58c734783497d2e40711fb1faaa848d (patch) | |
tree | 0629e6b6561727678c22c4469bad724aa37d60e5 /rs/java | |
parent | 573c2f8d540be9b61dbd780ee89dbc68031d7531 (diff) | |
parent | 5830e7a9fb56db24a101d7b45c6db970e38ed6f6 (diff) | |
download | frameworks_base-e5ad00d1f58c734783497d2e40711fb1faaa848d.zip frameworks_base-e5ad00d1f58c734783497d2e40711fb1faaa848d.tar.gz frameworks_base-e5ad00d1f58c734783497d2e40711fb1faaa848d.tar.bz2 |
am 5830e7a9: am 411473de: am caa8a8fb: Merge "[Renderscript] JAVA API update for Allocation.CopyTo add the following functions to make it more symmetric to copyFrom()."
* commit '5830e7a9fb56db24a101d7b45c6db970e38ed6f6':
[Renderscript] JAVA API update for Allocation.CopyTo add the following functions to make it more symmetric to copyFrom().
Diffstat (limited to 'rs/java')
-rw-r--r-- | rs/java/android/renderscript/Allocation.java | 385 | ||||
-rw-r--r-- | rs/java/android/renderscript/RenderScript.java | 23 |
2 files changed, 402 insertions, 6 deletions
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java index 4af6688..ede63a9 100644 --- a/rs/java/android/renderscript/Allocation.java +++ b/rs/java/android/renderscript/Allocation.java @@ -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) { @@ -1331,6 +1366,74 @@ public class Allocation extends BaseObj { } /** + * @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 * the new region is otherwise undefined. @@ -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 diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java index 33ecb96..1f3b63e 100644 --- a/rs/java/android/renderscript/RenderScript.java +++ b/rs/java/android/renderscript/RenderScript.java @@ -490,10 +490,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, @@ -570,6 +570,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, @@ -578,6 +587,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(); |