Adds support for multi-input kernels to Frameworks/Base/RS.

* Added a new JNI call to pass arrays of Allocations to the RS runtime.
* Added a new version of ForEach that takes an array of Allocations.
* Added some casts to disambiguate existing calls to forEach.

Change-Id: I46d2834c37075b2a2407fd8b010546818a4540d1
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index 5fe631b..7133a21 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -1154,6 +1154,101 @@
     _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
 }
 
+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;
+
+    } else {
+      // Convert from 64-bit jlong types to the native pointer type.
+
+      in_allocs = new RsAllocation[in_len];
+
+      for (int index = in_len; --index >= 0;) {
+        in_allocs[index] = (RsAllocation)in_ptr[index];
+      }
+    }
+
+    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 (sizeof(RsAllocation) != sizeof(jlong)) {
+      delete[] in_allocs;
+    }
+
+    _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
+}
+
+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);
+
+    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;
+
+    } else {
+      // Convert from 64-bit jlong types to the native pointer type.
+
+      in_allocs = new RsAllocation[in_len];
+
+      for (int index = in_len; --index >= 0;) {
+        in_allocs[index] = (RsAllocation)in_ptr[index];
+      }
+    }
+
+    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);
+}
+
 // -----------------------------------
 
 static jlong
@@ -1669,6 +1764,8 @@
 {"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 },