Merge "[Renderscript] Incremental Support for Intrinsics."
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/Allocation.java b/v8/renderscript/java/src/android/support/v8/renderscript/Allocation.java
index 427e199..8cf4e9d 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/Allocation.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/Allocation.java
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import android.content.res.Resources;
 import android.content.res.AssetManager;
 import android.graphics.Bitmap;
@@ -138,7 +139,12 @@
         return null;
     }
 
-
+    /*
+     * Hold reference to the shared allocation in compat context
+     * for Incremental Support Lib.
+     */
+    long mIncCompatAllocation;
+    boolean mIncAllocDestroyed;
     /**
      * The usage of the Allocation.  These signal to RenderScript where to place
      * the Allocation in memory.
@@ -218,6 +224,16 @@
         }
     }
 
+    /**
+     * Getter & Setter for the dummy allocation for Inc Support Lib.
+     *
+     */
+    public long getIncAllocID() {
+        return mIncCompatAllocation;
+    }
+    public void setIncAllocID(long id) {
+        mIncCompatAllocation = id;
+    }
 
     private long getIDSafe() {
         if (mAdaptedAllocation != null) {
@@ -311,6 +327,8 @@
 
         mType = t;
         mUsage = usage;
+        mIncCompatAllocation = 0;
+        mIncAllocDestroyed = false;
 
         if (t != null) {
             // TODO: A3D doesn't have Type info during creation, so we can't
@@ -2211,15 +2229,38 @@
     }
 
     /**
+     * Frees any native resources associated with this object.  The
+     * primary use is to force immediate cleanup of resources when it is
+     * believed the GC will not respond quickly enough.
      * For USAGE_IO_OUTPUT, destroy() implies setSurface(null).
-     *
      */
     @Override
     public void destroy() {
-        if((mUsage & USAGE_IO_OUTPUT) != 0) {
+        if (mIncCompatAllocation != 0) {
+            boolean shouldDestroy = false;
+            synchronized(this) {
+                if (!mIncAllocDestroyed) {
+                    shouldDestroy = true;
+                    mIncAllocDestroyed = true;
+                }
+            }
+
+            if (shouldDestroy) {
+                // must include nObjDestroy in the critical section
+                ReentrantReadWriteLock.ReadLock rlock = mRS.mRWLock.readLock();
+                rlock.lock();
+                if(mRS.isAlive()) {
+                    mRS.nIncObjDestroy(mIncCompatAllocation);
+                }
+                rlock.unlock();
+                mIncCompatAllocation = 0;
+            }
+        }
+        if ((mUsage & (USAGE_IO_INPUT | USAGE_IO_OUTPUT)) != 0) {
             setSurface(null);
         }
         super.destroy();
     }
+
 }
 
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/Element.java b/v8/renderscript/java/src/android/support/v8/renderscript/Element.java
index a483000..135d854 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/Element.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/Element.java
@@ -754,6 +754,13 @@
         super(id, rs);
     }
 
+    /*
+     * Get an identical dummy Element for Compat Context
+     *
+     */
+    public long getDummyElement(RenderScript mRS) {
+        return mRS.nIncElementCreate(mType.mID, mKind.mID, mNormalized, mVectorSize);
+    }
     /**
      * Create a custom Element of the specified DataType.  The DataKind will be
      * set to USER and the vector size to 1 indicating non-vector.
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java b/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
index 648f758..4de926c 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
@@ -79,7 +79,11 @@
     static private int sNative = -1;
     static private int sSdkVersion = -1;
     static private boolean useIOlib = false;
+    static private boolean useNative;
 
+    boolean isUseNative() {
+        return useNative;
+    }
     /*
      * Detect the bitness of the VM to allow FieldPacker to do the right thing.
      */
@@ -528,87 +532,131 @@
         rsnAllocationResize2D(mContext, id, dimX, dimY);
     }
 
-    native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
-    synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
+    native void rsnScriptBindAllocation(long con, long script, long alloc, int slot, boolean mUseInc);
+    synchronized void nScriptBindAllocation(long script, long alloc, int slot, boolean mUseInc) {
         validate();
-        rsnScriptBindAllocation(mContext, script, alloc, slot);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptBindAllocation(curCon, script, alloc, slot, mUseInc);
     }
-    native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
-    synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
+    native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone, boolean mUseInc);
+    synchronized void nScriptSetTimeZone(long script, byte[] timeZone, boolean mUseInc) {
         validate();
-        rsnScriptSetTimeZone(mContext, script, timeZone);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetTimeZone(curCon, script, timeZone, mUseInc);
     }
-    native void rsnScriptInvoke(long con, long id, int slot);
-    synchronized void nScriptInvoke(long id, int slot) {
+    native void rsnScriptInvoke(long con, long id, int slot, boolean mUseInc);
+    synchronized void nScriptInvoke(long id, int slot, boolean mUseInc) {
         validate();
-        rsnScriptInvoke(mContext, id, slot);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptInvoke(curCon, id, slot, mUseInc);
     }
-    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) {
+    native void rsnScriptForEach(long con, long incCon, long id, int slot, long ain, long aout, byte[] params, boolean mUseInc);
+    native void rsnScriptForEach(long con, long incCon, long id, int slot, long ain, long aout, boolean mUseInc);
+    native void rsnScriptForEachClipped(long con, long incCon, long id, int slot, long ain, long aout, byte[] params,
+                                        int xstart, int xend, int ystart, int yend, int zstart, int zend, boolean mUseInc);
+    native void rsnScriptForEachClipped(long con, long incCon, long id, int slot, long ain, long aout,
+                                        int xstart, int xend, int ystart, int yend, int zstart, int zend, boolean mUseInc);
+    synchronized void nScriptForEach(long id, int slot, long ain, long aout, byte[] params, boolean mUseInc) {
         validate();
         if (params == null) {
-            rsnScriptForEach(mContext, id, slot, ain, aout);
+            rsnScriptForEach(mContext, mIncCon, id, slot, ain, aout, mUseInc);
         } else {
-            rsnScriptForEach(mContext, id, slot, ain, aout, params);
+            rsnScriptForEach(mContext, mIncCon, id, slot, ain, aout, params, mUseInc);
         }
     }
 
     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) {
+                                            int xstart, int xend, int ystart, int yend, int zstart, int zend, boolean mUseInc) {
         validate();
         if (params == null) {
-            rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend);
+            rsnScriptForEachClipped(mContext, mIncCon, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend, mUseInc);
         } else {
-            rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend);
+            rsnScriptForEachClipped(mContext, mIncCon, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend, mUseInc);
         }
     }
 
-    native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
-    synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
+    native void rsnScriptInvokeV(long con, long id, int slot, byte[] params, boolean mUseInc);
+    synchronized void nScriptInvokeV(long id, int slot, byte[] params, boolean mUseInc) {
         validate();
-        rsnScriptInvokeV(mContext, id, slot, params);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptInvokeV(curCon, id, slot, params, mUseInc);
     }
-    native void rsnScriptSetVarI(long con, long id, int slot, int val);
-    synchronized void nScriptSetVarI(long id, int slot, int val) {
+    native void rsnScriptSetVarI(long con, long id, int slot, int val, boolean mUseInc);
+    synchronized void nScriptSetVarI(long id, int slot, int val, boolean mUseInc) {
         validate();
-        rsnScriptSetVarI(mContext, id, slot, val);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarI(curCon, id, slot, val, mUseInc);
     }
-    native void rsnScriptSetVarJ(long con, long id, int slot, long val);
-    synchronized void nScriptSetVarJ(long id, int slot, long val) {
+    native void rsnScriptSetVarJ(long con, long id, int slot, long val, boolean mUseInc);
+    synchronized void nScriptSetVarJ(long id, int slot, long val, boolean mUseInc) {
         validate();
-        rsnScriptSetVarJ(mContext, id, slot, val);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarJ(curCon, id, slot, val, mUseInc);
     }
-    native void rsnScriptSetVarF(long con, long id, int slot, float val);
-    synchronized void nScriptSetVarF(long id, int slot, float val) {
+    native void rsnScriptSetVarF(long con, long id, int slot, float val, boolean mUseInc);
+    synchronized void nScriptSetVarF(long id, int slot, float val, boolean mUseInc) {
         validate();
-        rsnScriptSetVarF(mContext, id, slot, val);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarF(curCon, id, slot, val, mUseInc);
     }
-    native void rsnScriptSetVarD(long con, long id, int slot, double val);
-    synchronized void nScriptSetVarD(long id, int slot, double val) {
+    native void rsnScriptSetVarD(long con, long id, int slot, double val, boolean mUseInc);
+    synchronized void nScriptSetVarD(long id, int slot, double val, boolean mUseInc) {
         validate();
-        rsnScriptSetVarD(mContext, id, slot, val);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarD(curCon, id, slot, val, mUseInc);
     }
-    native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
-    synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
+    native void rsnScriptSetVarV(long con, long id, int slot, byte[] val, boolean mUseInc);
+    synchronized void nScriptSetVarV(long id, int slot, byte[] val, boolean mUseInc) {
         validate();
-        rsnScriptSetVarV(mContext, id, slot, val);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarV(curCon, id, slot, val, mUseInc);
     }
     native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
-                                  long e, int[] dims);
+                                  long e, int[] dims, boolean mUseInc);
     synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
-                                      long e, int[] dims) {
+                                      long e, int[] dims, boolean mUseInc) {
         validate();
-        rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarVE(curCon, id, slot, val, e, dims, mUseInc);
     }
-    native void rsnScriptSetVarObj(long con, long id, int slot, long val);
-    synchronized void nScriptSetVarObj(long id, int slot, long val) {
+    native void rsnScriptSetVarObj(long con, long id, int slot, long val, boolean mUseInc);
+    synchronized void nScriptSetVarObj(long id, int slot, long val, boolean mUseInc) {
         validate();
-        rsnScriptSetVarObj(mContext, id, slot, val);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        rsnScriptSetVarObj(curCon, id, slot, val, mUseInc);
     }
 
     native long  rsnScriptCCreate(long con, String resName, String cacheDir,
@@ -618,16 +666,43 @@
         return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
     }
 
-    native long  rsnScriptIntrinsicCreate(long con, int id, long eid);
-    synchronized long nScriptIntrinsicCreate(int id, long eid) {
+    native long  rsnScriptIntrinsicCreate(long con, int id, long eid, boolean mUseInc);
+    synchronized long nScriptIntrinsicCreate(int id, long eid, boolean mUseInc) {
         validate();
-        return rsnScriptIntrinsicCreate(mContext, id, eid);
+        if (mUseInc) {
+            if (!mIncLoaded) {
+                try {
+                    System.loadLibrary("RSSupport");
+                } catch (UnsatisfiedLinkError e) {
+                    Log.e(LOG_TAG, "Error loading RS Compat library for Incremental Intrinsic Support: " + e);
+                    throw new RSRuntimeException("Error loading RS Compat library for Incremental Intrinsic Support: " + e);
+                }
+                if (!nIncLoadSO()) {
+                    throw new RSRuntimeException("Error loading libRSSupport library for Incremental Intrinsic Support");
+                }
+                mIncLoaded = true;
+            }
+            if (mIncDev == 0) {
+                mIncDev = nIncDeviceCreate();
+            }
+            if (mIncCon == 0) {
+                //Create a dummy compat context (synchronous).
+                mIncCon = nIncContextCreate(mIncDev, 0, 0, 0);
+            }
+            return rsnScriptIntrinsicCreate(mIncCon, id, eid, mUseInc);
+        } else {
+            return rsnScriptIntrinsicCreate(mContext, id, eid, mUseInc);
+        }
     }
 
-    native long  rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
-    synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
+    native long  rsnScriptKernelIDCreate(long con, long sid, int slot, int sig, boolean mUseInc);
+    synchronized long nScriptKernelIDCreate(long sid, int slot, int sig, boolean mUseInc) {
         validate();
-        return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        return rsnScriptKernelIDCreate(curCon, sid, slot, sig, mUseInc);
     }
 
     native long  rsnScriptInvokeIDCreate(long con, long sid, int slot);
@@ -636,10 +711,14 @@
         return rsnScriptInvokeIDCreate(mContext, sid, slot);
     }
 
-    native long  rsnScriptFieldIDCreate(long con, long sid, int slot);
-    synchronized long nScriptFieldIDCreate(long sid, int slot) {
+    native long  rsnScriptFieldIDCreate(long con, long sid, int slot, boolean mUseInc);
+    synchronized long nScriptFieldIDCreate(long sid, int slot, boolean mUseInc) {
         validate();
-        return rsnScriptFieldIDCreate(mContext, sid, slot);
+        long curCon = mContext;
+        if (mUseInc) {
+            curCon = mIncCon;
+        }
+        return rsnScriptFieldIDCreate(curCon, sid, slot, mUseInc);
     }
 
     native long  rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
@@ -674,11 +753,72 @@
         return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
     }
 
+// Additional Entry points For inc libRSSupport
 
+    native boolean nIncLoadSO();
+    native long nIncDeviceCreate();
+    native void nIncDeviceDestroy(long dev);
+    // Methods below are wrapped to protect the non-threadsafe
+    // lockless fifo.
+    native long  rsnIncContextCreate(long dev, int ver, int sdkVer, int contextType);
+    synchronized long nIncContextCreate(long dev, int ver, int sdkVer, int contextType) {
+        return rsnIncContextCreate(dev, ver, sdkVer, contextType);
+    }
+    native void rsnIncContextDestroy(long con);
+    synchronized void nIncContextDestroy() {
+        validate();
 
+        // take teardown lock
+        // teardown lock can only be taken when no objects are being destroyed
+        ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
+        wlock.lock();
+
+        long curCon = mIncCon;
+        // context is considered dead as of this point
+        mIncCon = 0;
+
+        wlock.unlock();
+        rsnIncContextDestroy(curCon);
+    }
+
+    native void rsnIncContextFinish(long con);
+    synchronized void nIncContextFinish() {
+        validate();
+        rsnIncContextFinish(mIncCon);
+    }
+
+    native void rsnIncObjDestroy(long con, long id);
+    void nIncObjDestroy(long id) {
+        // There is a race condition here.  The calling code may be run
+        // by the gc while teardown is occuring.  This protects againts
+        // deleting dead objects.
+        if (mIncCon != 0) {
+            rsnIncObjDestroy(mIncCon, id);
+        }
+    }
+    native long  rsnIncElementCreate(long con, long type, int kind, boolean norm, int vecSize);
+    synchronized long nIncElementCreate(long type, int kind, boolean norm, int vecSize) {
+        validate();
+        return rsnIncElementCreate(mIncCon, type, kind, norm, vecSize);
+    }
+    native long rsnIncTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
+    synchronized long nIncTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
+        validate();
+        return rsnIncTypeCreate(mIncCon, eid, x, y, z, mips, faces, yuv);
+    }
+    native long  rsnIncAllocationCreateTyped(long con, long incCon, long alloc, long type);
+    synchronized long nIncAllocationCreateTyped(long alloc, long type) {
+        validate();
+        return rsnIncAllocationCreateTyped(mContext, mIncCon, alloc, type);
+    }
 
     long     mDev;
     long     mContext;
+    //Dummy device & context for Inc Support Lib
+    long     mIncDev;
+    long     mIncCon;
+    //indicator of whether inc support lib has been loaded or not.
+    boolean  mIncLoaded;
     ReentrantReadWriteLock mRWLock;
     @SuppressWarnings({"FieldCanBeLocal"})
     MessageThread mMessageThread;
@@ -888,8 +1028,8 @@
         static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
         static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
         static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
-        static final int RS_MESSAGE_TO_CLIENT_USER = 4;
 
+        static final int RS_MESSAGE_TO_CLIENT_USER = 4;
         static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
 
         MessageThread(RenderScript rs) {
@@ -966,6 +1106,9 @@
             mApplicationContext = ctx.getApplicationContext();
             mNativeLibDir = mApplicationContext.getApplicationInfo().nativeLibraryDir;
         }
+        mIncDev = 0;
+        mIncCon = 0;
+        mIncLoaded = false;
         mRWLock = new ReentrantReadWriteLock();
     }
 
@@ -1000,7 +1143,7 @@
         } else if (sSdkVersion != sdkVersion) {
             throw new RSRuntimeException("Can't have two contexts with different SDK versions in support lib");
         }
-        boolean useNative = setupNative(sSdkVersion, ctx);
+        useNative = setupNative(sSdkVersion, ctx);
         synchronized(lock) {
             if (sInitialized == false) {
                 try {
@@ -1037,6 +1180,7 @@
         if (!rs.nLoadSO(useNative)) {
             if (useNative) {
                 android.util.Log.v(LOG_TAG, "Unable to load libRS.so, falling back to compat mode");
+                useNative = false;
             }
             try {
                 System.loadLibrary("RSSupport");
@@ -1123,6 +1267,11 @@
     public void destroy() {
         validate();
         nContextFinish();
+        if (mIncCon != 0) {
+            nIncContextFinish();
+            nIncContextDestroy();
+            mIncCon = 0;
+        }
         nContextDeinitToClient(mContext);
         mMessageThread.mRun = false;
         try {
@@ -1132,6 +1281,10 @@
 
         nContextDestroy();
         nDeviceDestroy(mDev);
+        if (mIncDev != 0) {
+            nIncDeviceDestroy(mIncDev);
+            mIncDev = 0;
+        }
         mDev = 0;
     }
 
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/Script.java b/v8/renderscript/java/src/android/support/v8/renderscript/Script.java
index f506daa..fcb4fd9 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/Script.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/Script.java
@@ -24,6 +24,35 @@
  **/
 public class Script extends BaseObj {
     /**
+     * Determine if Incremental Intrinsic Support is needed
+     *
+     */
+    private boolean mUseIncSupp;
+    protected void setIncSupp(boolean useInc) {
+        mUseIncSupp = useInc;
+    }
+    protected boolean isIncSupp() {
+        return mUseIncSupp;
+    }
+    /**
+     * An allocation for the compat context will be created when needed
+     * e.g. foreach(ain, aout), setVar(ain);
+     *
+     */
+    private long getDummyAlloc(Allocation ain) {
+        long dInElement = 0;
+        long dInType = 0;
+        long dummyAlloc = 0;
+        if (ain != null) {
+            dInElement = ain.getType().getElement().getDummyElement(mRS);
+            dInType = ain.getType().getDummyType(mRS, dInElement);
+            dummyAlloc = mRS.nIncAllocationCreateTyped(ain.getID(mRS), dInType);
+            ain.setIncAllocID(dummyAlloc);
+        }
+
+        return dummyAlloc;
+    }
+    /**
      * KernelID is an identifier for a Script + root function pair. It is used
      * as an identifier for ScriptGroup creation.
      *
@@ -61,7 +90,8 @@
         if (k != null) {
             return k;
         }
-        long id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig);
+
+        long id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig, mUseIncSupp);
         if (id == 0) {
             throw new RSDriverException("Failed to create KernelID");
         }
@@ -145,7 +175,7 @@
             return f;
         }
 
-        long id = mRS.nScriptFieldIDCreate(getID(mRS), slot);
+        long id = mRS.nScriptFieldIDCreate(getID(mRS), slot, mUseIncSupp);
         if (id == 0) {
             throw new RSDriverException("Failed to create FieldID");
         }
@@ -155,14 +185,13 @@
         return f;
     }
 
-
     /**
      * Only intended for use by generated reflected code.
      *
      * @param slot
      */
     protected void invoke(int slot) {
-        mRS.nScriptInvoke(getID(mRS), slot);
+        mRS.nScriptInvoke(getID(mRS), slot, mUseIncSupp);
     }
 
     /**
@@ -173,9 +202,9 @@
      */
     protected void invoke(int slot, FieldPacker v) {
         if (v != null) {
-            mRS.nScriptInvokeV(getID(mRS), slot, v.getData());
+            mRS.nScriptInvokeV(getID(mRS), slot, v.getData(), mUseIncSupp);
         } else {
-            mRS.nScriptInvoke(getID(mRS), slot);
+            mRS.nScriptInvoke(getID(mRS), slot, mUseIncSupp);
         }
     }
 
@@ -188,16 +217,16 @@
     public void bindAllocation(Allocation va, int slot) {
         mRS.validate();
         if (va != null) {
-            mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
+            mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot, mUseIncSupp);
         } else {
-            mRS.nScriptBindAllocation(getID(mRS), 0, slot);
+            mRS.nScriptBindAllocation(getID(mRS), 0, slot, mUseIncSupp);
         }
     }
 
     public void setTimeZone(String timeZone) {
         mRS.validate();
         try {
-            mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
+            mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"), mUseIncSupp);
         } catch (java.io.UnsupportedEncodingException e) {
             throw new RuntimeException(e);
         }
@@ -218,18 +247,26 @@
                 "At least one of ain or aout is required to be non-null.");
         }
         long in_id = 0;
+        long out_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);
+
+        if (mUseIncSupp) {
+            long ainInc = getDummyAlloc(ain);
+            long aoutInc = getDummyAlloc(aout);
+            mRS.nScriptForEach(getID(mRS), slot, ainInc, aoutInc, params, mUseIncSupp);
+        } else {
+            mRS.nScriptForEach(getID(mRS), slot, in_id, out_id, params, mUseIncSupp);
+        }
     }
 
     /**
@@ -252,22 +289,30 @@
             return;
         }
         long in_id = 0;
+        long out_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.nScriptForEachClipped(getID(mRS), slot, in_id, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend);
+        if (mUseIncSupp) {
+            long ainInc = getDummyAlloc(ain);
+            long aoutInc = getDummyAlloc(aout);
+            mRS.nScriptForEachClipped(getID(mRS), slot, ainInc, aoutInc, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend, mUseIncSupp);        
+        } else {
+            mRS.nScriptForEachClipped(getID(mRS), slot, in_id, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend, mUseIncSupp);
+        }
     }
 
     Script(long id, RenderScript rs) {
         super(id, rs);
+        mUseIncSupp = false;
     }
 
     /**
@@ -277,7 +322,7 @@
      * @param v
      */
     public void setVar(int index, float v) {
-        mRS.nScriptSetVarF(getID(mRS), index, v);
+        mRS.nScriptSetVarF(getID(mRS), index, v, mUseIncSupp);
     }
 
     /**
@@ -287,7 +332,7 @@
      * @param v
      */
     public void setVar(int index, double v) {
-        mRS.nScriptSetVarD(getID(mRS), index, v);
+        mRS.nScriptSetVarD(getID(mRS), index, v, mUseIncSupp);
     }
 
     /**
@@ -297,7 +342,7 @@
      * @param v
      */
     public void setVar(int index, int v) {
-        mRS.nScriptSetVarI(getID(mRS), index, v);
+        mRS.nScriptSetVarI(getID(mRS), index, v, mUseIncSupp);
     }
 
     /**
@@ -307,7 +352,7 @@
      * @param v
      */
     public void setVar(int index, long v) {
-        mRS.nScriptSetVarJ(getID(mRS), index, v);
+        mRS.nScriptSetVarD(getID(mRS), index, v, mUseIncSupp);
     }
 
     /**
@@ -317,7 +362,7 @@
      * @param v
      */
     public void setVar(int index, boolean v) {
-        mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
+        mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0, mUseIncSupp);
     }
 
     /**
@@ -327,7 +372,12 @@
      * @param o
      */
     public void setVar(int index, BaseObj o) {
-        mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
+        if (mUseIncSupp) {
+            long oInc = getDummyAlloc((Allocation)o);
+            mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : oInc, mUseIncSupp);            
+        } else {
+            mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS), mUseIncSupp);
+        }
     }
 
     /**
@@ -337,7 +387,7 @@
      * @param v
      */
     public void setVar(int index, FieldPacker v) {
-        mRS.nScriptSetVarV(getID(mRS), index, v.getData());
+        mRS.nScriptSetVarV(getID(mRS), index, v.getData(), mUseIncSupp);
     }
 
     /**
@@ -349,7 +399,12 @@
      * @param dims
      */
     public void setVar(int index, FieldPacker v, Element e, int[] dims) {
-        mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
+        if (mUseIncSupp) {
+            long dElement = e.getDummyElement(mRS);
+            mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), dElement, dims, mUseIncSupp);
+        } else {
+            mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims, mUseIncSupp);
+        }
     }
 
     /**
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptGroup.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptGroup.java
index 9c38f33..a6e6d00 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptGroup.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptGroup.java
@@ -18,6 +18,8 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 
 /**
  * ScriptGroup creates a group of kernels that are executed
@@ -46,6 +48,8 @@
 public class ScriptGroup extends BaseObj {
     IO mOutputs[];
     IO mInputs[];
+    private boolean mUseIncSupp = false;
+    private ArrayList<Node> mNodes = new ArrayList<Node>();
 
     static class IO {
         Script.KernelID mKID;
@@ -73,6 +77,7 @@
         Script.KernelID mToK;
         Script.KernelID mFrom;
         Type mAllocationType;
+        Allocation mAllocation;
     }
 
     static class Node {
@@ -81,6 +86,8 @@
         ArrayList<ConnectLine> mInputs = new ArrayList<ConnectLine>();
         ArrayList<ConnectLine> mOutputs = new ArrayList<ConnectLine>();
         int dagNumber;
+        boolean mSeen;
+        int mOrder;
 
         Node mNext;
 
@@ -107,7 +114,9 @@
         for (int ct=0; ct < mInputs.length; ct++) {
             if (mInputs[ct].mKID == s) {
                 mInputs[ct].mAllocation = a;
-                mRS.nScriptGroupSetInput(getID(mRS), s.getID(mRS), mRS.safeID(a));
+                if (!mUseIncSupp) {
+                    mRS.nScriptGroupSetInput(getID(mRS), s.getID(mRS), mRS.safeID(a));
+                }
                 return;
             }
         }
@@ -127,7 +136,9 @@
         for (int ct=0; ct < mOutputs.length; ct++) {
             if (mOutputs[ct].mKID == s) {
                 mOutputs[ct].mAllocation = a;
-                mRS.nScriptGroupSetOutput(getID(mRS), s.getID(mRS), mRS.safeID(a));
+                if (!mUseIncSupp) {
+                    mRS.nScriptGroupSetOutput(getID(mRS), s.getID(mRS), mRS.safeID(a));
+                }
                 return;
             }
         }
@@ -138,9 +149,70 @@
      * Execute the ScriptGroup.  This will run all the kernels in
      * the ScriptGroup.  No internal connection results will be visible
      * after execution of the ScriptGroup.
+     *
+     * If Incremental Support for intrinsics is needed, the execution
+     * will take the naive path: execute kernels one by one in the
+     * correct order.
      */
     public void execute() {
-        mRS.nScriptGroupExecute(getID(mRS));
+        if (!mUseIncSupp) {
+            mRS.nScriptGroupExecute(getID(mRS));
+        } else {
+            // setup the allocations.
+            for (int ct=0; ct < mNodes.size(); ct++) {
+                Node n = mNodes.get(ct);
+                for (int ct2=0; ct2 < n.mOutputs.size(); ct2++) {
+                    ConnectLine l = n.mOutputs.get(ct2);
+                    if (l.mAllocation !=null) {
+                        continue;
+                    }
+
+                    //create allocation here
+                    Allocation alloc = Allocation.createTyped(mRS, l.mAllocationType,
+                                                              Allocation.MipmapControl.MIPMAP_NONE,
+                                                              Allocation.USAGE_SCRIPT);
+
+                    l.mAllocation = alloc;
+                    for (int ct3=ct2+1; ct3 < n.mOutputs.size(); ct3++) {
+                        if (n.mOutputs.get(ct3).mFrom == l.mFrom) {
+                            n.mOutputs.get(ct3).mAllocation = alloc;
+                        }
+                    }
+                }
+            }
+            for (Node node : mNodes) {
+                for (Script.KernelID kernel : node.mKernels) {
+                    Allocation ain  = null;
+                    Allocation aout = null;
+
+                    for (ConnectLine nodeInput : node.mInputs) {
+                        if (nodeInput.mToK == kernel) {
+                            ain = nodeInput.mAllocation;
+                        }
+                    }
+
+                    for (IO sgInput : mInputs) {
+                        if (sgInput.mKID == kernel) {
+                            ain = sgInput.mAllocation;
+                        }
+                    }
+
+                    for (ConnectLine nodeOutput : node.mOutputs) {
+                        if (nodeOutput.mFrom == kernel) {
+                            aout = nodeOutput.mAllocation;
+                        }
+                    }
+
+                    for (IO sgOutput : mOutputs) {
+                        if (sgOutput.mKID == kernel) {
+                            aout = sgOutput.mAllocation;
+                        }
+                    }
+
+                    kernel.mScript.forEach(kernel.mSlot, ain, aout, null);
+                }
+            }
+        }
     }
 
 
@@ -172,6 +244,7 @@
         private ArrayList<Node> mNodes = new ArrayList<Node>();
         private ArrayList<ConnectLine> mLines = new ArrayList<ConnectLine>();
         private int mKernelCount;
+        private boolean mUseIncSupp = false;
 
         /**
          * Create a Builder for generating a ScriptGroup.
@@ -285,7 +358,9 @@
                 throw new RSInvalidStateException(
                     "Kernels may not be added once connections exist.");
             }
-
+            if (k.mScript.isIncSupp()) {
+                mUseIncSupp = true;
+            }
             //android.util.Log.v("RSR", "addKernel 1 k=" + k);
             if (findNode(k) != null) {
                 return this;
@@ -370,7 +445,54 @@
             return this;
         }
 
+        /**
+         * Calculate the order of each node.
+         *
+         *
+         * @return Success or Fail
+         */
+        private boolean calcOrderRecurse(Node node0, int depth) {
+            node0.mSeen = true;
+            if (node0.mOrder < depth) {
+                node0.mOrder = depth;
+            }
+            boolean ret = true;
 
+            for (ConnectLine link : node0.mOutputs) {
+                Node node1 = null;
+                if (link.mToF != null) {
+                    node1 = findNode(link.mToF.mScript);
+                } else {
+                    node1 = findNode(link.mToK.mScript);
+                }
+                if (node1.mSeen) {
+                    return false;
+                }
+                ret &= calcOrderRecurse(node1, node0.mOrder + 1);
+            }
+
+            return ret;
+        }
+
+        private boolean calcOrder() {
+            boolean ret = true;
+            for (Node n0 : mNodes) {
+                if (n0.mInputs.size() == 0) {
+                    for (Node n1 : mNodes) {
+                        n1.mSeen = false;
+                    }
+                    ret &= calcOrderRecurse(n0, 1);
+                }
+            }
+
+            Collections.sort(mNodes, new Comparator<Node>() {
+                public int compare(Node n1, Node n2) {
+                    return n1.mOrder - n2.mOrder;
+                }
+            });
+
+            return ret;
+        }
 
         /**
          * Creates the Script group.
@@ -419,33 +541,37 @@
                     if (!hasOutput) {
                         outputs.add(new IO(kid));
                     }
-
                 }
             }
             if (idx != mKernelCount) {
                 throw new RSRuntimeException("Count mismatch, should not happen.");
             }
 
-            long[] src = new long[mLines.size()];
-            long[] dstk = new long[mLines.size()];
-            long[] dstf = new long[mLines.size()];
-            long[] types = new long[mLines.size()];
+            long id = 0;
+            if (!mUseIncSupp) {
+                long[] src = new long[mLines.size()];
+                long[] dstk = new long[mLines.size()];
+                long[] dstf = new long[mLines.size()];
+                long[] types = new long[mLines.size()];
 
-            for (int ct=0; ct < mLines.size(); ct++) {
-                ConnectLine cl = mLines.get(ct);
-                src[ct] = cl.mFrom.getID(mRS);
-                if (cl.mToK != null) {
-                    dstk[ct] = cl.mToK.getID(mRS);
+                for (int ct=0; ct < mLines.size(); ct++) {
+                    ConnectLine cl = mLines.get(ct);
+                    src[ct] = cl.mFrom.getID(mRS);
+                    if (cl.mToK != null) {
+                        dstk[ct] = cl.mToK.getID(mRS);
+                    }
+                    if (cl.mToF != null) {
+                        dstf[ct] = cl.mToF.getID(mRS);
+                    }
+                    types[ct] = cl.mAllocationType.getID(mRS);
                 }
-                if (cl.mToF != null) {
-                    dstf[ct] = cl.mToF.getID(mRS);
+                id = mRS.nScriptGroupCreate(kernels, src, dstk, dstf, types);
+                if (id == 0) {
+                    throw new RSRuntimeException("Object creation error, should not happen.");
                 }
-                types[ct] = cl.mAllocationType.getID(mRS);
-            }
-
-            long id = mRS.nScriptGroupCreate(kernels, src, dstk, dstf, types);
-            if (id == 0) {
-                throw new RSRuntimeException("Object creation error, should not happen.");
+            } else {
+                //Calculate the order of the DAG so that script can run one after another.
+                calcOrder();
             }
 
             ScriptGroup sg = new ScriptGroup(id, mRS);
@@ -458,7 +584,8 @@
             for (int ct=0; ct < inputs.size(); ct++) {
                 sg.mInputs[ct] = inputs.get(ct);
             }
-
+            sg.mNodes = mNodes;
+            sg.mUseIncSupp = mUseIncSupp;
             return sg;
         }
 
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsic3DLUT.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsic3DLUT.java
index dad86fb..dcd1bc1 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsic3DLUT.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsic3DLUT.java
@@ -30,6 +30,8 @@
 public class ScriptIntrinsic3DLUT extends ScriptIntrinsic {
     private Allocation mLUT;
     private Element mElement;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     protected ScriptIntrinsic3DLUT(long id, RenderScript rs, Element e) {
         super(id, rs);
@@ -47,13 +49,18 @@
      * @return ScriptIntrinsic3DLUT
      */
     public static ScriptIntrinsic3DLUT create(RenderScript rs, Element e) {
-        long id = rs.nScriptIntrinsicCreate(8, e.getID(rs));
-
         if (!e.isCompatible(Element.U8_4(rs))) {
             throw new RSIllegalArgumentException("Element must be compatible with uchar4.");
         }
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
 
-        return new ScriptIntrinsic3DLUT(id, rs, e);
+        id = rs.nScriptIntrinsicCreate(8, e.getID(rs), mUseIncSupp);
+
+        ScriptIntrinsic3DLUT si = new ScriptIntrinsic3DLUT(id, rs, e);
+        si.setIncSupp(mUseIncSupp);
+        return si;
     }
 
     /**
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlend.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlend.java
index f3facac..7b1e59b 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlend.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlend.java
@@ -22,6 +22,9 @@
  * {@link android.support.v8.renderscript.Allocation} objects.
  **/
 public class ScriptIntrinsicBlend extends ScriptIntrinsic {
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
+
     ScriptIntrinsicBlend(long id, RenderScript rs) {
         super(id, rs);
     }
@@ -36,8 +39,15 @@
      */
     public static ScriptIntrinsicBlend create(RenderScript rs, Element e) {
         // 7 comes from RS_SCRIPT_INTRINSIC_ID_BLEND in rsDefines.h
-        long id = rs.nScriptIntrinsicCreate(7, e.getID(rs));
-        return new ScriptIntrinsicBlend(id, rs);
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(7, e.getID(rs), mUseIncSupp);
+
+        ScriptIntrinsicBlend si = new ScriptIntrinsicBlend(id, rs);
+        si.setIncSupp(mUseIncSupp);
+        return si;
 
     }
 
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlur.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlur.java
index b2378b3..a5b046b 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlur.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicBlur.java
@@ -29,6 +29,8 @@
 public class ScriptIntrinsicBlur extends ScriptIntrinsic {
     private final float[] mValues = new float[9];
     private Allocation mInput;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     protected ScriptIntrinsicBlur(long id, RenderScript rs) {
         super(id, rs);
@@ -49,10 +51,17 @@
         if ((!e.isCompatible(Element.U8_4(rs))) && (!e.isCompatible(Element.U8(rs)))) {
             throw new RSIllegalArgumentException("Unsuported element type.");
         }
-        long id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
-        ScriptIntrinsicBlur sib = new ScriptIntrinsicBlur(id, rs);
-        sib.setRadius(5.f);
-        return sib;
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(5, e.getID(rs), mUseIncSupp);
+
+        ScriptIntrinsicBlur si = new ScriptIntrinsicBlur(id, rs);
+        si.setIncSupp(mUseIncSupp);
+        si.setRadius(5.f);
+
+        return si;
     }
 
     /**
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicColorMatrix.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicColorMatrix.java
index 52cdb1f..5aa9572 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicColorMatrix.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicColorMatrix.java
@@ -29,7 +29,10 @@
  **/
 public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
     private final Matrix4f mMatrix = new Matrix4f();
+    private final Float4 mAdd = new Float4();
     private Allocation mInput;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     protected ScriptIntrinsicColorMatrix(long id, RenderScript rs) {
         super(id, rs);
@@ -50,8 +53,15 @@
         if (!e.isCompatible(Element.U8_4(rs))) {
             throw new RSIllegalArgumentException("Unsuported element type.");
         }
-        long id = rs.nScriptIntrinsicCreate(2, e.getID(rs));
-        return new ScriptIntrinsicColorMatrix(id, rs);
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(2, e.getID(rs), mUseIncSupp);
+
+        ScriptIntrinsicColorMatrix si = new ScriptIntrinsicColorMatrix(id, rs);
+        si.setIncSupp(mUseIncSupp);
+        return si;
 
     }
 
@@ -84,6 +94,49 @@
     }
 
     /**
+     * Set the value to be added after the color matrix has been
+     * applied. The default value is {0, 0, 0, 0}
+     *
+     * @param f The float4 value to be added.
+     */
+    public void setAdd(Float4 f) {
+        mAdd.x = f.x;
+        mAdd.y = f.y;
+        mAdd.z = f.z;
+        mAdd.w = f.w;
+
+        FieldPacker fp = new FieldPacker(4*4);
+        fp.addF32(f.x);
+        fp.addF32(f.y);
+        fp.addF32(f.z);
+        fp.addF32(f.w);
+        setVar(1, fp);
+    }
+
+    /**
+     * Set the value to be added after the color matrix has been
+     * applied. The default value is {0, 0, 0, 0}
+     *
+     * @param r The red add value.
+     * @param g The green add value.
+     * @param b The blue add value.
+     * @param a The alpha add value.
+     */
+    public void setAdd(float r, float g, float b, float a) {
+        mAdd.x = r;
+        mAdd.y = g;
+        mAdd.z = b;
+        mAdd.w = a;
+
+        FieldPacker fp = new FieldPacker(4*4);
+        fp.addF32(mAdd.x);
+        fp.addF32(mAdd.y);
+        fp.addF32(mAdd.z);
+        fp.addF32(mAdd.w);
+        setVar(1, fp);
+    }
+
+    /**
      * Set a color matrix to convert from RGB to luminance. The alpha channel
      * will be a copy.
      *
@@ -153,6 +206,50 @@
     }
 
     /**
+     * Invoke the kernel and apply the matrix to each cell of input
+     * {@link Allocation} and copy to the output {@link Allocation}.
+     *
+     * If the vector size of the input is less than four, the
+     * remaining components are treated as zero for the matrix
+     * multiply.
+     *
+     * If the output vector size is less than four, the unused
+     * vector components are discarded.
+     *
+     *
+     * @param ain Input allocation
+     * @param aout Output allocation
+     * @param opt LaunchOptions for clipping
+     */
+    public void forEach(Allocation ain, Allocation aout, Script.LaunchOptions opt) {
+        if (!ain.getElement().isCompatible(Element.U8(mRS)) &&
+            !ain.getElement().isCompatible(Element.U8_2(mRS)) &&
+            !ain.getElement().isCompatible(Element.U8_3(mRS)) &&
+            !ain.getElement().isCompatible(Element.U8_4(mRS)) &&
+            !ain.getElement().isCompatible(Element.F32(mRS)) &&
+            !ain.getElement().isCompatible(Element.F32_2(mRS)) &&
+            !ain.getElement().isCompatible(Element.F32_3(mRS)) &&
+            !ain.getElement().isCompatible(Element.F32_4(mRS))) {
+
+            throw new RSIllegalArgumentException("Unsuported element type.");
+        }
+
+        if (!aout.getElement().isCompatible(Element.U8(mRS)) &&
+            !aout.getElement().isCompatible(Element.U8_2(mRS)) &&
+            !aout.getElement().isCompatible(Element.U8_3(mRS)) &&
+            !aout.getElement().isCompatible(Element.U8_4(mRS)) &&
+            !aout.getElement().isCompatible(Element.F32(mRS)) &&
+            !aout.getElement().isCompatible(Element.F32_2(mRS)) &&
+            !aout.getElement().isCompatible(Element.F32_3(mRS)) &&
+            !aout.getElement().isCompatible(Element.F32_4(mRS))) {
+
+            throw new RSIllegalArgumentException("Unsuported element type.");
+        }
+
+        forEach(0, ain, aout, null, opt);
+    }
+
+    /**
      * Get a KernelID for this intrinsic kernel.
      *
      * @return Script.KernelID The KernelID object.
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve3x3.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve3x3.java
index 918f11a..ea45461 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve3x3.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve3x3.java
@@ -25,13 +25,18 @@
 public class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic {
     private final float[] mValues = new float[9];
     private Allocation mInput;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     ScriptIntrinsicConvolve3x3(long id, RenderScript rs) {
         super(id, rs);
     }
 
     /**
-     * Supported elements types are {@link Element#U8_4}
+     * Supported elements types are {@link Element#U8}, {@link
+     * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4},
+     * {@link Element#F32}, {@link Element#F32_2}, {@link
+     * Element#F32_3}, and {@link Element#F32_4}
      *
      * The default coefficients are.
      *
@@ -48,11 +53,24 @@
      */
     public static ScriptIntrinsicConvolve3x3 create(RenderScript rs, Element e) {
         float f[] = { 0, 0, 0, 0, 1, 0, 0, 0, 0};
-        if (!e.isCompatible(Element.U8_4(rs))) {
+        if (!e.isCompatible(Element.U8(rs)) &&
+            !e.isCompatible(Element.U8_2(rs)) &&
+            !e.isCompatible(Element.U8_3(rs)) &&
+            !e.isCompatible(Element.U8_4(rs)) &&
+            !e.isCompatible(Element.F32(rs)) &&
+            !e.isCompatible(Element.F32_2(rs)) &&
+            !e.isCompatible(Element.F32_3(rs)) &&
+            !e.isCompatible(Element.F32_4(rs))) {
             throw new RSIllegalArgumentException("Unsuported element type.");
         }
-        long id = rs.nScriptIntrinsicCreate(1, e.getID(rs));
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(1, e.getID(rs), mUseIncSupp);
+
         ScriptIntrinsicConvolve3x3 si = new ScriptIntrinsicConvolve3x3(id, rs);
+        si.setIncSupp(mUseIncSupp);
         si.setCoefficients(f);
         return si;
     }
@@ -101,6 +119,18 @@
     }
 
     /**
+     * Apply the filter to the input and save to the specified
+     * allocation.
+     *
+     * @param aout Output allocation. Must match creation element
+     *             type.
+     * @param opt LaunchOptions for clipping
+     */
+    public void forEach(Allocation aout, Script.LaunchOptions opt) {
+        forEach(0, (Allocation) null, aout, null, opt);
+    }
+
+    /**
      * Get a KernelID for this intrinsic kernel.
      *
      * @return Script.KernelID The KernelID object.
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve5x5.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve5x5.java
index 1d9fd8d..bcd37f1 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve5x5.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicConvolve5x5.java
@@ -25,13 +25,18 @@
 public class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic {
     private final float[] mValues = new float[25];
     private Allocation mInput;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     ScriptIntrinsicConvolve5x5(long id, RenderScript rs) {
         super(id, rs);
     }
 
     /**
-     * Supported elements types are {@link Element#U8_4}
+     * Supported elements types are {@link Element#U8}, {@link
+     * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4},
+     * {@link Element#F32}, {@link Element#F32_2}, {@link
+     * Element#F32_3}, and {@link Element#F32_4}
      *
      * The default coefficients are.
      * <code>
@@ -48,8 +53,25 @@
      * @return ScriptIntrinsicConvolve5x5
      */
     public static ScriptIntrinsicConvolve5x5 create(RenderScript rs, Element e) {
-        long id = rs.nScriptIntrinsicCreate(4, e.getID(rs));
-        return new ScriptIntrinsicConvolve5x5(id, rs);
+        if (!e.isCompatible(Element.U8(rs)) &&
+            !e.isCompatible(Element.U8_2(rs)) &&
+            !e.isCompatible(Element.U8_3(rs)) &&
+            !e.isCompatible(Element.U8_4(rs)) &&
+            !e.isCompatible(Element.F32(rs)) &&
+            !e.isCompatible(Element.F32_2(rs)) &&
+            !e.isCompatible(Element.F32_3(rs)) &&
+            !e.isCompatible(Element.F32_4(rs))) {
+            throw new RSIllegalArgumentException("Unsuported element type.");
+        }
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(4, e.getID(rs), mUseIncSupp);
+
+        ScriptIntrinsicConvolve5x5 si = new ScriptIntrinsicConvolve5x5(id, rs);
+        si.setIncSupp(mUseIncSupp);
+        return si;
 
     }
 
@@ -99,6 +121,19 @@
     }
 
     /**
+     * Apply the filter to the input and save to the specified
+     * allocation.
+     *
+     * @param aout Output allocation. Must match creation element
+     *             type.
+     * @param opt LaunchOptions for clipping
+     */
+    public void forEach(Allocation aout, Script.LaunchOptions opt) {
+        forEach(0, (Allocation) null, aout, null, opt);
+    }
+
+
+    /**
      * Get a KernelID for this intrinsic kernel.
      *
      * @return Script.KernelID The KernelID object.
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicHistogram.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicHistogram.java
new file mode 100644
index 0000000..43ac015
--- /dev/null
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicHistogram.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.support.v8.renderscript;
+
+import android.util.Log;
+
+/**
+ * Intrinsic Histogram filter.
+ *
+ *
+ **/
+public class ScriptIntrinsicHistogram extends ScriptIntrinsic {
+    private Allocation mOut;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
+
+    protected ScriptIntrinsicHistogram(long id, RenderScript rs) {
+        super(id, rs);
+    }
+
+    /**
+     * Create an intrinsic for calculating the histogram of an uchar
+     * or uchar4 image.
+     *
+     * Supported elements types are
+     * {@link Element#U8_4}, {@link Element#U8_3},
+     * {@link Element#U8_2}, {@link Element#U8}
+     *
+     * @param rs The RenderScript context
+     * @param e Element type for inputs
+     *
+     * @return ScriptIntrinsicHistogram
+     */
+    public static ScriptIntrinsicHistogram create(RenderScript rs, Element e) {
+        if ((!e.isCompatible(Element.U8_4(rs))) &&
+            (!e.isCompatible(Element.U8_3(rs))) &&
+            (!e.isCompatible(Element.U8_2(rs))) &&
+            (!e.isCompatible(Element.U8(rs)))) {
+            throw new RSIllegalArgumentException("Unsuported element type.");
+        }
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(9, e.getID(rs), mUseIncSupp);
+
+        ScriptIntrinsicHistogram si = new ScriptIntrinsicHistogram(id, rs);
+        si.setIncSupp(mUseIncSupp);
+        return si;
+    }
+
+    /**
+     * Process an input buffer and place the histogram into the
+     * output allocation. The output allocation may be a narrower
+     * vector size than the input. In this case the vector size of
+     * the output is used to determine how many of the input
+     * channels are used in the computation. This is useful if you
+     * have an RGBA input buffer but only want the histogram for
+     * RGB.
+     *
+     * 1D and 2D input allocations are supported.
+     *
+     * @param ain The input image
+     */
+    public void forEach(Allocation ain) {
+        forEach(ain, null);
+    }
+
+    /**
+     * Process an input buffer and place the histogram into the
+     * output allocation. The output allocation may be a narrower
+     * vector size than the input. In this case the vector size of
+     * the output is used to determine how many of the input
+     * channels are used in the computation. This is useful if you
+     * have an RGBA input buffer but only want the histogram for
+     * RGB.
+     *
+     * 1D and 2D input allocations are supported.
+     *
+     * @param ain The input image
+     * @param opt LaunchOptions for clipping
+     */
+    public void forEach(Allocation ain, Script.LaunchOptions opt) {
+        if (ain.getType().getElement().getVectorSize() <
+            mOut.getType().getElement().getVectorSize()) {
+
+            throw new RSIllegalArgumentException(
+                "Input vector size must be >= output vector size.");
+        }
+        if (mOut.getType().getElement().getVectorSize() == 3) {
+            throw new RSIllegalArgumentException(
+                "Output vector size should not be 3 for Input vector size 4.");
+        }
+        if (!ain.getType().getElement().isCompatible(Element.U8(mRS)) &&
+            !ain.getType().getElement().isCompatible(Element.U8_4(mRS))) {
+            throw new RSIllegalArgumentException("Output type must be U8 or U8_4.");
+        }
+
+        forEach(0, ain, null, null, opt);
+    }
+
+
+
+    /**
+     * Set the coefficients used for the RGBA to Luminocity
+     * calculation. The default is {0.299f, 0.587f, 0.114f, 0.f}.
+     *
+     * Coefficients must be >= 0 and sum to 1.0 or less.
+     *
+     * @param r Red coefficient
+     * @param g Green coefficient
+     * @param b Blue coefficient
+     * @param a Alpha coefficient
+     */
+    public void setDotCoefficients(float r, float g, float b, float a) {
+        if ((r < 0.f) || (g < 0.f) || (b < 0.f) || (a < 0.f)) {
+            throw new RSIllegalArgumentException("Coefficient may not be negative.");
+        }
+        if ((r + g + b + a) > 1.f) {
+            throw new RSIllegalArgumentException("Sum of coefficients must be 1.0 or less.");
+        }
+
+        FieldPacker fp = new FieldPacker(16);
+        fp.addF32(r);
+        fp.addF32(g);
+        fp.addF32(b);
+        fp.addF32(a);
+        setVar(0, fp);
+    }
+
+    /**
+     * Set the output of the histogram.  32 bit integer types are
+     * supported.
+     *
+     * @param aout The output allocation
+     */
+    public void setOutput(Allocation aout) {
+        mOut = aout;
+        if (mOut.getType().getElement() != Element.U32(mRS) &&
+            mOut.getType().getElement() != Element.U32_2(mRS) &&
+            mOut.getType().getElement() != Element.U32_3(mRS) &&
+            mOut.getType().getElement() != Element.U32_4(mRS) &&
+            mOut.getType().getElement() != Element.I32(mRS) &&
+            mOut.getType().getElement() != Element.I32_2(mRS) &&
+            mOut.getType().getElement() != Element.I32_3(mRS) &&
+            mOut.getType().getElement() != Element.I32_4(mRS)) {
+
+            throw new RSIllegalArgumentException("Output type must be U32 or I32.");
+        }
+        if ((mOut.getType().getX() != 256) ||
+            (mOut.getType().getY() != 0) ||
+            mOut.getType().hasMipmaps() ||
+            (mOut.getType().getYuv() != 0)) {
+
+            throw new RSIllegalArgumentException("Output must be 1D, 256 elements.");
+        }
+        setVar(1, aout);
+    }
+
+
+    /**
+     * Process an input buffer and place the histogram into the
+     * output allocation. The dot product of the input channel and
+     * the coefficients from 'setDotCoefficients' are used to
+     * calculate the output values.
+     *
+     * 1D and 2D input allocations are supported.
+     *
+     * @param ain The input image
+     */
+    public void forEach_Dot(Allocation ain) {
+        forEach_Dot(ain, null);
+    }
+
+    /**
+     * Process an input buffer and place the histogram into the
+     * output allocation. The dot product of the input channel and
+     * the coefficients from 'setDotCoefficients' are used to
+     * calculate the output values.
+     *
+     * 1D and 2D input allocations are supported.
+     *
+     * @param ain The input image
+     * @param opt LaunchOptions for clipping
+     */
+    public void forEach_Dot(Allocation ain, Script.LaunchOptions opt) {
+        if (mOut.getType().getElement().getVectorSize() != 1) {
+            throw new RSIllegalArgumentException("Output vector size must be one.");
+        }
+        if (!ain.getType().getElement().isCompatible(Element.U8(mRS)) &&
+            !ain.getType().getElement().isCompatible(Element.U8_4(mRS))) {
+            throw new RSIllegalArgumentException("Output type must be U8 or U8_4.");
+        }
+
+        forEach(1, ain, null, null, opt);
+    }
+
+
+
+    /**
+     * Get a KernelID for this intrinsic kernel.
+     *
+     * @return Script.KernelID The KernelID object.
+     */
+    public Script.KernelID getKernelID_Separate() {
+        return createKernelID(0, 3, null, null);
+    }
+
+    /**
+     * Get a FieldID for the input field of this intrinsic.
+     *
+     * @return Script.FieldID The FieldID object.
+     */
+    public Script.FieldID getFieldID_Input() {
+        return createFieldID(1, null);
+    }
+}
+
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicLUT.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicLUT.java
index 22f75ce..0b905ba 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicLUT.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicLUT.java
@@ -29,6 +29,8 @@
     private Allocation mTables;
     private final byte mCache[] = new byte[1024];
     private boolean mDirty = true;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     protected ScriptIntrinsicLUT(long id, RenderScript rs) {
         super(id, rs);
@@ -45,9 +47,14 @@
      * @return ScriptIntrinsicLUT
      */
     public static ScriptIntrinsicLUT create(RenderScript rs, Element e) {
-        long id = rs.nScriptIntrinsicCreate(3, e.getID(rs));
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(3, e.getID(rs), mUseIncSupp);
 
         ScriptIntrinsicLUT si = new ScriptIntrinsicLUT(id, rs);
+        si.setIncSupp(mUseIncSupp);
         si.mTables = Allocation.createSized(rs, Element.U8(rs), 1024);
         for (int ct=0; ct < 256; ct++) {
             si.mCache[ct] = (byte)ct;
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicResize.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicResize.java
new file mode 100644
index 0000000..2fdf23e
--- /dev/null
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicResize.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.support.v8.renderscript;
+
+import android.util.Log;
+
+/**
+ * Intrinsic for performing a resize of a 2D allocation.
+ */
+public class ScriptIntrinsicResize extends ScriptIntrinsic {
+    private Allocation mInput;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 21;
+
+    protected ScriptIntrinsicResize(long id, RenderScript rs) {
+        super(id, rs);
+    }
+
+    /**
+     * Supported elements types are {@link Element#U8}, {@link
+     * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}
+     * {@link Element#F32}, {@link Element#F32_2}, {@link
+     * Element#F32_3}, {@link Element#F32_4}
+     *
+     * @param rs The RenderScript context
+     *
+     * @return ScriptIntrinsicResize
+     */
+    public static ScriptIntrinsicResize create(RenderScript rs) {
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(12, 0, mUseIncSupp);
+
+        ScriptIntrinsicResize si = new ScriptIntrinsicResize(id, rs);
+        si.setIncSupp(mUseIncSupp);
+        return si;
+
+    }
+
+    /**
+     * Set the input of the resize.
+     * Must match the element type supplied during create.
+     *
+     * @param ain The input allocation.
+     */
+    public void setInput(Allocation ain) {
+        Element e = ain.getElement();
+        if (!e.isCompatible(Element.U8(mRS)) &&
+            !e.isCompatible(Element.U8_2(mRS)) &&
+            !e.isCompatible(Element.U8_3(mRS)) &&
+            !e.isCompatible(Element.U8_4(mRS)) &&
+            !e.isCompatible(Element.F32(mRS)) &&
+            !e.isCompatible(Element.F32_2(mRS)) &&
+            !e.isCompatible(Element.F32_3(mRS)) &&
+            !e.isCompatible(Element.F32_4(mRS))) {
+            throw new RSIllegalArgumentException("Unsuported element type.");
+        }
+
+        mInput = ain;
+        setVar(0, ain);
+    }
+
+    /**
+     * Get a FieldID for the input field of this intrinsic.
+     *
+     * @return Script.FieldID The FieldID object.
+     */
+    public Script.FieldID getFieldID_Input() {
+        return createFieldID(0, null);
+    }
+
+
+    /**
+     * Resize copy the input allocation to the output specified. The
+     * Allocation is rescaled if necessary using bi-cubic
+     * interpolation.
+     *
+     * @param aout Output allocation. Element type must match
+     *             current input.  Must not be same as input.
+     */
+    public void forEach_bicubic(Allocation aout) {
+        if (aout == mInput) {
+            throw new RSIllegalArgumentException("Output cannot be same as Input.");
+        }
+        forEach_bicubic(aout, null);
+    }
+
+    /**
+     * Resize copy the input allocation to the output specified. The
+     * Allocation is rescaled if necessary using bi-cubic
+     * interpolation.
+     *
+     * @param aout Output allocation. Element type must match
+     *             current input.
+     * @param opt LaunchOptions for clipping
+     */
+    public void forEach_bicubic(Allocation aout, Script.LaunchOptions opt) {
+        forEach(0, (Allocation) null, aout, null, opt);
+    }
+
+    /**
+     * Get a KernelID for this intrinsic kernel.
+     *
+     * @return Script.KernelID The KernelID object.
+     */
+    public Script.KernelID getKernelID_bicubic() {
+        return createKernelID(0, 2, null, null);
+    }
+
+
+}
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicYuvToRGB.java b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicYuvToRGB.java
index 1e1fae2..f3d0df7 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicYuvToRGB.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/ScriptIntrinsicYuvToRGB.java
@@ -26,6 +26,8 @@
  */
 public class ScriptIntrinsicYuvToRGB extends ScriptIntrinsic {
     private Allocation mInput;
+    // API level for the intrinsic
+    private static final int INTRINSIC_API_LEVEL = 19;
 
     ScriptIntrinsicYuvToRGB(long id, RenderScript rs) {
         super(id, rs);
@@ -43,8 +45,14 @@
      */
     public static ScriptIntrinsicYuvToRGB create(RenderScript rs, Element e) {
         // 6 comes from RS_SCRIPT_INTRINSIC_YUV_TO_RGB in rsDefines.h
-        long id = rs.nScriptIntrinsicCreate(6, e.getID(rs));
+        long id;
+        boolean mUseIncSupp = rs.isUseNative() &&
+                              android.os.Build.VERSION.SDK_INT < INTRINSIC_API_LEVEL;
+
+        id = rs.nScriptIntrinsicCreate(6, e.getID(rs), mUseIncSupp);
+
         ScriptIntrinsicYuvToRGB si = new ScriptIntrinsicYuvToRGB(id, rs);
+        si.setIncSupp(mUseIncSupp);
         return si;
     }
 
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/Type.java b/v8/renderscript/java/src/android/support/v8/renderscript/Type.java
index 556b189..94ff06f 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/Type.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/Type.java
@@ -191,6 +191,14 @@
         super(id, rs);
     }
 
+    /*
+     * Get an identical dummy Type for Compat Context
+     *
+     */
+    public long getDummyType(RenderScript mRS, long eid) {
+        return mRS.nIncTypeCreate(eid, mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces, mDimYuv);
+    }
+
     /**
      * Builder class for Type.
      *
diff --git a/v8/renderscript/jni/android_renderscript_RenderScript.cpp b/v8/renderscript/jni/android_renderscript_RenderScript.cpp
index 476a133..7b97a85 100644
--- a/v8/renderscript/jni/android_renderscript_RenderScript.cpp
+++ b/v8/renderscript/jni/android_renderscript_RenderScript.cpp
@@ -266,6 +266,8 @@
 
 // ---------------------------------------------------------------------------
 static dispatchTable dispatchTab;
+// Incremental Support lib
+static dispatchTable dispatchTabInc;
 
 static jboolean nLoadSO(JNIEnv *_env, jobject _this, jboolean useNative) {
     void* handle = NULL;
@@ -501,9 +503,9 @@
     size_t receiveLen;
     uint32_t subID;
     int id = dispatchTab.ContextGetMessage((RsContext)con,
-                                 buf, sizeof(buf),
-                                 &receiveLen, sizeof(receiveLen),
-                                 &subID, sizeof(subID));
+                                           buf, sizeof(buf),
+                                           &receiveLen, sizeof(receiveLen),
+                                           &subID, sizeof(subID));
     if (!id && receiveLen) {
         //        __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,
         //            "message receive buffer too small.  %zu", receiveLen);
@@ -520,9 +522,9 @@
     size_t receiveLen;
     uint32_t subID;
     int id = dispatchTab.ContextGetMessage((RsContext)con,
-                                 ptr, len * 4,
-                                 &receiveLen, sizeof(receiveLen),
-                                 &subID, sizeof(subID));
+                                           ptr, len * 4,
+                                           &receiveLen, sizeof(receiveLen),
+                                           &subID, sizeof(subID));
     if (!id && receiveLen) {
         //        __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,
         //            "message receive buffer too small.  %zu", receiveLen);
@@ -611,10 +613,10 @@
     const char **nameArray = names.c_str();
     size_t *sizeArray = names.c_str_len();
 
-    jlong id = (jlong)(uintptr_t)dispatchTab.ElementCreate2((RsContext)con,
-                                     (RsElement *)ids, fieldCount,
-                                     nameArray, fieldCount * sizeof(size_t),  sizeArray,
-                                     (const uint32_t *)arraySizes, fieldCount);
+    jlong id = (jlong)(uintptr_t)dispatchTab.ElementCreate2((RsContext)con, (RsElement *)ids,
+                                                            fieldCount, nameArray,
+                                                            fieldCount * sizeof(size_t),  sizeArray,
+                                                            (const uint32_t *)arraySizes, fieldCount);
 
     free(ids);
     free(arraySizes);
@@ -1028,81 +1030,114 @@
 // -----------------------------------
 
 static void
-nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
+nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot, jboolean mUseInc)
 {
     LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)",
             (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
-    dispatchTab.ScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
+    if (mUseInc) {
+        dispatchTabInc.ScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
+    } else {
+        dispatchTab.ScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
+    }
 }
 
 static void
-nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
+nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con,
             (void *)script, slot, val);
-    dispatchTab.ScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
+    } else {
+        dispatchTab.ScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
+    }
 }
 
 static void
-nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
+nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con,
             (void *)script, slot, val);
-    dispatchTab.ScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
+    } else {
+        dispatchTab.ScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
+    }
 }
 
 static void
-nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
+nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con,
             (void *)script, slot, val);
-    dispatchTab.ScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
+    } else {
+        dispatchTab.ScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
+    }
 }
 
 static void
-nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
+nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con,
             (void *)script, slot, val);
-    dispatchTab.ScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
+    } else {
+        dispatchTab.ScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
+    }
 }
 
 static void
-nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
+nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con,
             (void *)script, slot, val);
-    dispatchTab.ScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
+    } else { 
+        dispatchTab.ScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
+    }
 }
 
 static void
-nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
+nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
     jint len = _env->GetArrayLength(data);
     jbyte *ptr = _env->GetByteArrayElements(data, NULL);
-    dispatchTab.ScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
+    } else {
+        dispatchTab.ScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
+    }
     _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
 }
 
 static void
 nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
-                jlong elem, jintArray dims)
+                jlong elem, jintArray dims, jboolean mUseInc)
 {
     LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
     jint len = _env->GetArrayLength(data);
     jbyte *ptr = _env->GetByteArrayElements(data, NULL);
     jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
     jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
-    dispatchTab.ScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
-                     (const uint32_t *)dimsPtr, dimsLen);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
+                                      (const uint32_t *)dimsPtr, dimsLen);
+    } else {
+        dispatchTab.ScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
+                                   (const uint32_t *)dimsPtr, dimsLen);
+    }
     _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
     _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
 }
 
 
 static void
-nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
+nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone, jboolean mUseInc)
 {
     LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", (RsContext)con,
             (void *)script, (const char *)timeZone);
@@ -1110,8 +1145,11 @@
     jint length = _env->GetArrayLength(timeZone);
     jbyte* timeZone_ptr;
     timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
-
-    dispatchTab.ScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
+    if (mUseInc) {
+        dispatchTabInc.ScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
+    } else {
+        dispatchTab.ScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
+    }
 
     if (timeZone_ptr) {
         _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
@@ -1119,49 +1157,71 @@
 }
 
 static void
-nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
+nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot, jboolean mUseInc)
 {
     LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
-    dispatchTab.ScriptInvoke((RsContext)con, (RsScript)obj, slot);
+    if (mUseInc) {
+        dispatchTabInc.ScriptInvoke((RsContext)con, (RsScript)obj, slot);
+    } else {
+        dispatchTab.ScriptInvoke((RsContext)con, (RsScript)obj, slot);
+    }
 }
 
 static void
-nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
+nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jboolean mUseInc)
 {
     LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
     jint len = _env->GetArrayLength(data);
     jbyte *ptr = _env->GetByteArrayElements(data, NULL);
-    dispatchTab.ScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
+    if (mUseInc) {
+        dispatchTabInc.ScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
+    } else {
+        dispatchTab.ScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
+    }
     _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
 }
 
 static void
-nScriptForEach(JNIEnv *_env, jobject _this, jlong con,
-               jlong script, jint slot, jlong ain, jlong aout)
+nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong incCon,
+               jlong script, jint slot, jlong ain, jlong aout, jboolean mUseInc)
 {
     LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
-    dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
-                              (RsAllocation)ain, (RsAllocation)aout,
-                              NULL, 0, NULL, 0);
+    if (mUseInc) {
+        dispatchTab.ContextFinish((RsContext)con);
+        dispatchTabInc.ScriptForEach((RsContext)incCon, (RsScript)script, slot,
+                                     (RsAllocation)ain, (RsAllocation)aout,
+                                     NULL, 0, NULL, 0);
+    } else {
+        dispatchTab.ScriptForEach((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)
+nScriptForEachV(JNIEnv *_env, jobject _this, jlong con, jlong incCon,
+                jlong script, jint slot, jlong ain, jlong aout, jbyteArray params, jboolean mUseInc)
 {
     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);
-    dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
-                              (RsAllocation)ain, (RsAllocation)aout,
-                              ptr, len, NULL, 0);
+    if (mUseInc) {
+        dispatchTab.ContextFinish((RsContext)con);
+        dispatchTabInc.ScriptForEach((RsContext)incCon, (RsScript)script, slot,
+                                     (RsAllocation)ain, (RsAllocation)aout,
+                                     ptr, len, NULL, 0);
+    } else {
+        dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
+                                  (RsAllocation)ain, (RsAllocation)aout,
+                                  ptr, len, NULL, 0);
+    }
     _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
 }
 
 static void
-nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con,
+nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con, jlong incCon,
                       jlong script, jint slot, jlong ain, jlong aout,
                       jint xstart, jint xend,
-                      jint ystart, jint yend, jint zstart, jint zend)
+                      jint ystart, jint yend, jint zstart, jint zend, jboolean mUseInc)
 {
     LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
     RsScriptCall sc;
@@ -1174,16 +1234,23 @@
     sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
     sc.arrayStart = 0;
     sc.arrayEnd = 0;
-    dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
-                              (RsAllocation)ain, (RsAllocation)aout,
-                              NULL, 0, &sc, sizeof(sc));
+    if (mUseInc) {
+        dispatchTab.ContextFinish((RsContext)con);
+        dispatchTabInc.ScriptForEach((RsContext)incCon, (RsScript)script, slot,
+                                     (RsAllocation)ain, (RsAllocation)aout,
+                                     NULL, 0, &sc, sizeof(sc));
+    } else {
+        dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
+                                  (RsAllocation)ain, (RsAllocation)aout,
+                                  NULL, 0, &sc, sizeof(sc));
+    }
 }
 
 static void
-nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con,
+nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con, jlong incCon,
                        jlong script, jint slot, jlong ain, jlong aout,
                        jbyteArray params, jint xstart, jint xend,
-                       jint ystart, jint yend, jint zstart, jint zend)
+                       jint ystart, jint yend, jint zstart, jint zend, jboolean mUseInc)
 {
     LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
     jint len = _env->GetArrayLength(params);
@@ -1198,9 +1265,16 @@
     sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
     sc.arrayStart = 0;
     sc.arrayEnd = 0;
-    dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
-                              (RsAllocation)ain, (RsAllocation)aout,
-                              ptr, len, &sc, sizeof(sc));
+    if (mUseInc) {
+        dispatchTab.ContextFinish((RsContext)con);
+        dispatchTabInc.ScriptForEach((RsContext)incCon, (RsScript)script, slot,
+                                     (RsAllocation)ain, (RsAllocation)aout,
+                                     ptr, len, &sc, sizeof(sc));
+    } else {
+        dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot,
+                                  (RsAllocation)ain, (RsAllocation)aout,
+                                  ptr, len, &sc, sizeof(sc));
+    }
     _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
 }
 
@@ -1256,19 +1330,28 @@
 }
 
 static jlong
-nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
+nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid, jboolean mUseInc)
 {
     LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid);
-    return (jlong)(uintptr_t)dispatchTab.ScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
+    if (mUseInc) {
+        return (jlong)(uintptr_t)dispatchTabInc.ScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
+    } else {
+        return (jlong)(uintptr_t)dispatchTab.ScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
+    }
 }
 
 static jlong
-nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
+nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig, jboolean mUseInc)
 {
     LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
             (void *)sid, slot, sig);
-    return (jlong)(uintptr_t)dispatchTab.ScriptKernelIDCreate((RsContext)con, (RsScript)sid,
-                                                                     slot, sig);
+    if (mUseInc) {
+        return (jlong)(uintptr_t)dispatchTabInc.ScriptKernelIDCreate((RsContext)con, (RsScript)sid,
+                                                                     slot, sig);    
+    } else {
+        return (jlong)(uintptr_t)dispatchTab.ScriptKernelIDCreate((RsContext)con, (RsScript)sid,
+                                                                  slot, sig);
+    }
 }
 
 static jlong
@@ -1280,10 +1363,14 @@
 }
 
 static jlong
-nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
+nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jboolean mUseInc)
 {
     LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot);
-    return (jlong)(uintptr_t)dispatchTab.ScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
+    if (mUseInc) {
+        return (jlong)(uintptr_t)dispatchTabInc.ScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
+    } else {
+        return (jlong)(uintptr_t)dispatchTab.ScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
+    }
 }
 
 static jlong
@@ -1393,6 +1480,116 @@
     return (jint)sizeof(void*);
 }
 
+// ---------------------------------------------------------------------------
+// For Incremental Intrinsic Support
+static bool nIncLoadSO() {
+    void* handle = NULL;
+    handle = dlopen("libRSSupport.so", RTLD_LAZY | RTLD_LOCAL);
+    if (handle == NULL) {
+        LOG_API("couldn't dlopen %s, %s", filename, dlerror());
+        return false;
+    }
+
+    if (loadSymbols(handle, dispatchTabInc) == false) {
+        LOG_API("%s init failed!", filename);
+        return false;
+    }
+    LOG_API("Successfully loaded %s", filename);
+    return true;
+}
+
+// -----------------------------------
+// To create/destroy a dummy context
+static void
+nIncObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
+{
+    LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
+    dispatchTabInc.ObjDestroy((RsContext)con, (void *)obj);
+}
+
+
+static jlong
+nIncDeviceCreate(JNIEnv *_env, jobject _this)
+{
+    LOG_API("nDeviceCreate");
+    return (jlong)(uintptr_t)dispatchTabInc.DeviceCreate();
+}
+
+static void
+nIncDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
+{
+    LOG_API("nDeviceDestroy");
+    return dispatchTabInc.DeviceDestroy((RsDevice)dev);
+}
+
+static jlong
+nIncContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
+{
+    LOG_API("nContextCreate");
+    //The compat context for incremental support will be synchronous.
+    return (jlong)(uintptr_t)dispatchTabInc.ContextCreate((RsDevice)dev, ver, sdkVer,
+                                                          (RsContextType)ct,
+                                                          RS_CONTEXT_SYNCHRONOUS);
+}
+
+static void
+nIncContextFinish(JNIEnv *_env, jobject _this, jlong con)
+{
+    LOG_API("nContextFinish, con(%p)", (RsContext)con);
+    dispatchTabInc.ContextFinish((RsContext)con);
+}
+
+static void
+nIncContextDestroy(JNIEnv *_env, jobject _this, jlong con)
+{
+    LOG_API("nContextDestroy, con(%p)", (RsContext)con);
+    dispatchTabInc.ContextDestroy((RsContext)con);
+}
+
+// -----------------------------------
+// Create dummy Element
+static jlong
+nIncElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size)
+{
+    LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con,
+            type, kind, norm, size);
+    return (jlong)(uintptr_t)dispatchTabInc.ElementCreate((RsContext)con, (RsDataType)type,
+                                                          (RsDataKind)kind, norm, size);
+}
+// -----------------------------------
+// Create dummy Type
+static jlong
+nIncTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
+            jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
+{
+    LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
+            incCon, eid, dimx, dimy, dimz, mips, faces, yuv);
+
+    return (jlong)(uintptr_t)dispatchTabInc.TypeCreate((RsContext)con, (RsElement)eid, dimx, dimy,
+                                                       dimz, mips, faces, yuv);
+}
+
+// -----------------------------------
+// Create Allocation from pointer
+static jlong
+nIncAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong incCon, jlong alloc, jlong type)
+{
+    LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
+            incCon, (RsElement)type, mips, usage, (void *)pointer);
+    size_t strideIn;
+    void* pIn = NULL;
+    RsAllocation ainI = NULL;
+    if (alloc != 0) {
+        pIn = dispatchTab.AllocationGetPointer((RsContext)con, (RsAllocation)alloc, 0,
+                                               RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 0, 0,
+                                               &strideIn, sizeof(size_t));
+        ainI = dispatchTabInc.AllocationCreateTyped((RsContext)incCon, (RsType)type,
+                                                    RS_ALLOCATION_MIPMAP_NONE,
+                                                    RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED,
+                                                    (uintptr_t)pIn);
+    }
+    return (jlong)(uintptr_t) ainI;
+}
 
 // ---------------------------------------------------------------------------
 
@@ -1457,27 +1654,27 @@
 {"rsnAllocationResize1D",            "(JJI)V",                                (void*)nAllocationResize1D },
 {"rsnAllocationGenerateMipmaps",     "(JJ)V",                                 (void*)nAllocationGenerateMipmaps },
 
-{"rsnScriptBindAllocation",          "(JJJI)V",                               (void*)nScriptBindAllocation },
-{"rsnScriptSetTimeZone",             "(JJ[B)V",                               (void*)nScriptSetTimeZone },
-{"rsnScriptInvoke",                  "(JJI)V",                                (void*)nScriptInvoke },
-{"rsnScriptInvokeV",                 "(JJI[B)V",                              (void*)nScriptInvokeV },
-{"rsnScriptForEach",                 "(JJIJJ)V",                              (void*)nScriptForEach },
-{"rsnScriptForEach",                 "(JJIJJ[B)V",                            (void*)nScriptForEachV },
-{"rsnScriptForEachClipped",          "(JJIJJIIIIII)V",                        (void*)nScriptForEachClipped },
-{"rsnScriptForEachClipped",          "(JJIJJ[BIIIIII)V",                      (void*)nScriptForEachClippedV },
-{"rsnScriptSetVarI",                 "(JJII)V",                               (void*)nScriptSetVarI },
-{"rsnScriptSetVarJ",                 "(JJIJ)V",                               (void*)nScriptSetVarJ },
-{"rsnScriptSetVarF",                 "(JJIF)V",                               (void*)nScriptSetVarF },
-{"rsnScriptSetVarD",                 "(JJID)V",                               (void*)nScriptSetVarD },
-{"rsnScriptSetVarV",                 "(JJI[B)V",                              (void*)nScriptSetVarV },
-{"rsnScriptSetVarVE",                "(JJI[BJ[I)V",                           (void*)nScriptSetVarVE },
-{"rsnScriptSetVarObj",               "(JJIJ)V",                               (void*)nScriptSetVarObj },
+{"rsnScriptBindAllocation",          "(JJJIZ)V",                              (void*)nScriptBindAllocation },
+{"rsnScriptSetTimeZone",             "(JJ[BZ)V",                              (void*)nScriptSetTimeZone },
+{"rsnScriptInvoke",                  "(JJIZ)V",                               (void*)nScriptInvoke },
+{"rsnScriptInvokeV",                 "(JJI[BZ)V",                             (void*)nScriptInvokeV },
+{"rsnScriptForEach",                 "(JJJIJJZ)V",                            (void*)nScriptForEach },
+{"rsnScriptForEach",                 "(JJJIJJ[BZ)V",                          (void*)nScriptForEachV },
+{"rsnScriptForEachClipped",          "(JJJIJJIIIIIIZ)V",                      (void*)nScriptForEachClipped },
+{"rsnScriptForEachClipped",          "(JJJIJJ[BIIIIIIZ)V",                    (void*)nScriptForEachClippedV },
+{"rsnScriptSetVarI",                 "(JJIIZ)V",                              (void*)nScriptSetVarI },
+{"rsnScriptSetVarJ",                 "(JJIJZ)V",                              (void*)nScriptSetVarJ },
+{"rsnScriptSetVarF",                 "(JJIFZ)V",                              (void*)nScriptSetVarF },
+{"rsnScriptSetVarD",                 "(JJIDZ)V",                              (void*)nScriptSetVarD },
+{"rsnScriptSetVarV",                 "(JJI[BZ)V",                             (void*)nScriptSetVarV },
+{"rsnScriptSetVarVE",                "(JJI[BJ[IZ)V",                          (void*)nScriptSetVarVE },
+{"rsnScriptSetVarObj",               "(JJIJZ)V",                              (void*)nScriptSetVarObj },
 
 {"rsnScriptCCreate",                 "(JLjava/lang/String;Ljava/lang/String;[BI)J",  (void*)nScriptCCreate },
-{"rsnScriptIntrinsicCreate",         "(JIJ)J",                                (void*)nScriptIntrinsicCreate },
-{"rsnScriptKernelIDCreate",          "(JJII)J",                               (void*)nScriptKernelIDCreate },
+{"rsnScriptIntrinsicCreate",         "(JIJZ)J",                               (void*)nScriptIntrinsicCreate },
+{"rsnScriptKernelIDCreate",          "(JJIIZ)J",                              (void*)nScriptKernelIDCreate },
 {"rsnScriptInvokeIDCreate",          "(JJI)J",                                (void*)nScriptInvokeIDCreate },
-{"rsnScriptFieldIDCreate",           "(JJI)J",                                (void*)nScriptFieldIDCreate },
+{"rsnScriptFieldIDCreate",           "(JJIZ)J",                               (void*)nScriptFieldIDCreate },
 {"rsnScriptGroupCreate",             "(J[J[J[J[J[J)J",                        (void*)nScriptGroupCreate },
 //{"rsnScriptGroup2Create",            "(J[J)J",                                (void*)nScriptGroup2Create },
 {"rsnScriptGroupSetInput",           "(JJJJ)V",                               (void*)nScriptGroupSetInput },
@@ -1487,6 +1684,18 @@
 {"rsnSamplerCreate",                 "(JIIIIIF)J",                            (void*)nSamplerCreate },
 
 {"rsnSystemGetPointerSize",          "()I",                                   (void*)nSystemGetPointerSize },
+
+// Entry points for Inc libRSSupport
+{"nIncLoadSO",                       "()Z",                                   (bool*)nIncLoadSO },
+{"nIncDeviceCreate",                 "()J",                                   (void*)nIncDeviceCreate },
+{"nIncDeviceDestroy",                "(J)V",                                  (void*)nIncDeviceDestroy },
+{"rsnIncContextCreate",              "(JIII)J",                               (void*)nIncContextCreate },
+{"rsnIncContextFinish",              "(J)V",                                  (void*)nIncContextFinish },
+{"rsnIncContextDestroy",             "(J)V",                                  (void*)nIncContextDestroy },
+{"rsnIncObjDestroy",                 "(JJ)V",                                 (void*)nIncObjDestroy },
+{"rsnIncElementCreate",              "(JJIZI)J",                              (void*)nIncElementCreate },
+{"rsnIncTypeCreate",                 "(JJIIIZZI)J",                           (void*)nIncTypeCreate },
+{"rsnIncAllocationCreateTyped",      "(JJJJ)J",                               (void*)nIncAllocationCreateTyped },
 };
 
 // ---------------------------------------------------------------------------