Loading graphics/java/android/renderscript/Allocation.java +9 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,15 @@ public class Allocation extends BaseObj { mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d); } public void readData(int[] d) { mRS.nAllocationRead(mID, d); } public void readData(float[] d) { mRS.nAllocationRead(mID, d); } public class Adapter1D extends BaseObj { Adapter1D(int id, RenderScript rs) { super(rs); Loading graphics/java/android/renderscript/RenderScript.java +6 −0 Original line number Diff line number Diff line Loading @@ -100,6 +100,8 @@ public class RenderScript { native void nAllocationSubData1D(int id, int off, int count, float[] d); native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d); native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); native void nAllocationRead(int id, int[] d); native void nAllocationRead(int id, float[] d); native void nTriangleMeshDestroy(int id); native void nTriangleMeshBegin(int vertex, int index); Loading Loading @@ -187,6 +189,10 @@ public class RenderScript { native void nSimpleMeshBindVertex(int id, int alloc, int slot); native void nSimpleMeshBindIndex(int id, int alloc); native void nAnimationDestroy(int id); native void nAnimationBegin(int attribCount, int keyframeCount); native void nAnimationAdd(float time, float[] attribs); native int nAnimationCreate(); private int mDev; private int mContext; Loading graphics/jni/android_renderscript_RenderScript.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -389,6 +389,27 @@ nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); } static void nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); jint len = _env->GetArrayLength(data); LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); jint *ptr = _env->GetIntArrayElements(data, NULL); rsAllocationData((RsAllocation)alloc, ptr); _env->ReleaseIntArrayElements(data, ptr, JNI_COMMIT); } static void nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); jint len = _env->GetArrayLength(data); LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); jfloat *ptr = _env->GetFloatArrayElements(data, NULL); rsAllocationData((RsAllocation)alloc, ptr); _env->ReleaseFloatArrayElements(data, ptr, JNI_COMMIT); } // ----------------------------------- Loading Loading @@ -1197,6 +1218,8 @@ static JNINativeMethod methods[] = { {"nAllocationSubData1D", "(III[F)V", (void*)nAllocationSubData1D_f }, {"nAllocationSubData2D", "(IIIII[I)V", (void*)nAllocationSubData2D_i }, {"nAllocationSubData2D", "(IIIII[F)V", (void*)nAllocationSubData2D_f }, {"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i }, {"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f }, {"nTriangleMeshDestroy", "(I)V", (void*)nTriangleMeshDestroy }, {"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin }, Loading libs/rs/java/Fountain/res/raw/fountain.c +7 −15 Original line number Diff line number Diff line Loading @@ -7,8 +7,7 @@ int main(int launchID) { int count, touch, x, y, rate, maxLife, lifeShift; int life; int count, touch, x, y, rate; int ct, ct2; int newPart; int drawCount; Loading @@ -25,15 +24,7 @@ int main(int launchID) { y = loadI32(0, 4); rate = 4; maxLife = (count / rate) - 1; lifeShift = 0; { life = maxLife; while (life > 255) { life = life >> 1; lifeShift ++; } } int maxLife = (count / rate) - 1; if (touch) { newPart = loadI32(2, 0); Loading @@ -57,19 +48,20 @@ int main(int launchID) { } drawCount = 0; float height = getHeight(); for (ct=0; ct < count; ct++) { srcIdx = ct * 5 + 1; dx = loadF(2, srcIdx); dy = loadF(2, srcIdx + 1); life = loadI32(2, srcIdx + 2); int life = loadI32(2, srcIdx + 2); posx = loadF(2, srcIdx + 3); posy = loadF(2, srcIdx + 4); if (life) { if (posy < 480.f) { if (posy < height) { dstIdx = drawCount * 9; c = 0xffafcf | ((life >> lifeShift) << 24); c = 0xcfcfcfcf; storeI32(1, dstIdx, c); storeF(1, dstIdx + 1, posx); Loading @@ -91,7 +83,7 @@ int main(int launchID) { posx = posx + dx; posy = posy + dy; dy = dy + 0.1f; dy = dy + 0.05f; life --; //storeI32(2, srcIdx, dx); Loading libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +6 −5 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.renderscript.Primitive; public class FountainRS { public static final int PART_COUNT = 4000; public FountainRS() { } Loading Loading @@ -75,10 +76,8 @@ public class FountainRS { int mParams[] = new int[10]; private void initRS() { int partCount = 1024; mIntAlloc = Allocation.createSized(mRS, Element.USER_I32, 10); mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, partCount * 5 + 1); mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, PART_COUNT * 5 + 1); ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE); Loading @@ -93,10 +92,12 @@ public class FountainRS { mPF.setName("PgmFragParts"); mParams[0] = 0; mParams[1] = partCount; mParams[1] = PART_COUNT; mParams[2] = 0; mParams[3] = 0; mParams[4] = 0; mParams[5] = 0; mParams[6] = 0; mIntAlloc.data(mParams); Element.Builder eb = new Element.Builder(mRS); Loading @@ -109,7 +110,7 @@ public class FountainRS { Element primElement = eb.create(); SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS); int vtxSlot = smb.addVertexType(primElement, partCount * 3); int vtxSlot = smb.addVertexType(primElement, PART_COUNT * 3); smb.setPrimitive(Primitive.TRIANGLE); mSM = smb.create(); mSM.setName("PartMesh"); Loading Loading
graphics/java/android/renderscript/Allocation.java +9 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,15 @@ public class Allocation extends BaseObj { mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d); } public void readData(int[] d) { mRS.nAllocationRead(mID, d); } public void readData(float[] d) { mRS.nAllocationRead(mID, d); } public class Adapter1D extends BaseObj { Adapter1D(int id, RenderScript rs) { super(rs); Loading
graphics/java/android/renderscript/RenderScript.java +6 −0 Original line number Diff line number Diff line Loading @@ -100,6 +100,8 @@ public class RenderScript { native void nAllocationSubData1D(int id, int off, int count, float[] d); native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d); native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); native void nAllocationRead(int id, int[] d); native void nAllocationRead(int id, float[] d); native void nTriangleMeshDestroy(int id); native void nTriangleMeshBegin(int vertex, int index); Loading Loading @@ -187,6 +189,10 @@ public class RenderScript { native void nSimpleMeshBindVertex(int id, int alloc, int slot); native void nSimpleMeshBindIndex(int id, int alloc); native void nAnimationDestroy(int id); native void nAnimationBegin(int attribCount, int keyframeCount); native void nAnimationAdd(float time, float[] attribs); native int nAnimationCreate(); private int mDev; private int mContext; Loading
graphics/jni/android_renderscript_RenderScript.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -389,6 +389,27 @@ nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); } static void nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); jint len = _env->GetArrayLength(data); LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); jint *ptr = _env->GetIntArrayElements(data, NULL); rsAllocationData((RsAllocation)alloc, ptr); _env->ReleaseIntArrayElements(data, ptr, JNI_COMMIT); } static void nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); jint len = _env->GetArrayLength(data); LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); jfloat *ptr = _env->GetFloatArrayElements(data, NULL); rsAllocationData((RsAllocation)alloc, ptr); _env->ReleaseFloatArrayElements(data, ptr, JNI_COMMIT); } // ----------------------------------- Loading Loading @@ -1197,6 +1218,8 @@ static JNINativeMethod methods[] = { {"nAllocationSubData1D", "(III[F)V", (void*)nAllocationSubData1D_f }, {"nAllocationSubData2D", "(IIIII[I)V", (void*)nAllocationSubData2D_i }, {"nAllocationSubData2D", "(IIIII[F)V", (void*)nAllocationSubData2D_f }, {"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i }, {"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f }, {"nTriangleMeshDestroy", "(I)V", (void*)nTriangleMeshDestroy }, {"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin }, Loading
libs/rs/java/Fountain/res/raw/fountain.c +7 −15 Original line number Diff line number Diff line Loading @@ -7,8 +7,7 @@ int main(int launchID) { int count, touch, x, y, rate, maxLife, lifeShift; int life; int count, touch, x, y, rate; int ct, ct2; int newPart; int drawCount; Loading @@ -25,15 +24,7 @@ int main(int launchID) { y = loadI32(0, 4); rate = 4; maxLife = (count / rate) - 1; lifeShift = 0; { life = maxLife; while (life > 255) { life = life >> 1; lifeShift ++; } } int maxLife = (count / rate) - 1; if (touch) { newPart = loadI32(2, 0); Loading @@ -57,19 +48,20 @@ int main(int launchID) { } drawCount = 0; float height = getHeight(); for (ct=0; ct < count; ct++) { srcIdx = ct * 5 + 1; dx = loadF(2, srcIdx); dy = loadF(2, srcIdx + 1); life = loadI32(2, srcIdx + 2); int life = loadI32(2, srcIdx + 2); posx = loadF(2, srcIdx + 3); posy = loadF(2, srcIdx + 4); if (life) { if (posy < 480.f) { if (posy < height) { dstIdx = drawCount * 9; c = 0xffafcf | ((life >> lifeShift) << 24); c = 0xcfcfcfcf; storeI32(1, dstIdx, c); storeF(1, dstIdx + 1, posx); Loading @@ -91,7 +83,7 @@ int main(int launchID) { posx = posx + dx; posy = posy + dy; dy = dy + 0.1f; dy = dy + 0.05f; life --; //storeI32(2, srcIdx, dx); Loading
libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +6 −5 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.renderscript.Primitive; public class FountainRS { public static final int PART_COUNT = 4000; public FountainRS() { } Loading Loading @@ -75,10 +76,8 @@ public class FountainRS { int mParams[] = new int[10]; private void initRS() { int partCount = 1024; mIntAlloc = Allocation.createSized(mRS, Element.USER_I32, 10); mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, partCount * 5 + 1); mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, PART_COUNT * 5 + 1); ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE); Loading @@ -93,10 +92,12 @@ public class FountainRS { mPF.setName("PgmFragParts"); mParams[0] = 0; mParams[1] = partCount; mParams[1] = PART_COUNT; mParams[2] = 0; mParams[3] = 0; mParams[4] = 0; mParams[5] = 0; mParams[6] = 0; mIntAlloc.data(mParams); Element.Builder eb = new Element.Builder(mRS); Loading @@ -109,7 +110,7 @@ public class FountainRS { Element primElement = eb.create(); SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS); int vtxSlot = smb.addVertexType(primElement, partCount * 3); int vtxSlot = smb.addVertexType(primElement, PART_COUNT * 3); smb.setPrimitive(Primitive.TRIANGLE); mSM = smb.create(); mSM.setName("PartMesh"); Loading