Revert "Collapse code paths for single- and multi-input kernels."

This reverts commit eb3470219dea322efa93eb4b5457813ce71d0c5d.

Change-Id: Id943abf953e832ef831318e6699d4b46e9b46201
diff --git a/rs/java/android/renderscript/Script.java b/rs/java/android/renderscript/Script.java
index eb1687a..c49ef94 100644
--- a/rs/java/android/renderscript/Script.java
+++ b/rs/java/android/renderscript/Script.java
@@ -48,8 +48,7 @@
     /**
      * 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;
@@ -128,56 +127,59 @@
      * 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 (ain != null) {
-            in_ids    = mInIdsBuffer;
-            in_ids[0] = ain.getID(mRS);
+        if (sc == null) {
+            forEach(slot, ain, aout, v);
+            return;
         }
-
+        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();
         }
-
-        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);
     }
 
     /**
@@ -185,9 +187,8 @@
      *
      * @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());
     }
 
     /**
@@ -195,20 +196,24 @@
      *
      * @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);
@@ -218,33 +223,15 @@
         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];
     }
 
 
@@ -256,17 +243,11 @@
         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);
@@ -397,14 +378,11 @@
         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() {