am 34a63ba4: Merge "Ensure RenderScript tracing is always balanced via try/finally"
* commit '34a63ba4d79567146f2724c47b06ffa4f21639da': Ensure RenderScript tracing is always balanced via try/finally
This commit is contained in:
@@ -51,6 +51,7 @@ import android.os.Trace;
|
|||||||
* <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
|
* <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
|
||||||
* </div>
|
* </div>
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public class Allocation extends BaseObj {
|
public class Allocation extends BaseObj {
|
||||||
Type mType;
|
Type mType;
|
||||||
Bitmap mBitmap;
|
Bitmap mBitmap;
|
||||||
@@ -455,28 +456,31 @@ public class Allocation extends BaseObj {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void syncAll(int srcLocation) {
|
public void syncAll(int srcLocation) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "syncAll");
|
try {
|
||||||
switch (srcLocation) {
|
Trace.traceBegin(RenderScript.TRACE_TAG, "syncAll");
|
||||||
case USAGE_GRAPHICS_TEXTURE:
|
switch (srcLocation) {
|
||||||
case USAGE_SCRIPT:
|
case USAGE_GRAPHICS_TEXTURE:
|
||||||
if ((mUsage & USAGE_SHARED) != 0) {
|
case USAGE_SCRIPT:
|
||||||
copyFrom(mBitmap);
|
if ((mUsage & USAGE_SHARED) != 0) {
|
||||||
|
copyFrom(mBitmap);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case USAGE_GRAPHICS_CONSTANTS:
|
||||||
|
case USAGE_GRAPHICS_VERTEX:
|
||||||
|
break;
|
||||||
|
case USAGE_SHARED:
|
||||||
|
if ((mUsage & USAGE_SHARED) != 0) {
|
||||||
|
copyTo(mBitmap);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RSIllegalArgumentException("Source must be exactly one usage type.");
|
||||||
}
|
}
|
||||||
break;
|
mRS.validate();
|
||||||
case USAGE_GRAPHICS_CONSTANTS:
|
mRS.nAllocationSyncAll(getIDSafe(), srcLocation);
|
||||||
case USAGE_GRAPHICS_VERTEX:
|
} finally {
|
||||||
break;
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
case USAGE_SHARED:
|
|
||||||
if ((mUsage & USAGE_SHARED) != 0) {
|
|
||||||
copyTo(mBitmap);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new RSIllegalArgumentException("Source must be exactly one usage type.");
|
|
||||||
}
|
}
|
||||||
mRS.validate();
|
|
||||||
mRS.nAllocationSyncAll(getIDSafe(), srcLocation);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -487,14 +491,17 @@ public class Allocation extends BaseObj {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void ioSend() {
|
public void ioSend() {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "ioSend");
|
try {
|
||||||
if ((mUsage & USAGE_IO_OUTPUT) == 0) {
|
Trace.traceBegin(RenderScript.TRACE_TAG, "ioSend");
|
||||||
throw new RSIllegalArgumentException(
|
if ((mUsage & USAGE_IO_OUTPUT) == 0) {
|
||||||
"Can only send buffer if IO_OUTPUT usage specified.");
|
throw new RSIllegalArgumentException(
|
||||||
|
"Can only send buffer if IO_OUTPUT usage specified.");
|
||||||
|
}
|
||||||
|
mRS.validate();
|
||||||
|
mRS.nAllocationIoSend(getID(mRS));
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.validate();
|
|
||||||
mRS.nAllocationIoSend(getID(mRS));
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -503,14 +510,17 @@ public class Allocation extends BaseObj {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void ioReceive() {
|
public void ioReceive() {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "ioReceive");
|
try {
|
||||||
if ((mUsage & USAGE_IO_INPUT) == 0) {
|
Trace.traceBegin(RenderScript.TRACE_TAG, "ioReceive");
|
||||||
throw new RSIllegalArgumentException(
|
if ((mUsage & USAGE_IO_INPUT) == 0) {
|
||||||
"Can only receive if IO_INPUT usage specified.");
|
throw new RSIllegalArgumentException(
|
||||||
|
"Can only receive if IO_INPUT usage specified.");
|
||||||
|
}
|
||||||
|
mRS.validate();
|
||||||
|
mRS.nAllocationIoReceive(getID(mRS));
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.validate();
|
|
||||||
mRS.nAllocationIoReceive(getID(mRS));
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -519,28 +529,31 @@ public class Allocation extends BaseObj {
|
|||||||
* @param d Source array.
|
* @param d Source array.
|
||||||
*/
|
*/
|
||||||
public void copyFrom(BaseObj[] d) {
|
public void copyFrom(BaseObj[] d) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
||||||
validateIsObject();
|
mRS.validate();
|
||||||
if (d.length != mCurrentCount) {
|
validateIsObject();
|
||||||
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
|
if (d.length != mCurrentCount) {
|
||||||
mCurrentCount + ", array length = " + d.length);
|
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
|
||||||
}
|
mCurrentCount + ", array length = " + d.length);
|
||||||
|
}
|
||||||
|
|
||||||
if (RenderScript.sPointerSize == 8) {
|
if (RenderScript.sPointerSize == 8) {
|
||||||
long i[] = new long[d.length * 4];
|
long i[] = new long[d.length * 4];
|
||||||
for (int ct=0; ct < d.length; ct++) {
|
for (int ct=0; ct < d.length; ct++) {
|
||||||
i[ct * 4] = d[ct].getID(mRS);
|
i[ct * 4] = d[ct].getID(mRS);
|
||||||
|
}
|
||||||
|
copy1DRangeFromUnchecked(0, mCurrentCount, i);
|
||||||
|
} else {
|
||||||
|
int i[] = new int[d.length];
|
||||||
|
for (int ct=0; ct < d.length; ct++) {
|
||||||
|
i[ct] = (int) d[ct].getID(mRS);
|
||||||
|
}
|
||||||
|
copy1DRangeFromUnchecked(0, mCurrentCount, i);
|
||||||
}
|
}
|
||||||
copy1DRangeFromUnchecked(0, mCurrentCount, i);
|
} finally {
|
||||||
} else {
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
int i[] = new int[d.length];
|
|
||||||
for (int ct=0; ct < d.length; ct++) {
|
|
||||||
i[ct] = (int)d[ct].getID(mRS);
|
|
||||||
}
|
|
||||||
copy1DRangeFromUnchecked(0, mCurrentCount, i);
|
|
||||||
}
|
}
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateBitmapFormat(Bitmap b) {
|
private void validateBitmapFormat(Bitmap b) {
|
||||||
@@ -599,16 +612,19 @@ public class Allocation extends BaseObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void copyFromUnchecked(Object array, Element.DataType dt, int arrayLen) {
|
private void copyFromUnchecked(Object array, Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked");
|
||||||
if (mCurrentDimZ > 0) {
|
mRS.validate();
|
||||||
copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, array, dt, arrayLen);
|
if (mCurrentDimZ > 0) {
|
||||||
} else if (mCurrentDimY > 0) {
|
copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, array, dt, arrayLen);
|
||||||
copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, array, dt, arrayLen);
|
} else if (mCurrentDimY > 0) {
|
||||||
} else {
|
copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, array, dt, arrayLen);
|
||||||
copy1DRangeFromUnchecked(0, mCurrentCount, array, dt, arrayLen);
|
} else {
|
||||||
|
copy1DRangeFromUnchecked(0, mCurrentCount, array, dt, arrayLen);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -619,10 +635,13 @@ public class Allocation extends BaseObj {
|
|||||||
* @param array The source data array
|
* @param array The source data array
|
||||||
*/
|
*/
|
||||||
public void copyFromUnchecked(Object array) {
|
public void copyFromUnchecked(Object array) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked");
|
try {
|
||||||
copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, false),
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked");
|
||||||
java.lang.reflect.Array.getLength(array));
|
copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, false),
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
java.lang.reflect.Array.getLength(array));
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -679,10 +698,13 @@ public class Allocation extends BaseObj {
|
|||||||
* @param array The source data array
|
* @param array The source data array
|
||||||
*/
|
*/
|
||||||
public void copyFrom(Object array) {
|
public void copyFrom(Object array) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
try {
|
||||||
copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, true),
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
||||||
java.lang.reflect.Array.getLength(array));
|
copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, true),
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
java.lang.reflect.Array.getLength(array));
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -747,19 +769,22 @@ public class Allocation extends BaseObj {
|
|||||||
* @param b the source bitmap
|
* @param b the source bitmap
|
||||||
*/
|
*/
|
||||||
public void copyFrom(Bitmap b) {
|
public void copyFrom(Bitmap b) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
||||||
if (b.getConfig() == null) {
|
mRS.validate();
|
||||||
Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
|
if (b.getConfig() == null) {
|
||||||
Canvas c = new Canvas(newBitmap);
|
Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
c.drawBitmap(b, 0, 0, null);
|
Canvas c = new Canvas(newBitmap);
|
||||||
copyFrom(newBitmap);
|
c.drawBitmap(b, 0, 0, null);
|
||||||
return;
|
copyFrom(newBitmap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
validateBitmapSize(b);
|
||||||
|
validateBitmapFormat(b);
|
||||||
|
mRS.nAllocationCopyFromBitmap(getID(mRS), b);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
validateBitmapSize(b);
|
|
||||||
validateBitmapFormat(b);
|
|
||||||
mRS.nAllocationCopyFromBitmap(getID(mRS), b);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -769,13 +794,16 @@ public class Allocation extends BaseObj {
|
|||||||
* @param a the source allocation
|
* @param a the source allocation
|
||||||
*/
|
*/
|
||||||
public void copyFrom(Allocation a) {
|
public void copyFrom(Allocation a) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom");
|
||||||
if (!mType.equals(a.getType())) {
|
mRS.validate();
|
||||||
throw new RSIllegalArgumentException("Types of allocations must match.");
|
if (!mType.equals(a.getType())) {
|
||||||
|
throw new RSIllegalArgumentException("Types of allocations must match.");
|
||||||
|
}
|
||||||
|
copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, a, 0, 0);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, a, 0, 0);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -891,17 +919,20 @@ public class Allocation extends BaseObj {
|
|||||||
|
|
||||||
private void copy1DRangeFromUnchecked(int off, int count, Object array,
|
private void copy1DRangeFromUnchecked(int off, int count, Object array,
|
||||||
Element.DataType dt, int arrayLen) {
|
Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked");
|
try {
|
||||||
final int dataSize = mType.mElement.getBytesSize() * count;
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked");
|
||||||
// AutoPadding for Vec3 Element
|
final int dataSize = mType.mElement.getBytesSize() * count;
|
||||||
boolean usePadding = false;
|
// AutoPadding for Vec3 Element
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
boolean usePadding = false;
|
||||||
usePadding = true;
|
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);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1075,28 +1106,31 @@ public class Allocation extends BaseObj {
|
|||||||
|
|
||||||
void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, Object array,
|
void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, Object array,
|
||||||
Element.DataType dt, int arrayLen) {
|
Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked");
|
||||||
validate2DRange(xoff, yoff, w, h);
|
mRS.validate();
|
||||||
final int dataSize = mType.mElement.getBytesSize() * w * h;
|
validate2DRange(xoff, yoff, w, h);
|
||||||
// AutoPadding for Vec3 Element
|
final int dataSize = mType.mElement.getBytesSize() * w * h;
|
||||||
boolean usePadding = false;
|
// AutoPadding for Vec3 Element
|
||||||
int sizeBytes = arrayLen * dt.mSize;
|
boolean usePadding = false;
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
int sizeBytes = arrayLen * dt.mSize;
|
||||||
if (dataSize / 4 * 3 > sizeBytes) {
|
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize / 4 * 3 > sizeBytes) {
|
||||||
}
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
usePadding = true;
|
}
|
||||||
sizeBytes = dataSize;
|
usePadding = true;
|
||||||
} else {
|
sizeBytes = dataSize;
|
||||||
if (dataSize > sizeBytes) {
|
} else {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize > sizeBytes) {
|
||||||
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
|
||||||
|
array, sizeBytes, dt,
|
||||||
|
mType.mElement.mType.mSize, usePadding);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
|
|
||||||
array, sizeBytes, dt,
|
|
||||||
mType.mElement.mType.mSize, usePadding);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1110,11 +1144,14 @@ public class Allocation extends BaseObj {
|
|||||||
* @param array Data to be placed into the Allocation
|
* @param array Data to be placed into the Allocation
|
||||||
*/
|
*/
|
||||||
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, Object array) {
|
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, Object array) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom");
|
try {
|
||||||
copy2DRangeFromUnchecked(xoff, yoff, w, h, array,
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom");
|
||||||
validateObjectIsPrimitiveArray(array, true),
|
copy2DRangeFromUnchecked(xoff, yoff, w, h, array,
|
||||||
java.lang.reflect.Array.getLength(array));
|
validateObjectIsPrimitiveArray(array, true),
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
java.lang.reflect.Array.getLength(array));
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1195,14 +1232,17 @@ public class Allocation extends BaseObj {
|
|||||||
*/
|
*/
|
||||||
public void copy2DRangeFrom(int xoff, int yoff, int w, int h,
|
public void copy2DRangeFrom(int xoff, int yoff, int w, int h,
|
||||||
Allocation data, int dataXoff, int dataYoff) {
|
Allocation data, int dataXoff, int dataYoff) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom");
|
||||||
validate2DRange(xoff, yoff, w, h);
|
mRS.validate();
|
||||||
mRS.nAllocationData2D(getIDSafe(), xoff, yoff,
|
validate2DRange(xoff, yoff, w, h);
|
||||||
mSelectedLOD, mSelectedFace.mID,
|
mRS.nAllocationData2D(getIDSafe(), xoff, yoff,
|
||||||
w, h, data.getID(mRS), dataXoff, dataYoff,
|
mSelectedLOD, mSelectedFace.mID,
|
||||||
data.mSelectedLOD, data.mSelectedFace.mID);
|
w, h, data.getID(mRS), dataXoff, dataYoff,
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
data.mSelectedLOD, data.mSelectedFace.mID);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1256,28 +1296,31 @@ public class Allocation extends BaseObj {
|
|||||||
*/
|
*/
|
||||||
private void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d,
|
private void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d,
|
||||||
Object array, Element.DataType dt, int arrayLen) {
|
Object array, Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFromUnchecked");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFromUnchecked");
|
||||||
validate3DRange(xoff, yoff, zoff, w, h, d);
|
mRS.validate();
|
||||||
final int dataSize = mType.mElement.getBytesSize() * w * h * d;
|
validate3DRange(xoff, yoff, zoff, w, h, d);
|
||||||
// AutoPadding for Vec3 Element
|
final int dataSize = mType.mElement.getBytesSize() * w * h * d;
|
||||||
boolean usePadding = false;
|
// AutoPadding for Vec3 Element
|
||||||
int sizeBytes = arrayLen * dt.mSize;
|
boolean usePadding = false;
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
int sizeBytes = arrayLen * dt.mSize;
|
||||||
if (dataSize / 4 * 3 > sizeBytes) {
|
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize / 4 * 3 > sizeBytes) {
|
||||||
}
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
usePadding = true;
|
}
|
||||||
sizeBytes = dataSize;
|
usePadding = true;
|
||||||
} else {
|
sizeBytes = dataSize;
|
||||||
if (dataSize > sizeBytes) {
|
} else {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize > sizeBytes) {
|
||||||
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
|
||||||
|
array, sizeBytes, dt,
|
||||||
|
mType.mElement.mType.mSize, usePadding);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
|
|
||||||
array, sizeBytes, dt,
|
|
||||||
mType.mElement.mType.mSize, usePadding);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1294,11 +1337,14 @@ public class Allocation extends BaseObj {
|
|||||||
* @param array 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) {
|
public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, Object array) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFrom");
|
try {
|
||||||
copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, array,
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFrom");
|
||||||
validateObjectIsPrimitiveArray(array, true),
|
copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, array,
|
||||||
java.lang.reflect.Array.getLength(array));
|
validateObjectIsPrimitiveArray(array, true),
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
java.lang.reflect.Array.getLength(array));
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1334,34 +1380,40 @@ public class Allocation extends BaseObj {
|
|||||||
* @param b The bitmap to be set from the Allocation.
|
* @param b The bitmap to be set from the Allocation.
|
||||||
*/
|
*/
|
||||||
public void copyTo(Bitmap b) {
|
public void copyTo(Bitmap b) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo");
|
||||||
validateBitmapFormat(b);
|
mRS.validate();
|
||||||
validateBitmapSize(b);
|
validateBitmapFormat(b);
|
||||||
mRS.nAllocationCopyToBitmap(getID(mRS), b);
|
validateBitmapSize(b);
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
mRS.nAllocationCopyToBitmap(getID(mRS), b);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyTo(Object array, Element.DataType dt, int arrayLen) {
|
private void copyTo(Object array, Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo");
|
||||||
boolean usePadding = false;
|
mRS.validate();
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
boolean usePadding = false;
|
||||||
usePadding = true;
|
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
||||||
}
|
usePadding = true;
|
||||||
if (usePadding) {
|
|
||||||
if (dt.mSize * arrayLen < mSize / 4 * 3) {
|
|
||||||
throw new RSIllegalArgumentException(
|
|
||||||
"Size of output array cannot be smaller than size of allocation.");
|
|
||||||
}
|
}
|
||||||
} else {
|
if (usePadding) {
|
||||||
if (dt.mSize * arrayLen < mSize) {
|
if (dt.mSize * arrayLen < mSize / 4 * 3) {
|
||||||
throw new RSIllegalArgumentException(
|
throw new RSIllegalArgumentException(
|
||||||
"Size of output array cannot be smaller than size of allocation.");
|
"Size of output array cannot be smaller than size of allocation.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dt.mSize * arrayLen < mSize) {
|
||||||
|
throw new RSIllegalArgumentException(
|
||||||
|
"Size of output array cannot be smaller than size of allocation.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mRS.nAllocationRead(getID(mRS), array, dt, mType.mElement.mType.mSize, usePadding);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.nAllocationRead(getID(mRS), array, dt, mType.mElement.mType.mSize, usePadding);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1498,17 +1550,20 @@ public class Allocation extends BaseObj {
|
|||||||
|
|
||||||
private void copy1DRangeToUnchecked(int off, int count, Object array,
|
private void copy1DRangeToUnchecked(int off, int count, Object array,
|
||||||
Element.DataType dt, int arrayLen) {
|
Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeToUnchecked");
|
try {
|
||||||
final int dataSize = mType.mElement.getBytesSize() * count;
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeToUnchecked");
|
||||||
// AutoPadding for Vec3 Element
|
final int dataSize = mType.mElement.getBytesSize() * count;
|
||||||
boolean usePadding = false;
|
// AutoPadding for Vec3 Element
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
boolean usePadding = false;
|
||||||
usePadding = true;
|
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);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1658,27 +1713,30 @@ public class Allocation extends BaseObj {
|
|||||||
|
|
||||||
void copy2DRangeToUnchecked(int xoff, int yoff, int w, int h, Object array,
|
void copy2DRangeToUnchecked(int xoff, int yoff, int w, int h, Object array,
|
||||||
Element.DataType dt, int arrayLen) {
|
Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeToUnchecked");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeToUnchecked");
|
||||||
validate2DRange(xoff, yoff, w, h);
|
mRS.validate();
|
||||||
final int dataSize = mType.mElement.getBytesSize() * w * h;
|
validate2DRange(xoff, yoff, w, h);
|
||||||
// AutoPadding for Vec3 Element
|
final int dataSize = mType.mElement.getBytesSize() * w * h;
|
||||||
boolean usePadding = false;
|
// AutoPadding for Vec3 Element
|
||||||
int sizeBytes = arrayLen * dt.mSize;
|
boolean usePadding = false;
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
int sizeBytes = arrayLen * dt.mSize;
|
||||||
if (dataSize / 4 * 3 > sizeBytes) {
|
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize / 4 * 3 > sizeBytes) {
|
||||||
}
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
usePadding = true;
|
}
|
||||||
sizeBytes = dataSize;
|
usePadding = true;
|
||||||
} else {
|
sizeBytes = dataSize;
|
||||||
if (dataSize > sizeBytes) {
|
} else {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize > sizeBytes) {
|
||||||
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mRS.nAllocationRead2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
|
||||||
|
array, sizeBytes, dt, mType.mElement.mType.mSize, usePadding);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.nAllocationRead2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h,
|
|
||||||
array, sizeBytes, dt, mType.mElement.mType.mSize, usePadding);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1768,27 +1826,30 @@ public class Allocation extends BaseObj {
|
|||||||
*/
|
*/
|
||||||
private void copy3DRangeToUnchecked(int xoff, int yoff, int zoff, int w, int h, int d,
|
private void copy3DRangeToUnchecked(int xoff, int yoff, int zoff, int w, int h, int d,
|
||||||
Object array, Element.DataType dt, int arrayLen) {
|
Object array, Element.DataType dt, int arrayLen) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeToUnchecked");
|
try {
|
||||||
mRS.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeToUnchecked");
|
||||||
validate3DRange(xoff, yoff, zoff, w, h, d);
|
mRS.validate();
|
||||||
final int dataSize = mType.mElement.getBytesSize() * w * h * d;
|
validate3DRange(xoff, yoff, zoff, w, h, d);
|
||||||
// AutoPadding for Vec3 Element
|
final int dataSize = mType.mElement.getBytesSize() * w * h * d;
|
||||||
boolean usePadding = false;
|
// AutoPadding for Vec3 Element
|
||||||
int sizeBytes = arrayLen * dt.mSize;
|
boolean usePadding = false;
|
||||||
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
int sizeBytes = arrayLen * dt.mSize;
|
||||||
if (dataSize / 4 * 3 > sizeBytes) {
|
if (mAutoPadding && (mType.getElement().getVectorSize() == 3)) {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize / 4 * 3 > sizeBytes) {
|
||||||
}
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
usePadding = true;
|
}
|
||||||
sizeBytes = dataSize;
|
usePadding = true;
|
||||||
} else {
|
sizeBytes = dataSize;
|
||||||
if (dataSize > sizeBytes) {
|
} else {
|
||||||
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
if (dataSize > sizeBytes) {
|
||||||
|
throw new RSIllegalArgumentException("Array too small for allocation type.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mRS.nAllocationRead3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
|
||||||
|
array, sizeBytes, dt, mType.mElement.mType.mSize, usePadding);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
mRS.nAllocationRead3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d,
|
|
||||||
array, sizeBytes, dt, mType.mElement.mType.mSize, usePadding);
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1827,17 +1888,20 @@ public class Allocation extends BaseObj {
|
|||||||
* utilized
|
* utilized
|
||||||
*/
|
*/
|
||||||
static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, int usage) {
|
static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, int usage) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "createTyped");
|
try {
|
||||||
rs.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "createTyped");
|
||||||
if (type.getID(rs) == 0) {
|
rs.validate();
|
||||||
throw new RSInvalidStateException("Bad Type");
|
if (type.getID(rs) == 0) {
|
||||||
|
throw new RSInvalidStateException("Bad Type");
|
||||||
|
}
|
||||||
|
long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0);
|
||||||
|
if (id == 0) {
|
||||||
|
throw new RSRuntimeException("Allocation creation failed.");
|
||||||
|
}
|
||||||
|
return new Allocation(id, rs, type, usage);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0);
|
|
||||||
if (id == 0) {
|
|
||||||
throw new RSRuntimeException("Allocation creation failed.");
|
|
||||||
}
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
return new Allocation(id, rs, type, usage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1881,18 +1945,21 @@ public class Allocation extends BaseObj {
|
|||||||
*/
|
*/
|
||||||
static public Allocation createSized(RenderScript rs, Element e,
|
static public Allocation createSized(RenderScript rs, Element e,
|
||||||
int count, int usage) {
|
int count, int usage) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "createSized");
|
try {
|
||||||
rs.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "createSized");
|
||||||
Type.Builder b = new Type.Builder(rs, e);
|
rs.validate();
|
||||||
b.setX(count);
|
Type.Builder b = new Type.Builder(rs, e);
|
||||||
Type t = b.create();
|
b.setX(count);
|
||||||
|
Type t = b.create();
|
||||||
|
|
||||||
long id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0);
|
long id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0);
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
throw new RSRuntimeException("Allocation creation failed.");
|
throw new RSRuntimeException("Allocation creation failed.");
|
||||||
|
}
|
||||||
|
return new Allocation(id, rs, t, usage);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
}
|
}
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
return new Allocation(id, rs, t, usage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1951,44 +2018,47 @@ public class Allocation extends BaseObj {
|
|||||||
static public Allocation createFromBitmap(RenderScript rs, Bitmap b,
|
static public Allocation createFromBitmap(RenderScript rs, Bitmap b,
|
||||||
MipmapControl mips,
|
MipmapControl mips,
|
||||||
int usage) {
|
int usage) {
|
||||||
Trace.traceBegin(RenderScript.TRACE_TAG, "createFromBitmap");
|
try {
|
||||||
rs.validate();
|
Trace.traceBegin(RenderScript.TRACE_TAG, "createFromBitmap");
|
||||||
|
rs.validate();
|
||||||
|
|
||||||
// WAR undocumented color formats
|
// WAR undocumented color formats
|
||||||
if (b.getConfig() == null) {
|
if (b.getConfig() == null) {
|
||||||
if ((usage & USAGE_SHARED) != 0) {
|
if ((usage & USAGE_SHARED) != 0) {
|
||||||
throw new RSIllegalArgumentException("USAGE_SHARED cannot be used with a Bitmap that has a null config.");
|
throw new RSIllegalArgumentException("USAGE_SHARED cannot be used with a Bitmap that has a null config.");
|
||||||
|
}
|
||||||
|
Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas c = new Canvas(newBitmap);
|
||||||
|
c.drawBitmap(b, 0, 0, null);
|
||||||
|
return createFromBitmap(rs, newBitmap, mips, usage);
|
||||||
}
|
}
|
||||||
Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas c = new Canvas(newBitmap);
|
|
||||||
c.drawBitmap(b, 0, 0, null);
|
|
||||||
return createFromBitmap(rs, newBitmap, mips, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
Type t = typeFromBitmap(rs, b, mips);
|
Type t = typeFromBitmap(rs, b, mips);
|
||||||
|
|
||||||
// enable optimized bitmap path only with no mipmap and script-only usage
|
// enable optimized bitmap path only with no mipmap and script-only usage
|
||||||
if (mips == MipmapControl.MIPMAP_NONE &&
|
if (mips == MipmapControl.MIPMAP_NONE &&
|
||||||
t.getElement().isCompatible(Element.RGBA_8888(rs)) &&
|
t.getElement().isCompatible(Element.RGBA_8888(rs)) &&
|
||||||
usage == (USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE)) {
|
usage == (USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE)) {
|
||||||
long id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage);
|
long id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage);
|
||||||
|
if (id == 0) {
|
||||||
|
throw new RSRuntimeException("Load failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep a reference to the Bitmap around to prevent GC
|
||||||
|
Allocation alloc = new Allocation(id, rs, t, usage);
|
||||||
|
alloc.setBitmap(b);
|
||||||
|
return alloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage);
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
throw new RSRuntimeException("Load failed.");
|
throw new RSRuntimeException("Load failed.");
|
||||||
}
|
}
|
||||||
|
return new Allocation(id, rs, t, usage);
|
||||||
// keep a reference to the Bitmap around to prevent GC
|
} finally {
|
||||||
Allocation alloc = new Allocation(id, rs, t, usage);
|
Trace.traceEnd(RenderScript.TRACE_TAG);
|
||||||
alloc.setBitmap(b);
|
|
||||||
return alloc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage);
|
|
||||||
if (id == 0) {
|
|
||||||
throw new RSRuntimeException("Load failed.");
|
|
||||||
}
|
|
||||||
Trace.traceEnd(RenderScript.TRACE_TAG);
|
|
||||||
return new Allocation(id, rs, t, usage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user