Improve bitmap support and do conversion in native rather than java code to reduce conversion time.
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 6f72802..6ff39a4 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -117,6 +117,7 @@
 	libnativehelper \
 	libRS \
 	libcutils \
+    libsgl \
 	libutils \
 	libui
 
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 378fccc..2b33419 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -86,14 +86,14 @@
     RS_ELEMENT_USER_I32,
     RS_ELEMENT_USER_FLOAT, 
 
-    RS_ELEMENT_A_8, 
-    RS_ELEMENT_RGB_565, 
-    RS_ELEMENT_RGBA_5551, 
-    RS_ELEMENT_RGBA_4444, 
-    RS_ELEMENT_RGB_888, 
-    RS_ELEMENT_RGBA_8888, 
+    RS_ELEMENT_A_8,          // 7
+    RS_ELEMENT_RGB_565,      // 8
+    RS_ELEMENT_RGBA_5551,    // 9
+    RS_ELEMENT_RGBA_4444,    // 10
+    RS_ELEMENT_RGB_888,      // 11
+    RS_ELEMENT_RGBA_8888,    // 12
 
-    RS_ELEMENT_INDEX_16, 
+    RS_ELEMENT_INDEX_16, //13
     RS_ELEMENT_INDEX_32, 
     RS_ELEMENT_XY_F32, 
     RS_ELEMENT_XYZ_F32, 
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index 76f8dcf..cee6e22 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -15,7 +15,7 @@
     count = loadI32(con, 0, 1);
     touch = loadI32(con, 0, 2);
     x = loadI32(con, 0, 3);
-    y = 480 - loadI32(con, 0, 4);
+    y = loadI32(con, 0, 4);
 
     rate = 4;
     maxLife = (count / rate) - 1;
@@ -69,7 +69,7 @@
         posy = * (int* )(partPtr + 16); //loadEnvI32(con, 2, srcIdx + 4);
 
         if (life) {
-            if (posy > 0) {
+            if (posy < (480 << 16)) {
                 c = 0xffafcf | ((life >> lifeShift) << 24);
 
                 * (int* )(vertPtr) = c; //storeEnvU32(con, 1, dstIdx, c);
@@ -87,14 +87,14 @@
                 vertPtr = vertPtr + 36;
                 drawCount ++;
             } else {
-                if (dy < 0) {
+                if (dy > 0) {
                     dy = (-dy) >> 1;
                 }
             }
 
             posx = posx + dx;
             posy = posy + dy;
-            dy = dy - 0x400;
+            dy = dy + 0x400;
             life --;
 
             * (int* )(partPtr + 0) = dx; //storeEnvI32(con, 2, srcIdx, dx);
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java b/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java
index cf16cec..796fe35 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java
@@ -83,9 +83,8 @@
     native private int  nAllocationCreateTyped(int type);
     native private int  nAllocationCreatePredefSized(int predef, int count);
     native private int  nAllocationCreateSized(int elem, int count);
-    native private int  nAllocationCreateFromBitmap(int w, int h, int dstFmt, int srcFmt, boolean genMips, int[] data);
+    native private int  nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
 
-    //native private int  nAllocationCreateFromBitmap(type.mID);
     native private void nAllocationUploadToTexture(int alloc, int baseMioLevel);
     native private void nAllocationDestroy(int alloc);
     native private void nAllocationData(int id, int[] d);
@@ -190,21 +189,19 @@
         USER_I32 (5),
         USER_FLOAT (6),
 
-        A_8 (7),
-        RGB_565 (8),
-        RGBA_5551 (9),
-        RGBA_4444 (10),
-        RGB_888 (11),
-        RGBA_8888 (12),
+        A_8                (7),
+        RGB_565            (8),
+        RGB_888            (12),
+        RGBA_5551          (9),
+        RGBA_4444          (10),
+        RGBA_8888          (13),
 
-        INDEX_16 (13),
-        INDEX_32 (14),
-        XY_F32 (15),
-        XYZ_F32 (16),
-        ST_XY_F32 (17),
-        ST_XYZ_F32 (18),
-        NORM_XYZ_F32 (19),
-        NORM_ST_XYZ_F32 (20);
+        INDEX_16           (16),
+        INDEX_32           (17),
+        XY_F32             (18),
+        XYZ_F32            (19),
+        ST_XY_F32          (20),
+        ST_XYZ_F32         (21);
 
         int mID;
         ElementPredefined(int id) {
@@ -475,41 +472,7 @@
     }
 
     public Allocation allocationCreateFromBitmap(Bitmap b, ElementPredefined dstFmt, boolean genMips) {
-        int w = b.getWidth();
-        int h = b.getHeight();
-        int[] data = new int[w * h];
-
-        int outPtr = 0;
-        for(int y=0; y < h; y++) {
-            for(int x=0; x < w; x++) {
-                data[outPtr] = b.getPixel(x, y);
-                outPtr++;
-            }
-        }
-
-        int srcFmt = 0;
-        /*
-        switch(b.getConfig()) {
-        case ALPHA_8:
-            srcFmt = ElementPredefined.A_8.mID;
-            break;
-        case ARGB_4444:
-            srcFmt = ElementPredefined.RGBA_4444.mID;
-            break;
-        case ARGB_8888:
-            srcFmt = ElementPredefined.RGBA_8888.mID;
-            break;
-        case RGB_565:
-            srcFmt = ElementPredefined.RGB_565.mID;
-            break;
-        default:
-            Log.e(LOG_TAG, "allocationCreateFromBitmap, unknown bitmap format");
-        }
-        */
-
-        srcFmt = ElementPredefined.RGBA_8888.mID;
-
-        int id = nAllocationCreateFromBitmap(w, h, dstFmt.mID, srcFmt, genMips, data);
+        int id = nAllocationCreateFromBitmap(dstFmt.mID, genMips, b); 
         return new Allocation(id);
     }
 
diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp
index 4af58a6..61866b7 100644
--- a/libs/rs/jni/RenderScript_jni.cpp
+++ b/libs/rs/jni/RenderScript_jni.cpp
@@ -26,6 +26,8 @@
 #include <ui/EGLNativeWindowSurface.h>
 #include <ui/Surface.h>
 
+#include <core/SkBitmap.h>
+
 #include "jni.h"
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
@@ -48,12 +50,15 @@
     env->ThrowNew(npeClazz, msg);
 }
 
-static jfieldID gContextId;
+static jfieldID gContextId = 0;
+static jfieldID gNativeBitmapID = 0;
 
 static void _nInit(JNIEnv *_env, jclass _this)
 {
-    LOGE("_nInit");
     gContextId             = _env->GetFieldID(_this, "mContext", "I");
+
+    jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
+    gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
 }
 
 
@@ -218,19 +223,48 @@
     rsAllocationUploadToTexture((RsAllocation)a, mip);
 }
 
-static int
-nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint w, jint h, jint dstFmt, jint srcFmt, jboolean genMips, jintArray data)
+static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg)
 {
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    jint len = _env->GetArrayLength(data);
-    LOG_API("nAllocationCreateFromBitmap, con(%p), w(%i), h(%i), dstFmt(%i), srcFmt(%i), mip(%i), len(%i)", con, w, h, dstFmt, srcFmt, genMips, len);
+    switch (cfg) {
+    case SkBitmap::kA8_Config:
+        return RS_ELEMENT_A_8;
+    case SkBitmap::kARGB_4444_Config:
+        return RS_ELEMENT_RGBA_4444;
+    case SkBitmap::kARGB_8888_Config:
+        return RS_ELEMENT_RGBA_8888;
+    case SkBitmap::kRGB_565_Config:
+        return RS_ELEMENT_RGB_565;
 
-    jint *ptr = _env->GetIntArrayElements(data, NULL);
-    jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, (RsElementPredefined)srcFmt, genMips, ptr);
-    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
-    return id;
+    default:
+        break;
+    }
+    // If we don't have a conversion mark it as a user type.
+    LOGE("Unsupported bitmap type");
+    return RS_ELEMENT_USER_U8;
 }
 
+static int
+nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
+{
+    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+    SkBitmap const * nativeBitmap =
+            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+    const SkBitmap& bitmap(*nativeBitmap);
+    SkBitmap::Config config = bitmap.getConfig();
+
+    RsElementPredefined e = SkBitmapToPredefined(config);
+
+    if (e != RS_ELEMENT_USER_U8) {
+        bitmap.lockPixels();
+        const int w = bitmap.width();
+        const int h = bitmap.height();
+        const void* ptr = bitmap.getPixels();
+        jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
+        bitmap.unlockPixels();
+        return id;
+    }
+    return 0;
+}
 
 
 static void
@@ -795,7 +829,7 @@
 {"nAllocationCreateTyped",         "(I)I",                                 (void*)nAllocationCreateTyped },
 {"nAllocationCreatePredefSized",   "(II)I",                                (void*)nAllocationCreatePredefSized },
 {"nAllocationCreateSized",         "(II)I",                                (void*)nAllocationCreateSized },
-{"nAllocationCreateFromBitmap",    "(IIIIZ[I)I",                           (void*)nAllocationCreateFromBitmap },
+{"nAllocationCreateFromBitmap",    "(IZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
 {"nAllocationUploadToTexture",     "(II)V",                                (void*)nAllocationUploadToTexture },
 {"nAllocationDestroy",             "(I)V",                                 (void*)nAllocationDestroy },
 {"nAllocationData",                "(I[I)V",                               (void*)nAllocationData_i },
diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h
index 683c96e..f40e2ce 100644
--- a/libs/rs/rsUtils.h
+++ b/libs/rs/rsUtils.h
@@ -87,9 +87,9 @@
 static inline uint16_t rs888to565(uint32_t r, uint32_t g, uint32_t b)
 {
     uint16_t t = 0;
-    t |= r >> 3;
+    t |= b >> 3;
     t |= (g >> 2) << 5;
-    t |= (b >> 3) << 11;
+    t |= (r >> 3) << 11;
     return t;
 }