summaryrefslogtreecommitdiffstats
path: root/rs/java/android/renderscript/Allocation.java
diff options
context:
space:
mode:
authorMiao Wang <miaowang@google.com>2015-03-05 23:49:57 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-03-05 23:49:57 +0000
commit288e6f67181ce74ec4b97b61def1b9510b1221d0 (patch)
tree8dfa9fbf8922202f4c95445c6f05eba4d42a18b0 /rs/java/android/renderscript/Allocation.java
parent701f9c2fd8d4e31c5ed3a51e4767d4aeb9b20c40 (diff)
parent87e908dfdece91b5f504386d4901fa3342dc8083 (diff)
downloadframeworks_base-288e6f67181ce74ec4b97b61def1b9510b1221d0.zip
frameworks_base-288e6f67181ce74ec4b97b61def1b9510b1221d0.tar.gz
frameworks_base-288e6f67181ce74ec4b97b61def1b9510b1221d0.tar.bz2
Merge "[RenderScript] AutoPadding & Unpadding for Vec3 Elements during copyTo & copyFrom."
Diffstat (limited to 'rs/java/android/renderscript/Allocation.java')
-rw-r--r--rs/java/android/renderscript/Allocation.java130
1 files changed, 113 insertions, 17 deletions
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java
index a211b70..daf00e8 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;
@@ -270,6 +271,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.
@@ -851,7 +863,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 +875,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 +904,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 +1088,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 +1266,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 +1298,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");
@@ -1296,7 +1352,11 @@ public class Allocation extends BaseObj {
private void copyTo(Object array, Element.DataType dt, int arrayLen) {
Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo");
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);
}
@@ -1465,8 +1525,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);
}
@@ -1620,8 +1686,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);
}
@@ -1649,7 +1730,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();
@@ -1665,7 +1746,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();
@@ -1681,7 +1762,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();
@@ -1697,7 +1778,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();
@@ -1715,8 +1796,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);
}