diff options
Diffstat (limited to 'rs')
41 files changed, 561 insertions, 397 deletions
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java index 67d94f9..2191b54 100644 --- a/rs/java/android/renderscript/Allocation.java +++ b/rs/java/android/renderscript/Allocation.java @@ -16,16 +16,12 @@ package android.renderscript; -import java.io.IOException; -import java.io.InputStream; import java.util.HashMap; import android.content.res.Resources; -import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.Surface; import android.util.Log; -import android.util.TypedValue; import android.graphics.Canvas; import android.os.Trace; @@ -81,6 +77,65 @@ public class Allocation extends BaseObj { new HashMap<Long, Allocation>(); OnBufferAvailableListener mBufferNotifier; + private Element.DataType validateObjectIsPrimitiveArray(Object d, boolean checkType) { + final Class c = d.getClass(); + if (!c.isArray()) { + throw new RSIllegalArgumentException("Object passed is not an array of primitives."); + } + final Class cmp = c.getComponentType(); + if (!cmp.isPrimitive()) { + throw new RSIllegalArgumentException("Object passed is not an Array of primitives."); + } + + if (cmp == Long.TYPE) { + if (checkType) { + validateIsInt64(); + return mType.mElement.mType; + } + return Element.DataType.SIGNED_64; + } + + if (cmp == Integer.TYPE) { + if (checkType) { + validateIsInt32(); + return mType.mElement.mType; + } + return Element.DataType.SIGNED_32; + } + + if (cmp == Short.TYPE) { + if (checkType) { + validateIsInt16(); + return mType.mElement.mType; + } + return Element.DataType.SIGNED_16; + } + + if (cmp == Byte.TYPE) { + if (checkType) { + validateIsInt8(); + return mType.mElement.mType; + } + return Element.DataType.SIGNED_8; + } + + if (cmp == Float.TYPE) { + if (checkType) { + validateIsFloat32(); + } + return Element.DataType.FLOAT_32; + } + + if (cmp == Double.TYPE) { + if (checkType) { + validateIsFloat64(); + } + return Element.DataType.FLOAT_64; + } + return null; + } + + /** * The usage of the Allocation. These signal to RenderScript where to place * the Allocation in memory. @@ -292,6 +347,15 @@ public class Allocation extends BaseObj { super.finalize(); } + private void validateIsInt64() { + if ((mType.mElement.mType == Element.DataType.SIGNED_64) || + (mType.mElement.mType == Element.DataType.UNSIGNED_64)) { + return; + } + throw new RSIllegalArgumentException( + "64 bit integer source does not match allocation type " + mType.mElement.mType); + } + private void validateIsInt32() { if ((mType.mElement.mType == Element.DataType.SIGNED_32) || (mType.mElement.mType == Element.DataType.UNSIGNED_32)) { @@ -327,6 +391,14 @@ public class Allocation extends BaseObj { "32 bit float source does not match allocation type " + mType.mElement.mType); } + private void validateIsFloat64() { + if (mType.mElement.mType == Element.DataType.FLOAT_64) { + return; + } + throw new RSIllegalArgumentException( + "64 bit float source does not match allocation type " + mType.mElement.mType); + } + private void validateIsObject() { if ((mType.mElement.mType == Element.DataType.RS_ELEMENT) || (mType.mElement.mType == Element.DataType.RS_TYPE) || @@ -507,23 +579,30 @@ public class Allocation extends BaseObj { } } + private void copyFromUnchecked(Object array, Element.DataType dt, int arrayLen) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); + mRS.validate(); + if (mCurrentDimZ > 0) { + copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, array, dt, arrayLen); + } else if (mCurrentDimY > 0) { + copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, array, dt, arrayLen); + } else { + copy1DRangeFromUnchecked(0, mCurrentCount, array, dt, arrayLen); + } + Trace.traceEnd(RenderScript.TRACE_TAG); + } + /** * 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. * - * @param d the source data array + * @param array The source data array */ - public void copyFromUnchecked(int[] d) { + public void copyFromUnchecked(Object array) { Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFromUnchecked(0, mCurrentCount, d); - } + copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, false), + java.lang.reflect.Array.getLength(array)); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -534,17 +613,19 @@ public class Allocation extends BaseObj { * * @param d the source data array */ + public void copyFromUnchecked(int[] d) { + copyFromUnchecked(d, Element.DataType.SIGNED_32, d.length); + } + + /** + * 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. + * + * @param d the source data array + */ public void copyFromUnchecked(short[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFromUnchecked(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + copyFromUnchecked(d, Element.DataType.SIGNED_16, d.length); } /** @@ -555,16 +636,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFromUnchecked(byte[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFromUnchecked(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + copyFromUnchecked(d, Element.DataType.SIGNED_8, d.length); } /** @@ -575,37 +647,35 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFromUnchecked(float[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFromUnchecked(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + copyFromUnchecked(d, Element.DataType.FLOAT_32, d.length); } /** * Copy into this Allocation from an array. This variant is type checked * and will generate exceptions if the Allocation's {@link + * android.renderscript.Element} does not match the array's + * primitive type. + * + * @param array The source data array + */ + public void copyFrom(Object array) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); + copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, true), + java.lang.reflect.Array.getLength(array)); + Trace.traceEnd(RenderScript.TRACE_TAG); + } + + /** + * Copy into this Allocation from an array. This variant is type checked + * and will generate exceptions if the Allocation's {@link * android.renderscript.Element} is not a 32 bit integer type. * * @param d the source data array */ public void copyFrom(int[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFrom(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + validateIsInt32(); + copyFromUnchecked(d, Element.DataType.SIGNED_32, d.length); } /** @@ -616,16 +686,8 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFrom(short[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFrom(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + validateIsInt16(); + copyFromUnchecked(d, Element.DataType.SIGNED_16, d.length); } /** @@ -636,16 +698,8 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFrom(byte[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFrom(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + validateIsInt8(); + copyFromUnchecked(d, Element.DataType.SIGNED_8, d.length); } /** @@ -656,16 +710,8 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFrom(float[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); - mRS.validate(); - if (mCurrentDimZ > 0) { - copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); - } else if (mCurrentDimY > 0) { - copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); - } else { - copy1DRangeFrom(0, mCurrentCount, d); - } - Trace.traceEnd(RenderScript.TRACE_TAG); + validateIsFloat32(); + copyFromUnchecked(d, Element.DataType.FLOAT_32, d.length); } /** @@ -794,6 +840,29 @@ public class Allocation extends BaseObj { mRS.nAllocationGenerateMipmaps(getID(mRS)); } + private void copy1DRangeFromUnchecked(int off, int count, Object array, + Element.DataType dt, int arrayLen) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); + final int dataSize = mType.mElement.getBytesSize() * count; + data1DChecks(off, count, arrayLen * dt.mSize, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, array, dataSize, dt); + Trace.traceEnd(RenderScript.TRACE_TAG); + } + + /** + * Copy an array into part of this Allocation. 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 source data array + */ + public void copy1DRangeFromUnchecked(int off, int count, Object array) { + copy1DRangeFromUnchecked(off, count, array, + validateObjectIsPrimitiveArray(array, false), + java.lang.reflect.Array.getLength(array)); + } + /** * Copy an array into part of this Allocation. This method does not * guarantee that the Allocation is compatible with the input buffer. @@ -803,11 +872,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFromUnchecked(int off, int count, int[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); - int dataSize = mType.mElement.getBytesSize() * count; - data1DChecks(off, count, d.length * 4, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.SIGNED_32); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.SIGNED_32, d.length); } /** @@ -819,11 +884,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFromUnchecked(int off, int count, short[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); - int dataSize = mType.mElement.getBytesSize() * count; - data1DChecks(off, count, d.length * 2, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.SIGNED_16); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.SIGNED_16, d.length); } /** @@ -835,11 +896,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFromUnchecked(int off, int count, byte[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); - int dataSize = mType.mElement.getBytesSize() * count; - data1DChecks(off, count, d.length, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.SIGNED_8); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.SIGNED_8, d.length); } /** @@ -851,11 +908,23 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFromUnchecked(int off, int count, float[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); - int dataSize = mType.mElement.getBytesSize() * count; - data1DChecks(off, count, d.length * 4, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.FLOAT_32); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.FLOAT_32, d.length); + } + + + /** + * 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. + * + * @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 copy1DRangeFrom(int off, int count, Object array) { + copy1DRangeFromUnchecked(off, count, array, + validateObjectIsPrimitiveArray(array, true), + java.lang.reflect.Array.getLength(array)); } /** @@ -868,10 +937,8 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFrom(int off, int count, int[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFrom"); validateIsInt32(); - copy1DRangeFromUnchecked(off, count, d); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_32, d.length); } /** @@ -884,10 +951,8 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFrom(int off, int count, short[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFrom"); validateIsInt16(); - copy1DRangeFromUnchecked(off, count, d); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length); } /** @@ -900,10 +965,8 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFrom(int off, int count, byte[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFrom"); validateIsInt8(); - copy1DRangeFromUnchecked(off, count, d); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_8, d.length); } /** @@ -916,11 +979,10 @@ public class Allocation extends BaseObj { * @param d the source data array. */ public void copy1DRangeFrom(int off, int count, float[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFrom"); validateIsFloat32(); - copy1DRangeFromUnchecked(off, count, d); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy1DRangeFromUnchecked(off, count, d, Element.DataType.FLOAT_32, d.length); } + /** * Copy part of an Allocation into this Allocation. * @@ -955,39 +1017,31 @@ public class Allocation extends BaseObj { } } - void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, byte[] data) { + void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, Object array, + Element.DataType dt, int arrayLen) { Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked"); mRS.validate(); validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length, Element.DataType.SIGNED_8); + mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, + array, arrayLen * dt.mSize, dt); Trace.traceEnd(RenderScript.TRACE_TAG); } - void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, short[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked"); - mRS.validate(); - validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length * 2, Element.DataType.SIGNED_16); - Trace.traceEnd(RenderScript.TRACE_TAG); - } - - void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, int[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked"); - mRS.validate(); - validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length * 4, Element.DataType.SIGNED_32); - Trace.traceEnd(RenderScript.TRACE_TAG); - } - - void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, float[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked"); - mRS.validate(); - validate2DRange(xoff, yoff, w, h); - mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length * 4, Element.DataType.FLOAT_32); + /** + * Copy from an array into a rectangular region in this Allocation. The + * array is assumed to be tightly packed. + * + * @param xoff X offset of the region to update in this Allocation + * @param yoff Y offset of the region to update in this Allocation + * @param w Width of the region to update + * @param h Height of the region to update + * @param array Data to be placed into the Allocation + */ + public void copy2DRangeFrom(int xoff, int yoff, int w, int h, Object array) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); + copy2DRangeFromUnchecked(xoff, yoff, w, h, array, + validateObjectIsPrimitiveArray(array, true), + java.lang.reflect.Array.getLength(array)); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -1002,10 +1056,9 @@ public class Allocation extends BaseObj { * @param data to be placed into the Allocation */ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); validateIsInt8(); - copy2DRangeFromUnchecked(xoff, yoff, w, h, data); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy2DRangeFromUnchecked(xoff, yoff, w, h, data, + Element.DataType.SIGNED_8, data.length); } /** @@ -1019,10 +1072,9 @@ public class Allocation extends BaseObj { * @param data to be placed into the Allocation */ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); validateIsInt16(); - copy2DRangeFromUnchecked(xoff, yoff, w, h, data); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy2DRangeFromUnchecked(xoff, yoff, w, h, data, + Element.DataType.SIGNED_16, data.length); } /** @@ -1036,10 +1088,9 @@ public class Allocation extends BaseObj { * @param data to be placed into the Allocation */ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); validateIsInt32(); - copy2DRangeFromUnchecked(xoff, yoff, w, h, data); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy2DRangeFromUnchecked(xoff, yoff, w, h, data, + Element.DataType.SIGNED_32, data.length); } /** @@ -1053,10 +1104,9 @@ public class Allocation extends BaseObj { * @param data to be placed into the Allocation */ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); validateIsFloat32(); - copy2DRangeFromUnchecked(xoff, yoff, w, h, data); - Trace.traceEnd(RenderScript.TRACE_TAG); + copy2DRangeFromUnchecked(xoff, yoff, w, h, data, + Element.DataType.FLOAT_32, data.length); } /** @@ -1129,47 +1179,16 @@ public class Allocation extends BaseObj { * @hide * */ - void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, byte[] data) { - mRS.validate(); - validate3DRange(xoff, yoff, zoff, w, h, d); - mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length, Element.DataType.SIGNED_8); - } - - /** - * @hide - * - */ - void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, short[] data) { + private void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, + Object array, Element.DataType dt, int arrayLen) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFromUnchecked"); mRS.validate(); validate3DRange(xoff, yoff, zoff, w, h, d); - mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length * 2, Element.DataType.SIGNED_16); - } - - /** - * @hide - * - */ - void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, int[] data) { - mRS.validate(); - validate3DRange(xoff, yoff, zoff, w, h, d); - mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length * 4, Element.DataType.SIGNED_32); - } - - /** - * @hide - * - */ - void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, float[] data) { - mRS.validate(); - validate3DRange(xoff, yoff, zoff, w, h, d); - mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length * 4, Element.DataType.FLOAT_32); + mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d, + array, arrayLen * dt.mSize, dt); + Trace.traceEnd(RenderScript.TRACE_TAG); } - /** * @hide * Copy a rectangular region from the array into the allocation. @@ -1183,36 +1202,12 @@ public class Allocation extends BaseObj { * @param d Depth of the region to update * @param data to be placed into the allocation */ - public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, byte[] data) { - validateIsInt8(); - copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); - } - - /** - * @hide - * - */ - public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, short[] data) { - validateIsInt16(); - copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); - } - - /** - * @hide - * - */ - public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, int[] data) { - validateIsInt32(); - copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); - } - - /** - * @hide - * - */ - public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, float[] data) { - validateIsFloat32(); - copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); + public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, Object array) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFrom"); + copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, array, + validateObjectIsPrimitiveArray(array, true), + java.lang.reflect.Array.getLength(array)); + Trace.traceEnd(RenderScript.TRACE_TAG); } /** @@ -1256,6 +1251,26 @@ public class Allocation extends BaseObj { Trace.traceEnd(RenderScript.TRACE_TAG); } + private void copyTo(Object array, Element.DataType dt, int arrayLen) { + Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); + mRS.validate(); + mRS.nAllocationRead(getID(mRS), array, dt); + Trace.traceEnd(RenderScript.TRACE_TAG); + } + + /** + * Copy from the Allocation into an array. The array must be at + * least as large as the Allocation. The + * {@link android.renderscript.Element} must match the component + * type of the array passed in. + * + * @param array The array to be set from the Allocation. + */ + public void copyTo(Object array) { + copyTo(array, validateObjectIsPrimitiveArray(array, true), + java.lang.reflect.Array.getLength(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 @@ -1264,11 +1279,8 @@ public class Allocation extends BaseObj { * @param d The array to be set from the Allocation. */ public void copyTo(byte[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); validateIsInt8(); - mRS.validate(); - mRS.nAllocationRead(getID(mRS), d, Element.DataType.SIGNED_8); - Trace.traceEnd(RenderScript.TRACE_TAG); + copyTo(d, Element.DataType.SIGNED_8, d.length); } /** @@ -1279,11 +1291,8 @@ public class Allocation extends BaseObj { * @param d The array to be set from the Allocation. */ public void copyTo(short[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); validateIsInt16(); - mRS.validate(); - mRS.nAllocationRead(getID(mRS), d, Element.DataType.SIGNED_16); - Trace.traceEnd(RenderScript.TRACE_TAG); + copyTo(d, Element.DataType.SIGNED_16, d.length); } /** @@ -1294,11 +1303,8 @@ public class Allocation extends BaseObj { * @param d The array to be set from the Allocation. */ public void copyTo(int[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); validateIsInt32(); - mRS.validate(); - mRS.nAllocationRead(getID(mRS), d, Element.DataType.SIGNED_32); - Trace.traceEnd(RenderScript.TRACE_TAG); + copyTo(d, Element.DataType.SIGNED_32, d.length); } /** @@ -1309,11 +1315,8 @@ public class Allocation extends BaseObj { * @param d The array to be set from the Allocation. */ public void copyTo(float[] d) { - Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); validateIsFloat32(); - mRS.validate(); - mRS.nAllocationRead(getID(mRS), d, Element.DataType.FLOAT_32); - Trace.traceEnd(RenderScript.TRACE_TAG); + copyTo(d, Element.DataType.FLOAT_32, d.length); } /** @@ -1863,4 +1866,3 @@ public class Allocation extends BaseObj { } } - diff --git a/rs/java/android/renderscript/AllocationAdapter.java b/rs/java/android/renderscript/AllocationAdapter.java index b77d087..6c1b1ed 100644 --- a/rs/java/android/renderscript/AllocationAdapter.java +++ b/rs/java/android/renderscript/AllocationAdapter.java @@ -16,11 +16,6 @@ package android.renderscript; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.util.TypedValue; - /** * Only intended for use by generated reflected code. * diff --git a/rs/java/android/renderscript/Byte2.java b/rs/java/android/renderscript/Byte2.java index f796de3..3ad79e4 100644 --- a/rs/java/android/renderscript/Byte2.java +++ b/rs/java/android/renderscript/Byte2.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.lang.Math; -import android.util.Log; - /** * Class for exposing the native RenderScript byte2 type back to the Android system. diff --git a/rs/java/android/renderscript/Byte3.java b/rs/java/android/renderscript/Byte3.java index f2a95ac..a138313 100644 --- a/rs/java/android/renderscript/Byte3.java +++ b/rs/java/android/renderscript/Byte3.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.lang.Math; -import android.util.Log; - /** * Class for exposing the native RenderScript byte3 type back to the Android system. diff --git a/rs/java/android/renderscript/Byte4.java b/rs/java/android/renderscript/Byte4.java index b8a8a6b..fa4c13d 100644 --- a/rs/java/android/renderscript/Byte4.java +++ b/rs/java/android/renderscript/Byte4.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.lang.Math; -import android.util.Log; - /** * Class for exposing the native RenderScript byte4 type back to the Android system. diff --git a/rs/java/android/renderscript/Element.java b/rs/java/android/renderscript/Element.java index 2932770..93e839e 100644 --- a/rs/java/android/renderscript/Element.java +++ b/rs/java/android/renderscript/Element.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.lang.reflect.Field; -import android.util.Log; - /** * <p>An Element represents one item within an {@link * android.renderscript.Allocation}. An Element is roughly equivalent to a C diff --git a/rs/java/android/renderscript/FieldPacker.java b/rs/java/android/renderscript/FieldPacker.java index cf20e63..723ab24 100644 --- a/rs/java/android/renderscript/FieldPacker.java +++ b/rs/java/android/renderscript/FieldPacker.java @@ -16,7 +16,6 @@ package android.renderscript; -import android.util.Log; import java.util.BitSet; /** diff --git a/rs/java/android/renderscript/FileA3D.java b/rs/java/android/renderscript/FileA3D.java index 04bc7c6..4164810 100644 --- a/rs/java/android/renderscript/FileA3D.java +++ b/rs/java/android/renderscript/FileA3D.java @@ -17,15 +17,10 @@ package android.renderscript; import java.io.File; -import java.io.IOException; import java.io.InputStream; import android.content.res.AssetManager; import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.util.Log; -import android.util.TypedValue; /** * @hide diff --git a/rs/java/android/renderscript/Float2.java b/rs/java/android/renderscript/Float2.java index 26193d2..e9f8ca7 100644 --- a/rs/java/android/renderscript/Float2.java +++ b/rs/java/android/renderscript/Float2.java @@ -26,7 +26,7 @@ public class Float2 { public Float2() { } - /** @hide */ + /** @hide */ public Float2(Float2 data) { this.x = data.x; this.y = data.y; diff --git a/rs/java/android/renderscript/Font.java b/rs/java/android/renderscript/Font.java index cfd11c0..b22aeb7 100644 --- a/rs/java/android/renderscript/Font.java +++ b/rs/java/android/renderscript/Font.java @@ -17,7 +17,6 @@ package android.renderscript; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -26,8 +25,6 @@ import android.os.Environment; import android.content.res.AssetManager; import android.content.res.Resources; -import android.util.Log; -import android.util.TypedValue; /** * @hide diff --git a/rs/java/android/renderscript/Int3.java b/rs/java/android/renderscript/Int3.java index c770395..5431b9a 100644 --- a/rs/java/android/renderscript/Int3.java +++ b/rs/java/android/renderscript/Int3.java @@ -27,7 +27,7 @@ public class Int3 { public Int3() { } - + /** @hide */ public Int3(int i) { this.x = this.y = this.z = i; diff --git a/rs/java/android/renderscript/Long3.java b/rs/java/android/renderscript/Long3.java index 88ff855..8e243cc 100644 --- a/rs/java/android/renderscript/Long3.java +++ b/rs/java/android/renderscript/Long3.java @@ -27,7 +27,7 @@ public class Long3 { public Long3() { } - + /** @hide */ public Long3(long i) { this.x = this.y = this.z = i; diff --git a/rs/java/android/renderscript/Matrix2f.java b/rs/java/android/renderscript/Matrix2f.java index d3621fa..048262d 100644 --- a/rs/java/android/renderscript/Matrix2f.java +++ b/rs/java/android/renderscript/Matrix2f.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.lang.Math; -import android.util.Log; - /** * Class for exposing the native RenderScript rs_matrix2x2 type back to the Android system. diff --git a/rs/java/android/renderscript/Matrix3f.java b/rs/java/android/renderscript/Matrix3f.java index 8c3c330..9a4af77 100644 --- a/rs/java/android/renderscript/Matrix3f.java +++ b/rs/java/android/renderscript/Matrix3f.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.lang.Math; -import android.util.Log; - /** * Class for exposing the native RenderScript rs_matrix3x3 type back to the Android system. diff --git a/rs/java/android/renderscript/Matrix4f.java b/rs/java/android/renderscript/Matrix4f.java index cd18e30..5d5bf5f 100644 --- a/rs/java/android/renderscript/Matrix4f.java +++ b/rs/java/android/renderscript/Matrix4f.java @@ -17,7 +17,6 @@ package android.renderscript; import java.lang.Math; -import android.util.Log; /** diff --git a/rs/java/android/renderscript/Mesh.java b/rs/java/android/renderscript/Mesh.java index 9ce3fb2..a4ecc38 100644 --- a/rs/java/android/renderscript/Mesh.java +++ b/rs/java/android/renderscript/Mesh.java @@ -18,8 +18,6 @@ package android.renderscript; import java.util.Vector; -import android.util.Log; - /** * @hide * @deprecated in API 16 diff --git a/rs/java/android/renderscript/Path.java b/rs/java/android/renderscript/Path.java index 5cc67de..f3502aa 100644 --- a/rs/java/android/renderscript/Path.java +++ b/rs/java/android/renderscript/Path.java @@ -16,9 +16,6 @@ package android.renderscript; -import java.util.Vector; -import android.util.Log; - /** * @hide * diff --git a/rs/java/android/renderscript/ProgramFragment.java b/rs/java/android/renderscript/ProgramFragment.java index 5e886a3..2704130 100644 --- a/rs/java/android/renderscript/ProgramFragment.java +++ b/rs/java/android/renderscript/ProgramFragment.java @@ -17,9 +17,6 @@ package android.renderscript; -import android.util.Log; - - /** * @hide * @deprecated in API 16 diff --git a/rs/java/android/renderscript/ProgramFragmentFixedFunction.java b/rs/java/android/renderscript/ProgramFragmentFixedFunction.java index 22aed0a..e1c35c5 100644 --- a/rs/java/android/renderscript/ProgramFragmentFixedFunction.java +++ b/rs/java/android/renderscript/ProgramFragmentFixedFunction.java @@ -17,9 +17,6 @@ package android.renderscript; -import android.util.Log; - - /** * @hide * @deprecated in API 16 diff --git a/rs/java/android/renderscript/ProgramRaster.java b/rs/java/android/renderscript/ProgramRaster.java index e294b05..8c7c9aa 100644 --- a/rs/java/android/renderscript/ProgramRaster.java +++ b/rs/java/android/renderscript/ProgramRaster.java @@ -17,9 +17,6 @@ package android.renderscript; -import android.util.Log; - - /** * @hide * @deprecated in API 16 diff --git a/rs/java/android/renderscript/ProgramStore.java b/rs/java/android/renderscript/ProgramStore.java index 969cc25..c0fa9c4 100644 --- a/rs/java/android/renderscript/ProgramStore.java +++ b/rs/java/android/renderscript/ProgramStore.java @@ -17,9 +17,6 @@ package android.renderscript; -import android.util.Log; - - /** * @hide * <p>ProgramStore contains a set of parameters that control how diff --git a/rs/java/android/renderscript/ProgramVertex.java b/rs/java/android/renderscript/ProgramVertex.java index b6886e1..d194ba9 100644 --- a/rs/java/android/renderscript/ProgramVertex.java +++ b/rs/java/android/renderscript/ProgramVertex.java @@ -39,10 +39,6 @@ package android.renderscript; -import android.graphics.Matrix; -import android.util.Log; - - /** * @hide * @deprecated in API 16 diff --git a/rs/java/android/renderscript/ProgramVertexFixedFunction.java b/rs/java/android/renderscript/ProgramVertexFixedFunction.java index c479c77..2d281b8 100644 --- a/rs/java/android/renderscript/ProgramVertexFixedFunction.java +++ b/rs/java/android/renderscript/ProgramVertexFixedFunction.java @@ -17,10 +17,6 @@ package android.renderscript; -import android.graphics.Matrix; -import android.util.Log; - - /** * @hide * @deprecated in API 16 diff --git a/rs/java/android/renderscript/RSSurfaceView.java b/rs/java/android/renderscript/RSSurfaceView.java index 308d97a..5db72d9 100644 --- a/rs/java/android/renderscript/RSSurfaceView.java +++ b/rs/java/android/renderscript/RSSurfaceView.java @@ -16,16 +16,8 @@ package android.renderscript; -import java.io.Writer; -import java.util.ArrayList; -import java.util.concurrent.Semaphore; - import android.content.Context; -import android.os.Handler; -import android.os.Message; import android.util.AttributeSet; -import android.util.Log; -import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; diff --git a/rs/java/android/renderscript/RSTextureView.java b/rs/java/android/renderscript/RSTextureView.java index 7eeeeae..af3258a 100644 --- a/rs/java/android/renderscript/RSTextureView.java +++ b/rs/java/android/renderscript/RSTextureView.java @@ -16,16 +16,9 @@ package android.renderscript; -import java.io.Writer; -import java.util.ArrayList; -import java.util.concurrent.Semaphore; - import android.content.Context; import android.graphics.SurfaceTexture; -import android.os.Handler; -import android.os.Message; import android.util.AttributeSet; -import android.util.Log; import android.view.TextureView; /** diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java index 8618764..a4a9070 100644 --- a/rs/java/android/renderscript/RenderScript.java +++ b/rs/java/android/renderscript/RenderScript.java @@ -17,16 +17,12 @@ package android.renderscript; import java.io.File; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.concurrent.locks.ReentrantReadWriteLock; import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.SurfaceTexture; import android.os.Process; import android.util.Log; diff --git a/rs/java/android/renderscript/RenderScriptGL.java b/rs/java/android/renderscript/RenderScriptGL.java index c9cbe3e..714e835 100644 --- a/rs/java/android/renderscript/RenderScriptGL.java +++ b/rs/java/android/renderscript/RenderScriptGL.java @@ -16,17 +16,10 @@ package android.renderscript; -import java.lang.reflect.Field; - import android.content.Context; -import android.graphics.PixelFormat; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.SurfaceTexture; -import android.util.Log; import android.view.Surface; import android.view.SurfaceHolder; -import android.view.SurfaceView; /** * @hide diff --git a/rs/java/android/renderscript/Sampler.java b/rs/java/android/renderscript/Sampler.java index 8d0e29e..a4edbb5 100644 --- a/rs/java/android/renderscript/Sampler.java +++ b/rs/java/android/renderscript/Sampler.java @@ -16,17 +16,6 @@ package android.renderscript; - -import java.io.IOException; -import java.io.InputStream; - -import android.content.res.Resources; -import android.os.Bundle; -import android.util.Log; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - /** * Sampler object that defines how Allocations can be read as textures within a * kernel. Samplers are used in conjunction with the {@code rsSample} runtime diff --git a/rs/java/android/renderscript/ScriptC.java b/rs/java/android/renderscript/ScriptC.java index cdb2b08..9e76f52 100644 --- a/rs/java/android/renderscript/ScriptC.java +++ b/rs/java/android/renderscript/ScriptC.java @@ -16,18 +16,11 @@ package android.renderscript; -import android.content.Context; import android.content.res.Resources; -import android.util.Log; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Map.Entry; -import java.util.HashMap; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; /** * The superclass for all user-defined scripts. This is only diff --git a/rs/java/android/renderscript/ScriptGroup.java b/rs/java/android/renderscript/ScriptGroup.java index 48dba30..f1a7273 100644 --- a/rs/java/android/renderscript/ScriptGroup.java +++ b/rs/java/android/renderscript/ScriptGroup.java @@ -16,7 +16,6 @@ package android.renderscript; -import java.lang.reflect.Method; import java.util.ArrayList; /** diff --git a/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java b/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java index 96ec875..ce149d9 100644 --- a/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java +++ b/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java @@ -16,8 +16,6 @@ package android.renderscript; -import android.util.Log; - /** * * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The @@ -86,10 +84,23 @@ public final class ScriptIntrinsic3DLUT extends ScriptIntrinsic { * @param aout Output allocation */ public void forEach(Allocation ain, Allocation aout) { - forEach(0, ain, aout, null); + forEach(ain, aout, null); } /** + * Invoke the kernel and apply the lookup to each cell of ain + * and copy to aout. + * + * @param ain Input allocation + * @param aout Output allocation + * @param opt Launch options for kernel + */ + public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + forEach(0, ain, aout, null, opt); + } + + + /** * Get a KernelID for this intrinsic kernel. * * @return Script.KernelID The KernelID object. diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlend.java b/rs/java/android/renderscript/ScriptIntrinsicBlend.java index 40f1a3e..d4038c2 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicBlend.java +++ b/rs/java/android/renderscript/ScriptIntrinsicBlend.java @@ -40,14 +40,14 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { } - private void blend(int id, Allocation ain, Allocation aout) { + private void blend(int id, Allocation ain, Allocation aout, Script.LaunchOptions opt) { if (!ain.getElement().isCompatible(Element.U8_4(mRS))) { throw new RSIllegalArgumentException("Input is not of expected format."); } if (!aout.getElement().isCompatible(Element.U8_4(mRS))) { throw new RSIllegalArgumentException("Output is not of expected format."); } - forEach(id, ain, aout, null); + forEach(id, ain, aout, null, opt); } /** @@ -57,7 +57,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachClear(Allocation ain, Allocation aout) { - blend(0, ain, aout); + forEachClear(ain, aout, null); + } + + /** + * Sets dst = {0, 0, 0, 0} + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachClear(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(0, ain, aout, opt); } /** @@ -77,7 +88,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrc(Allocation ain, Allocation aout) { - blend(1, ain, aout); + forEachSrc(ain, aout, null); + } + + /** + * Sets dst = src + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrc(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + forEachDst(ain, aout, null); } /** @@ -102,6 +124,19 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { } /** + * Sets dst = dst + * + * This is a NOP. + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDst(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + // N, optOP + } + + /** * Get a KernelID for the Dst kernel. * * @return Script.KernelID The KernelID object. @@ -117,7 +152,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcOver(Allocation ain, Allocation aout) { - blend(3, ain, aout); + forEachSrcOver(ain, aout, null); + } + + /** + * Sets dst = src + dst * (1.0 - src.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(3, ain, aout, opt); } /** @@ -136,7 +182,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstOver(Allocation ain, Allocation aout) { - blend(4, ain, aout); + forEachDstOver(ain, aout, null); + } + + /** + * Sets dst = dst + src * (1.0 - dst.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstOver(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(4, ain, aout, opt); } /** @@ -155,7 +212,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcIn(Allocation ain, Allocation aout) { - blend(5, ain, aout); + forEachSrcIn(ain, aout, null); + } + + /** + * Sets dst = src * dst.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(5, ain, aout, opt); } /** @@ -174,7 +242,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstIn(Allocation ain, Allocation aout) { - blend(6, ain, aout); + forEachDstIn(ain, aout, null); + } + + /** + * Sets dst = dst * src.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstIn(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(6, ain, aout, opt); } /** @@ -193,7 +272,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcOut(Allocation ain, Allocation aout) { - blend(7, ain, aout); + forEachSrcOut(ain, aout, null); + } + + /** + * Sets dst = src * (1.0 - dst.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(7, ain, aout, opt); } /** @@ -212,7 +302,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstOut(Allocation ain, Allocation aout) { - blend(8, ain, aout); + forEachDstOut(ain, aout, null); + } + + /** + * Sets dst = dst * (1.0 - src.a) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstOut(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(8, ain, aout, opt); } /** @@ -232,7 +333,19 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSrcAtop(Allocation ain, Allocation aout) { - blend(9, ain, aout); + forEachSrcAtop(ain, aout, null); + } + + /** + * dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb + * dst.a = dst.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSrcAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(9, ain, aout, opt); } /** @@ -252,7 +365,19 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachDstAtop(Allocation ain, Allocation aout) { - blend(10, ain, aout); + forEachDstAtop(ain, aout, null); + } + + /** + * dst = dst.rgb * src.a + (1.0 - dst.a) * src.rgb + * dst.a = src.a + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachDstAtop(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(10, ain, aout, opt); } /** @@ -271,7 +396,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachXor(Allocation ain, Allocation aout) { - blend(11, ain, aout); + forEachXor(ain, aout, null); + } + + /** + * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a} + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachXor(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(11, ain, aout, opt); } /** @@ -300,7 +436,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachMultiply(Allocation ain, Allocation aout) { - blend(14, ain, aout); + forEachMultiply(ain, aout, null); + } + + /** + * Sets dst = src * dst + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachMultiply(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(14, ain, aout, opt); } /** @@ -396,7 +543,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachAdd(Allocation ain, Allocation aout) { - blend(34, ain, aout); + forEachAdd(ain, aout, null); + } + + /** + * Sets dst = min(src + dst, 1.0) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachAdd(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(34, ain, aout, opt); } /** @@ -415,7 +573,18 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { * @param aout The destination buffer */ public void forEachSubtract(Allocation ain, Allocation aout) { - blend(35, ain, aout); + forEachSubtract(ain, aout, null); + } + + /** + * Sets dst = max(dst - src, 0.0) + * + * @param ain The source buffer + * @param aout The destination buffer + * @param opt LaunchOptions for clipping + */ + public void forEachSubtract(Allocation ain, Allocation aout, Script.LaunchOptions opt) { + blend(35, ain, aout, opt); } /** diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlur.java b/rs/java/android/renderscript/ScriptIntrinsicBlur.java index d1a6fed..e7e33b8 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicBlur.java +++ b/rs/java/android/renderscript/ScriptIntrinsicBlur.java @@ -16,10 +16,6 @@ package android.renderscript; -import android.content.Context; -import android.content.res.Resources; -import android.util.Log; - /** * Intrinsic Gausian blur filter. Applies a gaussian blur of the * specified radius to all elements of an allocation. @@ -88,10 +84,23 @@ public final class ScriptIntrinsicBlur extends ScriptIntrinsic { * type. */ public void forEach(Allocation aout) { - forEach(0, null, aout, null); + forEach(aout, null); } /** + * Apply the filter to the input and save to the specified + * allocation. + * + * @param aout Output allocation. Must match creation element + * type. + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation aout, Script.LaunchOptions opt) { + forEach(0, null, aout, null, opt); + } + + + /** * Get a KernelID for this intrinsic kernel. * * @return Script.KernelID The KernelID object. diff --git a/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java b/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java index 601db17..57d917c 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java +++ b/rs/java/android/renderscript/ScriptIntrinsicColorMatrix.java @@ -16,8 +16,6 @@ package android.renderscript; -import android.util.Log; - /** * Intrinsic for applying a color matrix to allocations. * @@ -208,7 +206,6 @@ public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { setMatrix(); } - /** * Invoke the kernel and apply the matrix to each cell of input * {@link Allocation} and copy to the output {@link Allocation}. @@ -225,6 +222,26 @@ public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { * @param aout Output allocation */ public void forEach(Allocation ain, Allocation aout) { + forEach(ain, aout, null); + } + + /** + * Invoke the kernel and apply the matrix to each cell of input + * {@link Allocation} and copy to the output {@link Allocation}. + * + * If the vector size of the input is less than four, the + * remaining components are treated as zero for the matrix + * multiply. + * + * If the output vector size is less than four, the unused + * vector components are discarded. + * + * + * @param ain Input allocation + * @param aout Output allocation + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { if (!ain.getElement().isCompatible(Element.U8(mRS)) && !ain.getElement().isCompatible(Element.U8_2(mRS)) && !ain.getElement().isCompatible(Element.U8_3(mRS)) && @@ -249,7 +266,7 @@ public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { throw new RSIllegalArgumentException("Unsuported element type."); } - forEach(0, ain, aout, null); + forEach(0, ain, aout, null, opt); } /** diff --git a/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java b/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java index 25f3ee8..fb91fdc 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java +++ b/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java @@ -16,8 +16,6 @@ package android.renderscript; -import android.util.Log; - /** * Intrinsic for applying a 3x3 convolve to an allocation. * @@ -108,7 +106,19 @@ public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic { * type. */ public void forEach(Allocation aout) { - forEach(0, null, aout, null); + forEach(aout, null); + } + + /** + * Apply the filter to the input and save to the specified + * allocation. + * + * @param aout Output allocation. Must match creation element + * type. + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation aout, Script.LaunchOptions opt) { + forEach(0, null, aout, null, opt); } /** diff --git a/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java b/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java index 71ea4cb..0357560 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java +++ b/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java @@ -16,8 +16,6 @@ package android.renderscript; -import android.util.Log; - /** * Intrinsic for applying a 5x5 convolve to an allocation. * @@ -109,10 +107,23 @@ public final class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic { * type. */ public void forEach(Allocation aout) { - forEach(0, null, aout, null); + forEach(aout, null); } /** + * Apply the filter to the input and save to the specified + * allocation. + * + * @param aout Output allocation. Must match creation element + * type. + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation aout, Script.LaunchOptions opt) { + forEach(0, null, aout, null, opt); + } + + + /** * Get a KernelID for this intrinsic kernel. * * @return Script.KernelID The KernelID object. diff --git a/rs/java/android/renderscript/ScriptIntrinsicHistogram.java b/rs/java/android/renderscript/ScriptIntrinsicHistogram.java index 42e4d04..95b610a 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicHistogram.java +++ b/rs/java/android/renderscript/ScriptIntrinsicHistogram.java @@ -16,10 +16,6 @@ package android.renderscript; -import android.content.Context; -import android.content.res.Resources; -import android.util.Log; - /** * Intrinsic Histogram filter. * @@ -71,6 +67,24 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { * @param ain The input image */ public void forEach(Allocation ain) { + forEach(ain, null); + } + + /** + * Process an input buffer and place the histogram into the + * output allocation. The output allocation may be a narrower + * vector size than the input. In this case the vector size of + * the output is used to determine how many of the input + * channels are used in the computation. This is useful if you + * have an RGBA input buffer but only want the histogram for + * RGB. + * + * 1D and 2D input allocations are supported. + * + * @param ain The input image + * @param opt LaunchOptions for clipping + */ + public void forEach(Allocation ain, Script.LaunchOptions opt) { if (ain.getType().getElement().getVectorSize() < mOut.getType().getElement().getVectorSize()) { @@ -82,9 +96,11 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { throw new RSIllegalArgumentException("Output type must be U32 or I32."); } - forEach(0, ain, null, null); + forEach(0, ain, null, null, opt); } + + /** * Set the coefficients used for the RGBA to Luminocity * calculation. The default is {0.299f, 0.587f, 0.114f, 0.f}. @@ -141,6 +157,7 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { setVar(1, aout); } + /** * Process an input buffer and place the histogram into the * output allocation. The dot product of the input channel and @@ -152,6 +169,21 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { * @param ain The input image */ public void forEach_Dot(Allocation ain) { + forEach_Dot(ain, null); + } + + /** + * Process an input buffer and place the histogram into the + * output allocation. The dot product of the input channel and + * the coefficients from 'setDotCoefficients' are used to + * calculate the output values. + * + * 1D and 2D input allocations are supported. + * + * @param ain The input image + * @param opt LaunchOptions for clipping + */ + public void forEach_Dot(Allocation ain, Script.LaunchOptions opt) { if (mOut.getType().getElement().getVectorSize() != 1) { throw new RSIllegalArgumentException("Output vector size must be one."); } @@ -160,7 +192,7 @@ public final class ScriptIntrinsicHistogram extends ScriptIntrinsic { throw new RSIllegalArgumentException("Output type must be U32 or I32."); } - forEach(1, ain, null, null); + forEach(1, ain, null, null, opt); } diff --git a/rs/java/android/renderscript/ScriptIntrinsicLUT.java b/rs/java/android/renderscript/ScriptIntrinsicLUT.java index c45c015..69ff64a 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicLUT.java +++ b/rs/java/android/renderscript/ScriptIntrinsicLUT.java @@ -16,8 +16,6 @@ package android.renderscript; -import android.util.Log; - /** * Intrinsic for applying a per-channel lookup table. Each * channel of the input has an independant lookup table. The @@ -116,7 +114,6 @@ public final class ScriptIntrinsicLUT extends ScriptIntrinsic { mDirty = true; } - /** * Invoke the kernel and apply the lookup to each cell of ain * and copy to aout. @@ -125,11 +122,23 @@ public final class ScriptIntrinsicLUT extends ScriptIntrinsic { * @param aout Output allocation */ public void forEach(Allocation ain, Allocation aout) { + forEach(ain, aout, null); + } + + /** + * Invoke the kernel and apply the lookup to each cell of ain + * and copy to aout. + * + * @param ain Input allocation + * @param aout Output allocation + * @param opt Options for clipping + */ + public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) { if (mDirty) { mDirty = false; mTables.copyFromUnchecked(mCache); } - forEach(0, ain, aout, null); + forEach(0, ain, aout, null, opt); } /** diff --git a/rs/java/android/renderscript/Short2.java b/rs/java/android/renderscript/Short2.java index 070d608..24809f7 100644 --- a/rs/java/android/renderscript/Short2.java +++ b/rs/java/android/renderscript/Short2.java @@ -16,7 +16,10 @@ package android.renderscript; -/** + +/** + * Class for exposing the native RenderScript Short2 type back to the Android system. + * * Vector version of the basic short type. * Provides two short fields packed. */ diff --git a/rs/java/android/renderscript/Type.java b/rs/java/android/renderscript/Type.java index 7283814..83bf4a5 100644 --- a/rs/java/android/renderscript/Type.java +++ b/rs/java/android/renderscript/Type.java @@ -16,12 +16,6 @@ package android.renderscript; - -import java.lang.reflect.Field; - -import android.graphics.ImageFormat; -import android.util.Log; - /** * <p>A Type describes the {@link android.renderscript.Element} and dimensions used for an {@link * android.renderscript.Allocation} or a parallel operation. Types are created through {@link diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp index c4e19a1..80a5da2 100644 --- a/rs/jni/android_renderscript_RenderScript.cpp +++ b/rs/jni/android_renderscript_RenderScript.cpp @@ -392,7 +392,7 @@ nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray d jint len = 0; if (data) { len = _env->GetArrayLength(data); - jint *ptr = _env->GetIntArrayElements(data, NULL); + ptr = _env->GetIntArrayElements(data, NULL); } LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); |