summaryrefslogtreecommitdiff
path: root/rs/java/android/renderscript/Allocation.java
diff options
context:
space:
mode:
Diffstat (limited to 'rs/java/android/renderscript/Allocation.java')
-rw-r--r--rs/java/android/renderscript/Allocation.java201
1 files changed, 131 insertions, 70 deletions
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java
index ede63a92b385..523c8fb7b189 100644
--- a/rs/java/android/renderscript/Allocation.java
+++ b/rs/java/android/renderscript/Allocation.java
@@ -60,6 +60,7 @@ public class Allocation extends BaseObj {
boolean mReadAllowed = true;
boolean mWriteAllowed = true;
+ boolean mAutoPadding = false;
int mSelectedX;
int mSelectedY;
int mSelectedZ;
@@ -75,6 +76,8 @@ public class Allocation extends BaseObj {
new HashMap<Long, Allocation>();
OnBufferAvailableListener mBufferNotifier;
+ private Surface mGetSurfaceSurface = null;
+
private Element.DataType validateObjectIsPrimitiveArray(Object d, boolean checkType) {
final Class c = d.getClass();
if (!c.isArray()) {
@@ -270,6 +273,17 @@ public class Allocation extends BaseObj {
}
/**
+ * @hide
+ * Enable/Disable AutoPadding for Vec3 elements.
+ *
+ * @param useAutoPadding True: enable AutoPadding; flase: disable AutoPadding
+ *
+ */
+ public void setAutoPadding(boolean useAutoPadding) {
+ mAutoPadding = useAutoPadding;
+ }
+
+ /**
* Get the size of the Allocation in bytes.
*
* @return size of the Allocation in bytes.
@@ -785,6 +799,7 @@ public class Allocation extends BaseObj {
copy1DRangeFromUnchecked(xoff, count, data);
}
+
/**
* This is only intended to be used by auto-generated code reflected from
* the RenderScript script files.
@@ -804,20 +819,6 @@ public class Allocation extends BaseObj {
*
* @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
@@ -851,7 +852,7 @@ public class Allocation extends BaseObj {
component_number, data, data_length);
}
- private void data1DChecks(int off, int count, int len, int dataSize) {
+ private void data1DChecks(int off, int count, int len, int dataSize, boolean usePadding) {
mRS.validate();
if(off < 0) {
throw new RSIllegalArgumentException("Offset must be >= 0.");
@@ -863,8 +864,14 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Overflow, Available count " + mCurrentCount +
", got " + count + " at offset " + off + ".");
}
- if(len < dataSize) {
- throw new RSIllegalArgumentException("Array too small for allocation type.");
+ if(usePadding) {
+ if(len < dataSize / 4 * 3) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ } else {
+ if(len < dataSize) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
}
}
@@ -886,8 +893,14 @@ public class Allocation extends BaseObj {
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);
+ // AutoPadding for Vec3 Element
+ boolean usePadding = false;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ usePadding = true;
+ }
+ data1DChecks(off, count, arrayLen * dt.mSize, dataSize, usePadding);
+ mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, array, dataSize, dt,
+ mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1064,8 +1077,24 @@ public class Allocation extends BaseObj {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked");
mRS.validate();
validate2DRange(xoff, yoff, w, h);
+ final int dataSize = mType.mElement.getBytesSize() * w * h;
+ // AutoPadding for Vec3 Element
+ boolean usePadding = false;
+ int sizeBytes = arrayLen * dt.mSize;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ if (dataSize / 4 * 3 > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ usePadding = true;
+ sizeBytes = dataSize;
+ } else {
+ if (dataSize > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ }
mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
- array, arrayLen * dt.mSize, dt);
+ array, sizeBytes, dt,
+ mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1226,8 +1255,24 @@ public class Allocation extends BaseObj {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFromUnchecked");
mRS.validate();
validate3DRange(xoff, yoff, zoff, w, h, d);
+ final int dataSize = mType.mElement.getBytesSize() * w * h * d;
+ // AutoPadding for Vec3 Element
+ boolean usePadding = false;
+ int sizeBytes = arrayLen * dt.mSize;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ if (dataSize / 4 * 3 > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ usePadding = true;
+ sizeBytes = dataSize;
+ } else {
+ if (dataSize > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ }
mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
- array, arrayLen * dt.mSize, dt);
+ array, sizeBytes, dt,
+ mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1242,7 +1287,7 @@ public class Allocation extends BaseObj {
* @param w Width of the region to update
* @param h Height of the region to update
* @param d Depth of the region to update
- * @param data to be placed into the allocation
+ * @param array to be placed into the allocation
*/
public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, Object array) {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFrom");
@@ -1300,7 +1345,11 @@ public class Allocation extends BaseObj {
"Size of output array cannot be smaller than size of allocation.");
}
mRS.validate();
- mRS.nAllocationRead(getID(mRS), array, dt);
+ boolean usePadding = false;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ usePadding = true;
+ }
+ mRS.nAllocationRead(getID(mRS), array, dt, mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1367,35 +1416,8 @@ 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
+ * This is only intended to be used by auto-generated code reflected from
+ * the RenderScript script files and should not be used by developers.
*
* @param xoff
* @param yoff
@@ -1403,8 +1425,7 @@ public class Allocation extends BaseObj {
* @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");
+ public void copyToFieldPacker(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.");
@@ -1419,19 +1440,18 @@ public class Allocation extends BaseObj {
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;
+ final byte[] data = fp.getData();
+ int data_length = fp.getPos();
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 + ".");
+ if (data_length != eSize) {
+ throw new RSIllegalArgumentException("Field packer sizelength " + data_length +
+ " does not match component size " + eSize + ".");
}
mRS.nAllocationElementRead(getIDSafe(), xoff, yoff, zoff, mSelectedLOD,
- component_number, array, eSize, dt);
- Trace.traceEnd(RenderScript.TRACE_TAG);
+ component_number, data, data_length);
}
/**
* Resize a 1D allocation. The contents of the allocation are preserved.
@@ -1469,8 +1489,14 @@ public class Allocation extends BaseObj {
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);
+ // AutoPadding for Vec3 Element
+ boolean usePadding = false;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ usePadding = true;
+ }
+ data1DChecks(off, count, arrayLen * dt.mSize, dataSize, usePadding);
+ mRS.nAllocationRead1D(getIDSafe(), off, mSelectedLOD, count, array, dataSize, dt,
+ mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1624,8 +1650,23 @@ public class Allocation extends BaseObj {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeToUnchecked");
mRS.validate();
validate2DRange(xoff, yoff, w, h);
+ final int dataSize = mType.mElement.getBytesSize() * w * h;
+ // AutoPadding for Vec3 Element
+ boolean usePadding = false;
+ int sizeBytes = arrayLen * dt.mSize;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ if (dataSize / 4 * 3 > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ usePadding = true;
+ sizeBytes = dataSize;
+ } else {
+ if (dataSize > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ }
mRS.nAllocationRead2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
- array, arrayLen * dt.mSize, dt);
+ array, sizeBytes, dt, mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1653,7 +1694,7 @@ public class Allocation extends BaseObj {
* @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
+ * @param data Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, byte[] data) {
validateIsInt8();
@@ -1669,7 +1710,7 @@ public class Allocation extends BaseObj {
* @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
+ * @param data Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, short[] data) {
validateIsInt16();
@@ -1685,7 +1726,7 @@ public class Allocation extends BaseObj {
* @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
+ * @param data Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, int[] data) {
validateIsInt32();
@@ -1701,7 +1742,7 @@ public class Allocation extends BaseObj {
* @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
+ * @param data Dest Array to be copied into
*/
public void copy2DRangeTo(int xoff, int yoff, int w, int h, float[] data) {
validateIsFloat32();
@@ -1719,8 +1760,23 @@ public class Allocation extends BaseObj {
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeToUnchecked");
mRS.validate();
validate3DRange(xoff, yoff, zoff, w, h, d);
+ final int dataSize = mType.mElement.getBytesSize() * w * h * d;
+ // AutoPadding for Vec3 Element
+ boolean usePadding = false;
+ int sizeBytes = arrayLen * dt.mSize;
+ if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
+ if (dataSize / 4 * 3 > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ usePadding = true;
+ sizeBytes = dataSize;
+ } else {
+ if (dataSize > sizeBytes) {
+ throw new RSIllegalArgumentException("Array too small for allocation type.");
+ }
+ }
mRS.nAllocationRead3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
- array, arrayLen * dt.mSize, dt);
+ array, sizeBytes, dt, mType.mElement.mType.mSize, usePadding);
Trace.traceEnd(RenderScript.TRACE_TAG);
}
@@ -1936,7 +1992,12 @@ public class Allocation extends BaseObj {
if ((mUsage & USAGE_IO_INPUT) == 0) {
throw new RSInvalidStateException("Allocation is not a surface texture.");
}
- return mRS.nAllocationGetSurface(getID(mRS));
+
+ if (mGetSurfaceSurface == null) {
+ mGetSurfaceSurface = mRS.nAllocationGetSurface(getID(mRS));
+ }
+
+ return mGetSurfaceSurface;
}
/**