Loading rs/java/android/renderscript/RenderScript.java +44 −6 Original line number Diff line number Diff line Loading @@ -590,14 +590,52 @@ public class RenderScript { validate(); rsnScriptInvoke(mContext, id, slot); } native void rsnScriptForEach(long con, long id, int slot, long ain, long aout, byte[] params); native void rsnScriptForEach(long con, long id, int slot, long ain, long aout); native void rsnScriptForEachClipped(long con, long id, int slot, long ain, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend); native void rsnScriptForEachClipped(long con, long id, int slot, long ain, long aout, int xstart, int xend, int ystart, int yend, int zstart, int zend); synchronized void nScriptForEach(long id, int slot, long ain, long aout, byte[] params) { validate(); if (params == null) { rsnScriptForEach(mContext, id, slot, ain, aout); } else { rsnScriptForEach(mContext, id, slot, ain, aout, params); } } synchronized void nScriptForEachClipped(long id, int slot, long ain, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend) { validate(); if (params == null) { rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend); } else { rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend); } } native void rsnScriptForEach(long con, long id, int slot, long[] ains, long aout, byte[] params, int[] limits); /** * Multi-input code. * */ synchronized void nScriptForEach(long id, int slot, long[] ains, long aout, byte[] params, int[] limits) { // @hide native void rsnScriptForEachMultiClipped(long con, long id, int slot, long[] ains, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend); // @hide native void rsnScriptForEachMultiClipped(long con, long id, int slot, long[] ains, long aout, int xstart, int xend, int ystart, int yend, int zstart, int zend); // @hide synchronized void nScriptForEachMultiClipped(long id, int slot, long[] ains, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend) { validate(); rsnScriptForEach(mContext, id, slot, ains, aout, params, limits); if (params == null) { rsnScriptForEachMultiClipped(mContext, id, slot, ains, aout, xstart, xend, ystart, yend, zstart, zend); } else { rsnScriptForEachMultiClipped(mContext, id, slot, ains, aout, params, xstart, xend, ystart, yend, zstart, zend); } } native void rsnScriptInvokeV(long con, long id, int slot, byte[] params); Loading rs/java/android/renderscript/Script.java +46 −68 Original line number Diff line number Diff line Loading @@ -48,8 +48,7 @@ public class Script extends BaseObj { /** * Only to be used by generated reflected classes. */ protected KernelID createKernelID(int slot, int sig, Element ein, Element eout) { protected KernelID createKernelID(int slot, int sig, Element ein, Element eout) { KernelID k = mKIDs.get(slot); if (k != null) { return k; Loading Loading @@ -128,56 +127,59 @@ public class Script extends BaseObj { * Only intended for use by generated reflected code. * */ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) { forEach(slot, ain, aout, v, null); protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) { mRS.validate(); mRS.validateObject(ain); mRS.validateObject(aout); if (ain == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); } long in_id = 0; if (ain != null) { in_id = ain.getID(mRS); } long out_id = 0; if (aout != null) { out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } mRS.nScriptForEach(getID(mRS), slot, in_id, out_id, params); } /** * Only intended for use by generated reflected code. * */ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v, LaunchOptions sc) { // TODO: Is this necessary if nScriptForEach calls validate as well? protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v, LaunchOptions sc) { mRS.validate(); mRS.validateObject(ain); mRS.validateObject(aout); if (ain == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); } long[] in_ids = null; if (sc == null) { forEach(slot, ain, aout, v); return; } long in_id = 0; if (ain != null) { in_ids = mInIdsBuffer; in_ids[0] = ain.getID(mRS); in_id = ain.getID(mRS); } long out_id = 0; if (aout != null) { out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } int[] limits = null; if (sc != null) { limits = new int[6]; limits[0] = sc.xstart; limits[1] = sc.xend; limits[2] = sc.ystart; limits[3] = sc.yend; limits[4] = sc.zstart; limits[5] = sc.zend; } mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); mRS.nScriptForEachClipped(getID(mRS), slot, in_id, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend); } /** Loading @@ -185,9 +187,8 @@ public class Script extends BaseObj { * * @hide */ protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v) { forEach(slot, ains, aout, v, null); protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v) { forEach(slot, ains, aout, v, new LaunchOptions()); } /** Loading @@ -195,20 +196,24 @@ public class Script extends BaseObj { * * @hide */ protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v, LaunchOptions sc) { // TODO: Is this necessary if nScriptForEach calls validate as well? protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v, LaunchOptions sc) { mRS.validate(); for (Allocation ain : ains) { mRS.validateObject(ain); } mRS.validateObject(aout); mRS.validateObject(aout); if (ains == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); } if (sc == null) { forEach(slot, ains, aout, v); return; } long[] in_ids = new long[ains.length]; for (int index = 0; index < ains.length; ++index) { in_ids[index] = ains[index].getID(mRS); Loading @@ -218,33 +223,15 @@ public class Script extends BaseObj { if (aout != null) { out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } int[] limits = null; if (sc != null) { limits = new int[6]; limits[0] = sc.xstart; limits[1] = sc.xend; limits[2] = sc.ystart; limits[3] = sc.yend; limits[4] = sc.zstart; limits[5] = sc.zend; } mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); mRS.nScriptForEachMultiClipped(getID(mRS), slot, in_ids, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend); } long[] mInIdsBuffer; Script(long id, RenderScript rs) { super(id, rs); mInIdsBuffer = new long[1]; } Loading @@ -256,17 +243,11 @@ public class Script extends BaseObj { mRS.validate(); mRS.validateObject(va); if (va != null) { android.content.Context context = mRS.getApplicationContext(); if (context.getApplicationInfo().targetSdkVersion >= 20) { if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 20) { final Type t = va.mType; if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || (t.getZ() != 0)) { if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || (t.getZ() != 0)) { throw new RSIllegalArgumentException( "API 20+ only allows simple 1D allocations to be " + "used with bind."); "API 20+ only allows simple 1D allocations to be used with bind."); } } mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); Loading Loading @@ -397,14 +378,11 @@ public class Script extends BaseObj { protected Allocation mAllocation; protected void init(RenderScript rs, int dimx) { mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT); mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT); } protected void init(RenderScript rs, int dimx, int usages) { mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages); mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages); } protected FieldBase() { Loading rs/jni/android_renderscript_RenderScript.cpp +136 −56 Original line number Diff line number Diff line Loading @@ -1094,21 +1094,78 @@ nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, } static void nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlongArray ains, jlong aout, jbyteArray params, jintArray limits) nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout) { LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0); } static void nScriptForEachV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout, jbyteArray params) { LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); jint len = _env->GetArrayLength(params); jbyte *ptr = _env->GetByteArrayElements(params, NULL); rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0); _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); } jint in_len = 0; jlong *in_ptr = NULL; static void nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); } RsAllocation *in_allocs = NULL; static void nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout, jbyteArray params, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); jint len = _env->GetArrayLength(params); jbyte *ptr = _env->GetByteArrayElements(params, NULL); RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc)); _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); } if (ains != NULL) { in_len = _env->GetArrayLength(ains); in_ptr = _env->GetLongArrayElements(ains, NULL); static void nScriptForEachMultiClipped(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlongArray ains, jlong aout, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachMultiClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); jint in_len = _env->GetArrayLength(ains); jlong* in_ptr = _env->GetLongArrayElements(ains, NULL); RsAllocation *in_allocs = NULL; if (sizeof(RsAllocation) == sizeof(jlong)) { in_allocs = (RsAllocation*)in_ptr; Loading @@ -1116,60 +1173,80 @@ nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, } else { // Convert from 64-bit jlong types to the native pointer type. in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); in_allocs = new RsAllocation[in_len]; for (int index = in_len; --index >= 0;) { in_allocs[index] = (RsAllocation)in_ptr[index]; } } } jint param_len = 0; jbyte *param_ptr = NULL; RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); if (params != NULL) { param_len = _env->GetArrayLength(params); param_ptr = _env->GetByteArrayElements(params, NULL); if (sizeof(RsAllocation) != sizeof(jlong)) { delete[] in_allocs; } RsScriptCall sc, *sca = NULL; uint32_t sc_size = 0; _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); } jint limit_len = 0; jint *limit_ptr = NULL; static void nScriptForEachMultiClippedV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlongArray ains, jlong aout, jbyteArray params, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachMultiClippedV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); if (limits != NULL) { limit_len = _env->GetArrayLength(limits); limit_ptr = _env->GetIntArrayElements(limits, NULL); jint in_len = _env->GetArrayLength(ains); jlong* in_ptr = _env->GetLongArrayElements(ains, NULL); assert(limit_len == 6); RsAllocation *in_allocs = NULL; sc.xStart = limit_ptr[0]; sc.xEnd = limit_ptr[1]; sc.yStart = limit_ptr[2]; sc.yEnd = limit_ptr[3]; sc.zStart = limit_ptr[4]; sc.zEnd = limit_ptr[5]; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; if (sizeof(RsAllocation) == sizeof(jlong)) { in_allocs = (RsAllocation*)in_ptr; sca = ≻ } } else { // Convert from 64-bit jlong types to the native pointer type. rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, sca, sc_size); in_allocs = new RsAllocation[in_len]; if (ains != NULL) { _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); for (int index = in_len; --index >= 0;) { in_allocs[index] = (RsAllocation)in_ptr[index]; } if (params != NULL) { _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); } if (limits != NULL) { _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); jint param_len = _env->GetArrayLength(params); jbyte* param_ptr = _env->GetByteArrayElements(params, NULL); RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, &sc, sizeof(sc)); if (sizeof(RsAllocation) != sizeof(jlong)) { delete[] in_allocs; } _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); } // ----------------------------------- Loading Loading @@ -1683,9 +1760,12 @@ static JNINativeMethod methods[] = { {"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, {"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, {"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, {"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach }, {"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach }, {"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV }, {"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped }, {"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV }, {"rsnScriptForEachMultiClipped", "(JJI[JJIIIIII)V", (void*)nScriptForEachMultiClipped }, {"rsnScriptForEachMultiClipped", "(JJI[JJ[BIIIIII)V", (void*)nScriptForEachMultiClippedV }, {"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, {"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, {"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, Loading Loading
rs/java/android/renderscript/RenderScript.java +44 −6 Original line number Diff line number Diff line Loading @@ -590,14 +590,52 @@ public class RenderScript { validate(); rsnScriptInvoke(mContext, id, slot); } native void rsnScriptForEach(long con, long id, int slot, long ain, long aout, byte[] params); native void rsnScriptForEach(long con, long id, int slot, long ain, long aout); native void rsnScriptForEachClipped(long con, long id, int slot, long ain, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend); native void rsnScriptForEachClipped(long con, long id, int slot, long ain, long aout, int xstart, int xend, int ystart, int yend, int zstart, int zend); synchronized void nScriptForEach(long id, int slot, long ain, long aout, byte[] params) { validate(); if (params == null) { rsnScriptForEach(mContext, id, slot, ain, aout); } else { rsnScriptForEach(mContext, id, slot, ain, aout, params); } } synchronized void nScriptForEachClipped(long id, int slot, long ain, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend) { validate(); if (params == null) { rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend); } else { rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend); } } native void rsnScriptForEach(long con, long id, int slot, long[] ains, long aout, byte[] params, int[] limits); /** * Multi-input code. * */ synchronized void nScriptForEach(long id, int slot, long[] ains, long aout, byte[] params, int[] limits) { // @hide native void rsnScriptForEachMultiClipped(long con, long id, int slot, long[] ains, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend); // @hide native void rsnScriptForEachMultiClipped(long con, long id, int slot, long[] ains, long aout, int xstart, int xend, int ystart, int yend, int zstart, int zend); // @hide synchronized void nScriptForEachMultiClipped(long id, int slot, long[] ains, long aout, byte[] params, int xstart, int xend, int ystart, int yend, int zstart, int zend) { validate(); rsnScriptForEach(mContext, id, slot, ains, aout, params, limits); if (params == null) { rsnScriptForEachMultiClipped(mContext, id, slot, ains, aout, xstart, xend, ystart, yend, zstart, zend); } else { rsnScriptForEachMultiClipped(mContext, id, slot, ains, aout, params, xstart, xend, ystart, yend, zstart, zend); } } native void rsnScriptInvokeV(long con, long id, int slot, byte[] params); Loading
rs/java/android/renderscript/Script.java +46 −68 Original line number Diff line number Diff line Loading @@ -48,8 +48,7 @@ public class Script extends BaseObj { /** * Only to be used by generated reflected classes. */ protected KernelID createKernelID(int slot, int sig, Element ein, Element eout) { protected KernelID createKernelID(int slot, int sig, Element ein, Element eout) { KernelID k = mKIDs.get(slot); if (k != null) { return k; Loading Loading @@ -128,56 +127,59 @@ public class Script extends BaseObj { * Only intended for use by generated reflected code. * */ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) { forEach(slot, ain, aout, v, null); protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) { mRS.validate(); mRS.validateObject(ain); mRS.validateObject(aout); if (ain == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); } long in_id = 0; if (ain != null) { in_id = ain.getID(mRS); } long out_id = 0; if (aout != null) { out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } mRS.nScriptForEach(getID(mRS), slot, in_id, out_id, params); } /** * Only intended for use by generated reflected code. * */ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v, LaunchOptions sc) { // TODO: Is this necessary if nScriptForEach calls validate as well? protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v, LaunchOptions sc) { mRS.validate(); mRS.validateObject(ain); mRS.validateObject(aout); if (ain == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); } long[] in_ids = null; if (sc == null) { forEach(slot, ain, aout, v); return; } long in_id = 0; if (ain != null) { in_ids = mInIdsBuffer; in_ids[0] = ain.getID(mRS); in_id = ain.getID(mRS); } long out_id = 0; if (aout != null) { out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } int[] limits = null; if (sc != null) { limits = new int[6]; limits[0] = sc.xstart; limits[1] = sc.xend; limits[2] = sc.ystart; limits[3] = sc.yend; limits[4] = sc.zstart; limits[5] = sc.zend; } mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); mRS.nScriptForEachClipped(getID(mRS), slot, in_id, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend); } /** Loading @@ -185,9 +187,8 @@ public class Script extends BaseObj { * * @hide */ protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v) { forEach(slot, ains, aout, v, null); protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v) { forEach(slot, ains, aout, v, new LaunchOptions()); } /** Loading @@ -195,20 +196,24 @@ public class Script extends BaseObj { * * @hide */ protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v, LaunchOptions sc) { // TODO: Is this necessary if nScriptForEach calls validate as well? protected void forEach(int slot, Allocation[] ains, Allocation aout, FieldPacker v, LaunchOptions sc) { mRS.validate(); for (Allocation ain : ains) { mRS.validateObject(ain); } mRS.validateObject(aout); mRS.validateObject(aout); if (ains == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); } if (sc == null) { forEach(slot, ains, aout, v); return; } long[] in_ids = new long[ains.length]; for (int index = 0; index < ains.length; ++index) { in_ids[index] = ains[index].getID(mRS); Loading @@ -218,33 +223,15 @@ public class Script extends BaseObj { if (aout != null) { out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } int[] limits = null; if (sc != null) { limits = new int[6]; limits[0] = sc.xstart; limits[1] = sc.xend; limits[2] = sc.ystart; limits[3] = sc.yend; limits[4] = sc.zstart; limits[5] = sc.zend; } mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); mRS.nScriptForEachMultiClipped(getID(mRS), slot, in_ids, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend); } long[] mInIdsBuffer; Script(long id, RenderScript rs) { super(id, rs); mInIdsBuffer = new long[1]; } Loading @@ -256,17 +243,11 @@ public class Script extends BaseObj { mRS.validate(); mRS.validateObject(va); if (va != null) { android.content.Context context = mRS.getApplicationContext(); if (context.getApplicationInfo().targetSdkVersion >= 20) { if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 20) { final Type t = va.mType; if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || (t.getZ() != 0)) { if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || (t.getZ() != 0)) { throw new RSIllegalArgumentException( "API 20+ only allows simple 1D allocations to be " + "used with bind."); "API 20+ only allows simple 1D allocations to be used with bind."); } } mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); Loading Loading @@ -397,14 +378,11 @@ public class Script extends BaseObj { protected Allocation mAllocation; protected void init(RenderScript rs, int dimx) { mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT); mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT); } protected void init(RenderScript rs, int dimx, int usages) { mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages); mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages); } protected FieldBase() { Loading
rs/jni/android_renderscript_RenderScript.cpp +136 −56 Original line number Diff line number Diff line Loading @@ -1094,21 +1094,78 @@ nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, } static void nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlongArray ains, jlong aout, jbyteArray params, jintArray limits) nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout) { LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0); } static void nScriptForEachV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout, jbyteArray params) { LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); jint len = _env->GetArrayLength(params); jbyte *ptr = _env->GetByteArrayElements(params, NULL); rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0); _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); } jint in_len = 0; jlong *in_ptr = NULL; static void nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); } RsAllocation *in_allocs = NULL; static void nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong ain, jlong aout, jbyteArray params, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); jint len = _env->GetArrayLength(params); jbyte *ptr = _env->GetByteArrayElements(params, NULL); RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc)); _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); } if (ains != NULL) { in_len = _env->GetArrayLength(ains); in_ptr = _env->GetLongArrayElements(ains, NULL); static void nScriptForEachMultiClipped(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlongArray ains, jlong aout, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachMultiClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); jint in_len = _env->GetArrayLength(ains); jlong* in_ptr = _env->GetLongArrayElements(ains, NULL); RsAllocation *in_allocs = NULL; if (sizeof(RsAllocation) == sizeof(jlong)) { in_allocs = (RsAllocation*)in_ptr; Loading @@ -1116,60 +1173,80 @@ nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, } else { // Convert from 64-bit jlong types to the native pointer type. in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); in_allocs = new RsAllocation[in_len]; for (int index = in_len; --index >= 0;) { in_allocs[index] = (RsAllocation)in_ptr[index]; } } } jint param_len = 0; jbyte *param_ptr = NULL; RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); if (params != NULL) { param_len = _env->GetArrayLength(params); param_ptr = _env->GetByteArrayElements(params, NULL); if (sizeof(RsAllocation) != sizeof(jlong)) { delete[] in_allocs; } RsScriptCall sc, *sca = NULL; uint32_t sc_size = 0; _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); } jint limit_len = 0; jint *limit_ptr = NULL; static void nScriptForEachMultiClippedV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlongArray ains, jlong aout, jbyteArray params, jint xstart, jint xend, jint ystart, jint yend, jint zstart, jint zend) { LOG_API("nScriptForEachMultiClippedV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); if (limits != NULL) { limit_len = _env->GetArrayLength(limits); limit_ptr = _env->GetIntArrayElements(limits, NULL); jint in_len = _env->GetArrayLength(ains); jlong* in_ptr = _env->GetLongArrayElements(ains, NULL); assert(limit_len == 6); RsAllocation *in_allocs = NULL; sc.xStart = limit_ptr[0]; sc.xEnd = limit_ptr[1]; sc.yStart = limit_ptr[2]; sc.yEnd = limit_ptr[3]; sc.zStart = limit_ptr[4]; sc.zEnd = limit_ptr[5]; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; if (sizeof(RsAllocation) == sizeof(jlong)) { in_allocs = (RsAllocation*)in_ptr; sca = ≻ } } else { // Convert from 64-bit jlong types to the native pointer type. rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, sca, sc_size); in_allocs = new RsAllocation[in_len]; if (ains != NULL) { _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); for (int index = in_len; --index >= 0;) { in_allocs[index] = (RsAllocation)in_ptr[index]; } if (params != NULL) { _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); } if (limits != NULL) { _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); jint param_len = _env->GetArrayLength(params); jbyte* param_ptr = _env->GetByteArrayElements(params, NULL); RsScriptCall sc; sc.xStart = xstart; sc.xEnd = xend; sc.yStart = ystart; sc.yEnd = yend; sc.zStart = zstart; sc.zEnd = zend; sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; sc.arrayStart = 0; sc.arrayEnd = 0; rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, &sc, sizeof(sc)); if (sizeof(RsAllocation) != sizeof(jlong)) { delete[] in_allocs; } _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); } // ----------------------------------- Loading Loading @@ -1683,9 +1760,12 @@ static JNINativeMethod methods[] = { {"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, {"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, {"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, {"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach }, {"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach }, {"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV }, {"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped }, {"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV }, {"rsnScriptForEachMultiClipped", "(JJI[JJIIIIII)V", (void*)nScriptForEachMultiClipped }, {"rsnScriptForEachMultiClipped", "(JJI[JJ[BIIIIII)V", (void*)nScriptForEachMultiClippedV }, {"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, {"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, {"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, Loading