Fix Fountain test app so that it actually builds.

Also check in first part of an libACC implementation.
This commit is contained in:
Jack Palevich
2009-05-26 18:58:04 -07:00
parent ecd53112c5
commit 55d4522392
7 changed files with 205 additions and 63 deletions

View File

@@ -112,6 +112,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
libandroid_runtime \
libacc \
libnativehelper \
libRS \
libcutils \

View File

@@ -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)
##################################################

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.calc">
<application android:label="Calc">
<activity android:name="Calc"
<application android:label="Fountain">
<activity android:name="Fountain"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -10,4 +10,4 @@
</intent-filter>
</activity>
</application>
</manifest>
</manifest>

View File

@@ -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);
}

View File

@@ -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;
}
}
}

View File

@@ -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<rate; ct2++) {\n"
" dx = scriptRand(con, 0x10000) - 0x8000;\n"
" dy = scriptRand(con, 0x10000) - 0x8000;\n"
"\n"
" idx = newPart * 5 + 1;\n"
" storeEnvI32(con, 2, idx, dx);\n"
" storeEnvI32(con, 2, idx + 1, dy);\n"
" storeEnvI32(con, 2, idx + 2, maxLife);\n"
" storeEnvI32(con, 2, idx + 3, x << 16);\n"
" storeEnvI32(con, 2, idx + 4, y << 16);\n"
"\n"
" newPart++;\n"
" if (newPart >= 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
// ---------------------------------------------------------------------------

View File

@@ -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<Matrix *>(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<Matrix *>(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<Matrix *>(mat);
m->load(reinterpret_cast<const Matrix *>(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<Matrix *>(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<Matrix *>(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<Matrix *>(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<Matrix *>(mat);
m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
reinterpret_cast<const Matrix *>(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<Matrix *>(mat);
m->multiply(reinterpret_cast<const Matrix *>(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<Matrix *>(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<Matrix *>(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<Matrix *>(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<ScriptC::Env *>(vp);
return &static_cast<const uint8_t *>(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<ScriptC::Env *>(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<const float *>(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<ScriptC::Env *>(vp);
return static_cast<const int32_t *>(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<ScriptC::Env *>(vp);
return static_cast<const uint32_t *>(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<ScriptC::Env *>(vp);
memcpy(v, &static_cast<const float *>(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<ScriptC::Env *>(vp);
memcpy(m, &static_cast<const float *>(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<ScriptC::Env *>(vp);
static_cast<float *>(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<ScriptC::Env *>(vp);
static_cast<int32_t *>(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<ScriptC::Env *>(vp);
static_cast<uint32_t *>(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<ScriptC::Env *>(vp);
memcpy(&static_cast<float *>(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<ScriptC::Env *>(vp);
memcpy(&static_cast<float *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(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<ScriptC::Env *>(vp);
rsi_ProgramFragmentBindTexture(env->mContext,
rsi_ProgramFragmentBindTexture(env->mContext,
static_cast<ProgramFragment *>(vpf),
slot,
static_cast<Allocation *>(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<ScriptC::Env *>(vp);
rsi_ProgramFragmentBindSampler(env->mContext,
rsi_ProgramFragmentBindSampler(env->mContext,
static_cast<ProgramFragment *>(vpf),
slot,
static_cast<Sampler *>(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<ScriptC::Env *>(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<ScriptC::Env *>(vp);