From 55d45223923bc55791e7174f5ea37694aa308e58 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Tue, 26 May 2009 18:58:04 -0700 Subject: [PATCH] Fix Fountain test app so that it actually builds. Also check in first part of an libACC implementation. --- libs/rs/Android.mk | 1 + libs/rs/java/Fountain/Android.mk | 2 +- libs/rs/java/Fountain/AndroidManifest.xml | 6 +- .../src/com/android/fountain/Fountain.java | 6 +- .../com/android/fountain/FountainView.java | 32 ++-- libs/rs/jni/RenderScript_jni.cpp | 141 ++++++++++++++++++ libs/rs/rsScriptC.cpp | 80 +++++----- 7 files changed, 205 insertions(+), 63 deletions(-) diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 108836fe3af20..7ae5709792f12 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -112,6 +112,7 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ + libacc \ libnativehelper \ libRS \ libcutils \ diff --git a/libs/rs/java/Fountain/Android.mk b/libs/rs/java/Fountain/Android.mk index 179009f8b88a8..cf084672431ea 100644 --- a/libs/rs/java/Fountain/Android.mk +++ b/libs/rs/java/Fountain/Android.mk @@ -19,7 +19,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-java-files-under, src) -LOCAL_PACKAGE_NAME := Calc +LOCAL_PACKAGE_NAME := Fountain include $(BUILD_PACKAGE) ################################################## diff --git a/libs/rs/java/Fountain/AndroidManifest.xml b/libs/rs/java/Fountain/AndroidManifest.xml index 8eee06635fb70..62b0b0d1780d3 100644 --- a/libs/rs/java/Fountain/AndroidManifest.xml +++ b/libs/rs/java/Fountain/AndroidManifest.xml @@ -1,8 +1,8 @@ - - + @@ -10,4 +10,4 @@ - + diff --git a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java index 94fdb8ebe4b57..ca0f02003ccc6 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java @@ -34,14 +34,14 @@ import android.widget.ListView; import java.lang.Runtime; -public class Calc extends Activity { +public class Fountain extends Activity { //EventListener mListener = new EventListener(); private static final String LOG_TAG = "libRS_jni"; private static final boolean DEBUG = false; private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; - private CalcView mView; + private FountainView mView; // get the current looper (from your Activity UI thread for instance @@ -53,7 +53,7 @@ public class Calc extends Activity { // Create our Preview view and set it as the content of our // Activity - mView = new CalcView(this); + mView = new FountainView(this); setContentView(mView); } diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java index ecde9101e9914..b6aa9f8bab1ba 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java @@ -28,12 +28,12 @@ import android.util.Log; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; -import android.view.KeyEvent; -import android.view.MotionEvent; +import android.view.KeyEvent; +import android.view.MotionEvent; -public class CalcView extends RSSurfaceView { +public class FountainView extends RSSurfaceView { - public CalcView(Context context) { + public FountainView(Context context) { super(context); //setFocusable(true); @@ -101,20 +101,20 @@ public class CalcView extends RSSurfaceView { initRS(); } - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) - { - // break point at here - // this method doesn't work when 'extends View' include 'extends ScrollView'. - return super.onKeyDown(keyCode, event); - } + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) + { + // break point at here + // this method doesn't work when 'extends View' include 'extends ScrollView'. + return super.onKeyDown(keyCode, event); + } int mTouchAction; - @Override - public boolean onTouchEvent(MotionEvent ev) - { - //Log.e("CalcView", ev.toString()); + @Override + public boolean onTouchEvent(MotionEvent ev) + { + //Log.e("FountainView", ev.toString()); boolean ret = true; int act = ev.getAction(); mParams[1] = (int)ev.getX(); @@ -129,7 +129,7 @@ public class CalcView extends RSSurfaceView { mIntAlloc.subData1D(2, 3, mParams); return ret; - } + } } diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp index 5b226a54be694..ce377fc46650c 100644 --- a/libs/rs/jni/RenderScript_jni.cpp +++ b/libs/rs/jni/RenderScript_jni.cpp @@ -33,6 +33,12 @@ #include "../RenderScript.h" #include "../RenderScriptEnv.h" +// #define USE_ACC + +#ifdef USE_ACC +#include "acc/acc.h" +#endif + //#define LOG_API LOGE #define LOG_API(...) @@ -40,6 +46,140 @@ using namespace android; extern "C" void test_script(void *con, const rsc_FunctionTable *ft, uint32_t launchID); +#ifdef USE_ACC +static const char* TEST_SCRIPT = "" + "// Fountain test script\n" + "\n" + "void main(con, ft, launchID) {\n" + " int count, touch, x, y, rate, maxLife, lifeShift;\n" + " int life;\n" + " int ct, ct2;\n" + " int newPart;\n" + " int drawCount;\n" + " int dx, dy, idx;\n" + " int partPtr;\n" + " int vertPtr;\n" + " int posx,posy;\n" + " int c;\n" + "\n" + " count = loadEnvI32(con, 0, 1);\n" + " touch = loadEnvI32(con, 0, 2);\n" + " x = loadEnvI32(ft, con, 0, 3);\n" + " y = 480 - loadEnvI32(con, 0, 4);\n" + "\n" + " rate = 4;\n" + " maxLife = (count / rate) - 1;\n" + " lifeShift = 0;\n" + " {\n" + " life = maxLife;\n" + " while (life > 255) {\n" + " life >>= 1;\n" + " lifeShift ++;\n" + " }\n" + " }\n" + "\n" + " if (touch) {\n" + " newPart = loadEnvI32(con, 2, 0);\n" + " for (ct2=0; ct2= count) {\n" + " newPart = 0;\n" + " }\n" + " }\n" + " storeEnvI32(con, 2, 0, newPart);\n" + " }\n" + "\n" + " // Emulate intrinsic perf...\n" + " partPtr = loadEnvVp(con, 2, 4);\n" + " vertPtr = loadEnvVp(con, 1, 0);\n" + "\n" + " drawCount = 0;\n" + " for (ct=0; ct < count; ct++) {\n" + " //int srcIdx = ct * 5 + 1;\n" + " //int dstIdx = ct * 3 * 3;\n" + "\n" + " dx = * (int* )(partPtr + 0); //loadEnvI32(con, 2, srcIdx);\n" + " dy = * (int* )(partPtr + 4); //loadEnvI32(con, 2, srcIdx + 1);\n" + " life = * (int* )(partPtr + 8); //loadEnvI32(con, 2, srcIdx + 2);\n" + " posx = * (int* )(partPtr + 12); //loadEnvI32(con, 2, srcIdx + 3);\n" + " posy = * (int* )(partPtr + 16); //loadEnvI32(con, 2, srcIdx + 4);\n" + "\n" + " if (life) {\n" + " if (posy > 0) {\n" + " c = 0xffafcf | ((life >> lifeShift) << 24);\n" + "\n" + " * (int* )(vertPtr) = c; //storeEnvU32(con, 1, dstIdx, c);\n" + " * (int* )(vertPtr + 4) = posx; //storeEnvI32(con, 1, dstIdx + 1, posx);\n" + " * (int* )(vertPtr + 8) = posy; //storeEnvI32(con, 1, dstIdx + 2, posy);\n" + "\n" + " * (int* )(vertPtr + 12) = c; //storeEnvU32(con, 1, dstIdx + 3, c);\n" + " * (int* )(vertPtr + 16) = posx + 0x10000; //storeEnvI32(con, 1, dstIdx + 4, posx + 0x10000);\n" + " * (int* )(vertPtr + 20) = posy + dy * 4; //storeEnvI32(con, 1, dstIdx + 5, posy);\n" + "\n" + " * (int* )(vertPtr + 24) = c; //storeEnvU32(con, 1, dstIdx + 6, c);\n" + " * (int* )(vertPtr + 28) = posx - 0x10000; //storeEnvI32(con, 1, dstIdx + 7, posx + 0x0800);\n" + " * (int* )(vertPtr + 32) = posy + dy * 4; //storeEnvI32(con, 1, dstIdx + 8, posy + 0x10000);\n" + "\n" + " vertPtr += 36;\n" + " drawCount ++;\n" + " } else {\n" + " if (dy < 0) {\n" + " dy = (-dy) >> 1;\n" + " }\n" + " }\n" + "\n" + " posx += dx;\n" + " posy += dy;\n" + " dy -= 0x400;\n" + " life --;\n" + "\n" + " * (int* )(partPtr + 0) = dx; //storeEnvI32(con, 2, srcIdx, dx);\n" + " * (int* )(partPtr + 4) = dy; //storeEnvI32(con, 2, srcIdx + 1, dy);\n" + " * (int* )(partPtr + 8) = life; //storeEnvI32(con, 2, srcIdx + 2, life);\n" + " * (int* )(partPtr + 12) = posx; //storeEnvI32(con, 2, srcIdx + 3, posx);\n" + " * (int* )(partPtr + 16) = posy; //storeEnvI32(con, 2, srcIdx + 4, posy);\n" + " }\n" + "\n" + " partPtr += 20;\n" + " }\n" + "\n" + " drawTriangleArray(con, loadEnvI32(con, 0, 5), drawCount);\n" + "}\n" + ""; + +typedef void (*ScriptEntry)(void *con, const rsc_FunctionTable *ft, uint32_t launchID); + +ACCscript* gScript; +ScriptEntry gScriptEntry; + +void test_script(void *con, const rsc_FunctionTable *ft, uint32_t launchID) +{ + if (!gScript) { + gScript = accCreateScript(); + } + if (!gScriptEntry) { + const char* scriptSource[] = { TEST_SCRIPT }; + accScriptSource(gScript, 1, scriptSource, NULL); + accCompileScript(gScript); + accGetScriptLabel(gScript, "main", (ACCvoid**) &gScriptEntry); + } + if (gScriptEntry) { + gScriptEntry(con, ft, launchID); + } +} + + +#else void test_script(void *con, const rsc_FunctionTable *ft, uint32_t launchID) { int count = ft->loadEnvI32(con, 0, 1); @@ -136,6 +276,7 @@ void test_script(void *con, const rsc_FunctionTable *ft, uint32_t launchID) ft->drawTriangleArray(con, (RsAllocation)ft->loadEnvI32(con, 0, 5), drawCount); } +#endif // --------------------------------------------------------------------------- diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index f825e6e3ffe7e..3c4bfa2a59355 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -31,81 +31,81 @@ ScriptC::~ScriptC() { } -static void matrixLoadIdentity(void *con, rsc_Matrix *mat) +extern "C" void matrixLoadIdentity(void *con, rsc_Matrix *mat) { Matrix *m = reinterpret_cast(mat); m->loadIdentity(); } -static void matrixLoadFloat(void *con, rsc_Matrix *mat, const float *f) +extern "C" void matrixLoadFloat(void *con, rsc_Matrix *mat, const float *f) { Matrix *m = reinterpret_cast(mat); m->load(f); } -static void matrixLoadMat(void *con, rsc_Matrix *mat, const rsc_Matrix *newmat) +extern "C" void matrixLoadMat(void *con, rsc_Matrix *mat, const rsc_Matrix *newmat) { Matrix *m = reinterpret_cast(mat); m->load(reinterpret_cast(newmat)); } -static void matrixLoadRotate(void *con, rsc_Matrix *mat, float rot, float x, float y, float z) +extern "C" void matrixLoadRotate(void *con, rsc_Matrix *mat, float rot, float x, float y, float z) { Matrix *m = reinterpret_cast(mat); m->loadRotate(rot, x, y, z); } -static void matrixLoadScale(void *con, rsc_Matrix *mat, float x, float y, float z) +extern "C" void matrixLoadScale(void *con, rsc_Matrix *mat, float x, float y, float z) { Matrix *m = reinterpret_cast(mat); m->loadScale(x, y, z); } -static void matrixLoadTranslate(void *con, rsc_Matrix *mat, float x, float y, float z) +extern "C" void matrixLoadTranslate(void *con, rsc_Matrix *mat, float x, float y, float z) { Matrix *m = reinterpret_cast(mat); m->loadTranslate(x, y, z); } -static void matrixLoadMultiply(void *con, rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) +extern "C" void matrixLoadMultiply(void *con, rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) { Matrix *m = reinterpret_cast(mat); m->loadMultiply(reinterpret_cast(lhs), reinterpret_cast(rhs)); } -static void matrixMultiply(void *con, rsc_Matrix *mat, const rsc_Matrix *rhs) +extern "C" void matrixMultiply(void *con, rsc_Matrix *mat, const rsc_Matrix *rhs) { Matrix *m = reinterpret_cast(mat); m->multiply(reinterpret_cast(rhs)); } -static void matrixRotate(void *con, rsc_Matrix *mat, float rot, float x, float y, float z) +extern "C" void matrixRotate(void *con, rsc_Matrix *mat, float rot, float x, float y, float z) { Matrix *m = reinterpret_cast(mat); m->rotate(rot, x, y, z); } -static void matrixScale(void *con, rsc_Matrix *mat, float x, float y, float z) +extern "C" void matrixScale(void *con, rsc_Matrix *mat, float x, float y, float z) { Matrix *m = reinterpret_cast(mat); m->scale(x, y, z); } -static void matrixTranslate(void *con, rsc_Matrix *mat, float x, float y, float z) +extern "C" void matrixTranslate(void *con, rsc_Matrix *mat, float x, float y, float z) { Matrix *m = reinterpret_cast(mat); m->translate(x, y, z); } -static const void * loadVp(void *vp, uint32_t bank, uint32_t offset) +extern "C" const void * loadVp(void *vp, uint32_t bank, uint32_t offset) { ScriptC::Env * env = static_cast(vp); return &static_cast(env->mScript->mSlots[bank]->getPtr())[offset]; } -static float loadF(void *vp, uint32_t bank, uint32_t offset) +extern "C" float loadF(void *vp, uint32_t bank, uint32_t offset) { ScriptC::Env * env = static_cast(vp); //LOGE("bank %i, offset %i", bank, offset); @@ -113,132 +113,132 @@ static float loadF(void *vp, uint32_t bank, uint32_t offset) return static_cast(env->mScript->mSlots[bank]->getPtr())[offset]; } -static int32_t loadI32(void *vp, uint32_t bank, uint32_t offset) +extern "C" int32_t loadI32(void *vp, uint32_t bank, uint32_t offset) { ScriptC::Env * env = static_cast(vp); return static_cast(env->mScript->mSlots[bank]->getPtr())[offset]; } -static uint32_t loadU32(void *vp, uint32_t bank, uint32_t offset) +extern "C" uint32_t loadU32(void *vp, uint32_t bank, uint32_t offset) { ScriptC::Env * env = static_cast(vp); return static_cast(env->mScript->mSlots[bank]->getPtr())[offset]; } -static void loadEnvVec4(void *vp, uint32_t bank, uint32_t offset, rsc_Vector4 *v) +extern "C" void loadEnvVec4(void *vp, uint32_t bank, uint32_t offset, rsc_Vector4 *v) { ScriptC::Env * env = static_cast(vp); memcpy(v, &static_cast(env->mScript->mSlots[bank]->getPtr())[offset], sizeof(rsc_Vector4)); } -static void loadEnvMatrix(void *vp, uint32_t bank, uint32_t offset, rsc_Matrix *m) +extern "C" void loadEnvMatrix(void *vp, uint32_t bank, uint32_t offset, rsc_Matrix *m) { ScriptC::Env * env = static_cast(vp); memcpy(m, &static_cast(env->mScript->mSlots[bank]->getPtr())[offset], sizeof(rsc_Matrix)); } -static void storeF(void *vp, uint32_t bank, uint32_t offset, float v) +extern "C" void storeF(void *vp, uint32_t bank, uint32_t offset, float v) { ScriptC::Env * env = static_cast(vp); static_cast(env->mScript->mSlots[bank]->getPtr())[offset] = v; } -static void storeI32(void *vp, uint32_t bank, uint32_t offset, int32_t v) +extern "C" void storeI32(void *vp, uint32_t bank, uint32_t offset, int32_t v) { ScriptC::Env * env = static_cast(vp); static_cast(env->mScript->mSlots[bank]->getPtr())[offset] = v; } -static void storeU32(void *vp, uint32_t bank, uint32_t offset, uint32_t v) +extern "C" void storeU32(void *vp, uint32_t bank, uint32_t offset, uint32_t v) { ScriptC::Env * env = static_cast(vp); static_cast(env->mScript->mSlots[bank]->getPtr())[offset] = v; } -static void storeEnvVec4(void *vp, uint32_t bank, uint32_t offset, const rsc_Vector4 *v) +extern "C" void storeEnvVec4(void *vp, uint32_t bank, uint32_t offset, const rsc_Vector4 *v) { ScriptC::Env * env = static_cast(vp); memcpy(&static_cast(env->mScript->mSlots[bank]->getPtr())[offset], v, sizeof(rsc_Vector4)); } -static void storeEnvMatrix(void *vp, uint32_t bank, uint32_t offset, const rsc_Matrix *m) +extern "C" void storeEnvMatrix(void *vp, uint32_t bank, uint32_t offset, const rsc_Matrix *m) { ScriptC::Env * env = static_cast(vp); memcpy(&static_cast(env->mScript->mSlots[bank]->getPtr())[offset], m, sizeof(rsc_Matrix)); } -static void color(void *vp, float r, float g, float b, float a) +extern "C" void color(void *vp, float r, float g, float b, float a) { ScriptC::Env * env = static_cast(vp); glColor4f(r, g, b, a); } -static void renderTriangleMesh(void *vp, RsTriangleMesh mesh) +extern "C" void renderTriangleMesh(void *vp, RsTriangleMesh mesh) { ScriptC::Env * env = static_cast(vp); rsi_TriangleMeshRender(env->mContext, mesh); } -static void renderTriangleMeshRange(void *vp, RsTriangleMesh mesh, uint32_t start, uint32_t count) +extern "C" void renderTriangleMeshRange(void *vp, RsTriangleMesh mesh, uint32_t start, uint32_t count) { ScriptC::Env * env = static_cast(vp); rsi_TriangleMeshRenderRange(env->mContext, mesh, start, count); } -static void materialDiffuse(void *vp, float r, float g, float b, float a) +extern "C" void materialDiffuse(void *vp, float r, float g, float b, float a) { ScriptC::Env * env = static_cast(vp); float v[] = {r, g, b, a}; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); } -static void materialSpecular(void *vp, float r, float g, float b, float a) +extern "C" void materialSpecular(void *vp, float r, float g, float b, float a) { ScriptC::Env * env = static_cast(vp); float v[] = {r, g, b, a}; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); } -static void lightPosition(void *vp, float x, float y, float z, float w) +extern "C" void lightPosition(void *vp, float x, float y, float z, float w) { ScriptC::Env * env = static_cast(vp); float v[] = {x, y, z, w}; glLightfv(GL_LIGHT0, GL_POSITION, v); } -static void materialShininess(void *vp, float s) +extern "C" void materialShininess(void *vp, float s) { ScriptC::Env * env = static_cast(vp); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); } -static void uploadToTexture(void *vp, RsAllocation va, uint32_t baseMipLevel) +extern "C" void uploadToTexture(void *vp, RsAllocation va, uint32_t baseMipLevel) { ScriptC::Env * env = static_cast(vp); rsi_AllocationUploadToTexture(env->mContext, va, baseMipLevel); } -static void enable(void *vp, uint32_t p) +extern "C" void enable(void *vp, uint32_t p) { ScriptC::Env * env = static_cast(vp); glEnable(p); } -static void disable(void *vp, uint32_t p) +extern "C" void disable(void *vp, uint32_t p) { ScriptC::Env * env = static_cast(vp); glDisable(p); } -static uint32_t scriptRand(void *vp, uint32_t max) +extern "C" uint32_t scriptRand(void *vp, uint32_t max) { return (uint32_t)(((float)rand()) * max / RAND_MAX); } // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a -static void drawTriangleArray(void *vp, RsAllocation alloc, uint32_t count) +extern "C" void drawTriangleArray(void *vp, RsAllocation alloc, uint32_t count) { const Allocation *a = (const Allocation *)alloc; const uint32_t *ptr = (const uint32_t *)a->getPtr(); @@ -261,28 +261,28 @@ static void drawTriangleArray(void *vp, RsAllocation alloc, uint32_t count) glDrawArrays(GL_TRIANGLES, 0, count * 3); } -static void pfBindTexture(void *vp, RsProgramFragment vpf, uint32_t slot, RsAllocation va) +extern "C" void pfBindTexture(void *vp, RsProgramFragment vpf, uint32_t slot, RsAllocation va) { //LOGE("pfBindTexture %p", vpf); ScriptC::Env * env = static_cast(vp); - rsi_ProgramFragmentBindTexture(env->mContext, + rsi_ProgramFragmentBindTexture(env->mContext, static_cast(vpf), slot, static_cast(va)); } -static void pfBindSampler(void *vp, RsProgramFragment vpf, uint32_t slot, RsSampler vs) +extern "C" void pfBindSampler(void *vp, RsProgramFragment vpf, uint32_t slot, RsSampler vs) { ScriptC::Env * env = static_cast(vp); - rsi_ProgramFragmentBindSampler(env->mContext, + rsi_ProgramFragmentBindSampler(env->mContext, static_cast(vpf), slot, static_cast(vs)); } -static void contextBindProgramFragmentStore(void *vp, RsProgramFragmentStore pfs) +extern "C" void contextBindProgramFragmentStore(void *vp, RsProgramFragmentStore pfs) { //LOGE("contextBindProgramFragmentStore %p", pfs); ScriptC::Env * env = static_cast(vp); @@ -290,7 +290,7 @@ static void contextBindProgramFragmentStore(void *vp, RsProgramFragmentStore pfs } -static void contextBindProgramFragment(void *vp, RsProgramFragment pf) +extern "C" void contextBindProgramFragment(void *vp, RsProgramFragment pf) { //LOGE("contextBindProgramFragment %p", pf); ScriptC::Env * env = static_cast(vp);