Loading libs/rs/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,7 @@ LOCAL_SHARED_LIBRARIES := \ libnativehelper \ libRS \ libcutils \ libsgl \ libutils \ libui Loading libs/rs/RenderScript.h +8 −8 Original line number Diff line number Diff line Loading @@ -86,14 +86,14 @@ enum RsElementPredefined { 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_INDEX_16, 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, //13 RS_ELEMENT_INDEX_32, RS_ELEMENT_XY_F32, RS_ELEMENT_XYZ_F32, Loading libs/rs/java/Fountain/res/raw/fountain.c +4 −4 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ main(con, ft, launchID) { 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; Loading Loading @@ -69,7 +69,7 @@ main(con, ft, launchID) { 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); Loading @@ -87,14 +87,14 @@ main(con, ft, launchID) { 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); Loading libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java +15 −52 Original line number Diff line number Diff line Loading @@ -83,9 +83,8 @@ public class RenderScript { 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); Loading Loading @@ -192,19 +191,17 @@ public class RenderScript { A_8 (7), RGB_565 (8), RGB_888 (12), RGBA_5551 (9), RGBA_4444 (10), RGB_888 (11), RGBA_8888 (12), 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); RGBA_8888 (13), 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) { Loading Loading @@ -475,41 +472,7 @@ public class RenderScript { } 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); } Loading libs/rs/jni/RenderScript_jni.cpp +45 −11 Original line number Diff line number Diff line Loading @@ -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" Loading @@ -48,12 +50,15 @@ static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) 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"); } Loading Loading @@ -218,19 +223,48 @@ nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip) rsAllocationUploadToTexture((RsAllocation)a, mip); } static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg) { 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; 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 w, jint h, jint dstFmt, jint srcFmt, jboolean genMips, jintArray data) nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) { 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); SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); jint *ptr = _env->GetIntArrayElements(data, NULL); jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, (RsElementPredefined)srcFmt, genMips, ptr); _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 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 Loading Loading @@ -795,7 +829,7 @@ static JNINativeMethod methods[] = { {"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 }, Loading Loading
libs/rs/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,7 @@ LOCAL_SHARED_LIBRARIES := \ libnativehelper \ libRS \ libcutils \ libsgl \ libutils \ libui Loading
libs/rs/RenderScript.h +8 −8 Original line number Diff line number Diff line Loading @@ -86,14 +86,14 @@ enum RsElementPredefined { 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_INDEX_16, 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, //13 RS_ELEMENT_INDEX_32, RS_ELEMENT_XY_F32, RS_ELEMENT_XYZ_F32, Loading
libs/rs/java/Fountain/res/raw/fountain.c +4 −4 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ main(con, ft, launchID) { 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; Loading Loading @@ -69,7 +69,7 @@ main(con, ft, launchID) { 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); Loading @@ -87,14 +87,14 @@ main(con, ft, launchID) { 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); Loading
libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java +15 −52 Original line number Diff line number Diff line Loading @@ -83,9 +83,8 @@ public class RenderScript { 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); Loading Loading @@ -192,19 +191,17 @@ public class RenderScript { A_8 (7), RGB_565 (8), RGB_888 (12), RGBA_5551 (9), RGBA_4444 (10), RGB_888 (11), RGBA_8888 (12), 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); RGBA_8888 (13), 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) { Loading Loading @@ -475,41 +472,7 @@ public class RenderScript { } 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); } Loading
libs/rs/jni/RenderScript_jni.cpp +45 −11 Original line number Diff line number Diff line Loading @@ -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" Loading @@ -48,12 +50,15 @@ static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) 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"); } Loading Loading @@ -218,19 +223,48 @@ nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip) rsAllocationUploadToTexture((RsAllocation)a, mip); } static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg) { 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; 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 w, jint h, jint dstFmt, jint srcFmt, jboolean genMips, jintArray data) nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) { 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); SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); jint *ptr = _env->GetIntArrayElements(data, NULL); jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, (RsElementPredefined)srcFmt, genMips, ptr); _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 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 Loading Loading @@ -795,7 +829,7 @@ static JNINativeMethod methods[] = { {"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 }, Loading