Support defered generation of mipmaps.  With this change we support mipmap generation when the texture is uploaded to GL without requiring RS to retain the full chain.
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index e5cf38e..8185404 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -45,7 +45,12 @@
 
     public void uploadToTexture(int baseMipLevel) {
         mRS.validate();
-        mRS.nAllocationUploadToTexture(mID, baseMipLevel);
+        mRS.nAllocationUploadToTexture(mID, false, baseMipLevel);
+    }
+
+    public void uploadToTexture(boolean genMips, int baseMipLevel) {
+        mRS.validate();
+        mRS.nAllocationUploadToTexture(mID, genMips, baseMipLevel);
     }
 
     public void uploadToBufferObject() {
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 84b1a70..70c97ea 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -101,7 +101,7 @@
     native int  nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
     native int  nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);
 
-    native void nAllocationUploadToTexture(int alloc, int baseMioLevel);
+    native void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel);
     native void nAllocationUploadToBufferObject(int alloc);
 
     native void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 0ffdf71..cb5a00e 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -444,11 +444,11 @@
 }
 
 static void
-nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
+nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jboolean genMip, jint mip)
 {
     RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
-    rsAllocationUploadToTexture(con, (RsAllocation)a, mip);
+    LOG_API("nAllocationUploadToTexture, con(%p), a(%p), genMip(%i), mip(%i)", con, (RsAllocation)a, genMip, mip);
+    rsAllocationUploadToTexture(con, (RsAllocation)a, genMip, mip);
 }
 
 static void
@@ -1369,7 +1369,7 @@
 {"nAllocationCreateFromBitmap",    "(IZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
 {"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I",      (void*)nAllocationCreateFromBitmapBoxed },
 {"nAllocationCreateFromAssetStream","(IZI)I",                              (void*)nAllocationCreateFromAssetStream },
-{"nAllocationUploadToTexture",     "(II)V",                                (void*)nAllocationUploadToTexture },
+{"nAllocationUploadToTexture",     "(IZI)V",                               (void*)nAllocationUploadToTexture },
 {"nAllocationUploadToBufferObject","(I)V",                                 (void*)nAllocationUploadToBufferObject },
 {"nAllocationSubData1D",           "(III[II)V",                            (void*)nAllocationSubData1D_i },
 {"nAllocationSubData1D",           "(III[SI)V",                            (void*)nAllocationSubData1D_s },
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 10e5285..89d9d5e 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -113,6 +113,7 @@
 
 AllocationUploadToTexture {
 	param RsAllocation alloc
+	param bool genMipMaps
 	param uint32_t baseMipLevel
 	}
 
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 1ae2317..f1798de 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -17,6 +17,7 @@
 #include "rsContext.h"
 
 #include <GLES/gl.h>
+#include <GLES2/gl2.h>
 #include <GLES/glext.h>
 
 using namespace android;
@@ -88,12 +89,13 @@
     return false;
 }
 
-void Allocation::deferedUploadToTexture(const Context *rsc, uint32_t lodOffset)
+void Allocation::deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset)
 {
     rsAssert(lodOffset < mType->getLODCount());
     mIsTexture = true;
     mTextureLOD = lodOffset;
     mUploadDefered = true;
+    mTextureGenMipmap = !mType->getDimLOD() && genMipmap;
 }
 
 void Allocation::uploadToTexture(const Context *rsc)
@@ -138,6 +140,10 @@
                      adapt.getDimX(), adapt.getDimY(),
                      0, format, type, ptr);
     }
+    if (mTextureGenMipmap) {
+        glGenerateMipmap(GL_TEXTURE_2D);
+    }
+
 }
 
 void Allocation::deferedUploadToBufferObject(const Context *rsc)
@@ -316,10 +322,10 @@
     return rsi_AllocationCreateTyped(rsc, type);
 }
 
-void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, uint32_t baseMipLevel)
+void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel)
 {
     Allocation *alloc = static_cast<Allocation *>(va);
-    alloc->deferedUploadToTexture(rsc, baseMipLevel);
+    alloc->deferedUploadToTexture(rsc, genmip, baseMipLevel);
 }
 
 void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va)
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index f0b2122..778c904 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -46,7 +46,7 @@
     void * getPtr() const {return mPtr;}
     const Type * getType() const {return mType.get();}
 
-    void deferedUploadToTexture(const Context *rsc, uint32_t lodOffset);
+    void deferedUploadToTexture(const Context *rsc, bool genMipmap, uint32_t lodOffset);
     void uploadToTexture(const Context *rsc);
     uint32_t getTextureID() const {return mTextureID;}
 
@@ -98,6 +98,7 @@
     // Is this a legal structure to be used as a texture source.
     // Initially this will require 1D or 2D and color data
     bool mIsTexture;
+    bool mTextureGenMipmap;
     uint32_t mTextureLOD;
     uint32_t mTextureID;
 
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 6b8ed0d..235c153 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -975,7 +975,7 @@
 static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
 {
     GET_TLS();
-    rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
+    rsi_AllocationUploadToTexture(rsc, va, false, baseMipLevel);
 }
 
 static void SC_uploadToBufferObject(RsAllocation va)