diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-20 14:32:15 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-20 14:32:15 -0700 |
commit | c7b0dba641d5417286caa3694e70b039012d1e91 (patch) | |
tree | 813c5549be9466fe2fab61d30321cee6b3807cee /libs | |
parent | 91aa1ad300b732ef0a16ef213a0038c2e1dd05dd (diff) | |
parent | c97bb8844f9887d915d3c9e4b3582bd761357f98 (diff) | |
download | frameworks_base-c7b0dba641d5417286caa3694e70b039012d1e91.zip frameworks_base-c7b0dba641d5417286caa3694e70b039012d1e91.tar.gz frameworks_base-c7b0dba641d5417286caa3694e70b039012d1e91.tar.bz2 |
Merge change 7939
* changes:
Split rsScriptC into class implemtation and library functions. Update test apps, all 3 should be working.
Diffstat (limited to 'libs')
-rw-r--r-- | libs/rs/Android.mk | 1 | ||||
-rw-r--r-- | libs/rs/RenderScriptEnv.h | 60 | ||||
-rw-r--r-- | libs/rs/java/Film/res/raw/filmstrip.c | 31 | ||||
-rw-r--r-- | libs/rs/java/Rollo/res/raw/rollo.c | 2 | ||||
-rw-r--r-- | libs/rs/java/Rollo/src/com/android/rollo/RolloView.java | 2 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 464 | ||||
-rw-r--r-- | libs/rs/rsScriptC.h | 6 | ||||
-rw-r--r-- | libs/rs/rsScriptC_Lib.cpp | 523 |
8 files changed, 545 insertions, 544 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 5f47871..0091e32 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -98,6 +98,7 @@ LOCAL_SRC_FILES:= \ rsSampler.cpp \ rsScript.cpp \ rsScriptC.cpp \ + rsScriptC_Lib.cpp \ rsThreadIO.cpp \ rsType.cpp \ rsTriangleMesh.cpp diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h index 53de1f1..0789301 100644 --- a/libs/rs/RenderScriptEnv.h +++ b/libs/rs/RenderScriptEnv.h @@ -30,65 +30,7 @@ typedef struct { #define RS_PROGRAM_VERTEX_PROJECTION_OFFSET 16 #define RS_PROGRAM_VERTEX_TEXTURE_OFFSET 32 -typedef struct { - const void * (*loadEnvVp)(uint32_t bank, uint32_t offset); - - float (*loadEnvF)(uint32_t bank, uint32_t offset); - int32_t (*loadEnvI32)(uint32_t bank, uint32_t offset); - uint32_t (*loadEnvU32)(uint32_t bank, uint32_t offset); - void (*loadEnvVec4)(uint32_t bank, uint32_t offset, rsc_Vector4 *); - void (*loadEnvMatrix)(uint32_t bank, uint32_t offset, rsc_Matrix *); - - void (*storeEnvF)(uint32_t bank, uint32_t offset, float); - void (*storeEnvI32)(uint32_t bank, uint32_t offset, int32_t); - void (*storeEnvU32)(uint32_t bank, uint32_t offset, uint32_t); - void (*storeEnvVec4)(uint32_t bank, uint32_t offset, const rsc_Vector4 *); - void (*storeEnvMatrix)(uint32_t bank, uint32_t offset, const rsc_Matrix *); - - void (*matrixLoadIdentity)(rsc_Matrix *); - void (*matrixLoadFloat)(rsc_Matrix *, const float *); - void (*matrixLoadMat)(rsc_Matrix *, const rsc_Matrix *); - void (*matrixLoadRotate)(rsc_Matrix *, float rot, float x, float y, float z); - void (*matrixLoadScale)(rsc_Matrix *, float x, float y, float z); - void (*matrixLoadTranslate)(rsc_Matrix *, float x, float y, float z); - void (*matrixLoadMultiply)(rsc_Matrix *, const rsc_Matrix *lhs, const rsc_Matrix *rhs); - void (*matrixMultiply)(rsc_Matrix *, const rsc_Matrix *rhs); - void (*matrixRotate)(rsc_Matrix *, float rot, float x, float y, float z); - void (*matrixScale)(rsc_Matrix *, float x, float y, float z); - void (*matrixTranslate)(rsc_Matrix *, float x, float y, float z); - - void (*color)(float r, float g, float b, float a); - - void (*programFragmentBindTexture)(RsProgramFragment, uint32_t slot, RsAllocation); - void (*programFragmentBindSampler)(RsProgramFragment, uint32_t slot, RsAllocation); - - void (*materialDiffuse)(float r, float g, float b, float a); - void (*materialSpecular)(float r, float g, float b, float a); - void (*lightPosition)(float x, float y, float z, float w); - void (*materialShininess)(float s); - - void (*uploadToTexture)(RsAllocation va, uint32_t baseMipLevel); - - void (*enable)(uint32_t); - void (*disable)(uint32_t); - - uint32_t (*rand)(uint32_t max); - - void (*contextBindProgramFragment)(RsProgramFragment pf); - void (*contextBindProgramFragmentStore)(RsProgramFragmentStore pfs); - - - // Drawing funcs - void (*renderTriangleMesh)(RsTriangleMesh); - void (*renderTriangleMeshRange)(RsTriangleMesh, uint32_t start, uint32_t count); - - // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a - void (*drawTriangleArray)(RsAllocation alloc, uint32_t count); - - void (*drawRect)(int32_t x1, int32_t x2, int32_t y1, int32_t y2); -} rsc_FunctionTable; - -typedef int (*rsc_RunScript)(uint32_t launchIndex, const rsc_FunctionTable *); +//typedef int (*rsc_RunScript)(uint32_t launchIndex, const rsc_FunctionTable *); /* EnableCap */ diff --git a/libs/rs/java/Film/res/raw/filmstrip.c b/libs/rs/java/Film/res/raw/filmstrip.c index 1687a31..863b930 100644 --- a/libs/rs/java/Film/res/raw/filmstrip.c +++ b/libs/rs/java/Film/res/raw/filmstrip.c @@ -23,47 +23,36 @@ int main(int index) { int f1,f2,f3,f4, f5,f6,f7,f8, f9,f10,f11,f12, f13,f14,f15,f16; int g1,g2,g3,g4, g5,g6,g7,g8, g9,g10,g11,g12, g13,g14,g15,g16; - int float_1; - int float_0; - int float_2; - int float_90; - int float_0_5; - int trans; // float - int rot; // float + float trans; + float rot; int x; float focusPos; // float int focusID; int lastFocusID; int imgCount; - float_2 = intToFloat(2); - float_1 = intToFloat(1); - float_0 = intToFloat(0); - float_90= intToFloat(90); - float_0_5 = fixedtoFloat(0x8000); - trans = loadF(1, 0); rot = loadF(1, 1); - matrixLoadScale(&f16, float_2, float_2, float_2); - matrixTranslate(&f16, 0, 0, trans); - matrixRotate(&f16, float_90, 0, 0, float_1); - matrixRotate(&f16, rot, float_1, 0, 0); - storeEnvMatrix(3, 0, &f16); + matrixLoadScale(&f16, 2.f, 2.f, 2.f); + matrixTranslate(&f16, 0.f, 0.f, trans); + matrixRotate(&f16, 90.f, 0.f, 0.f, 1.f); + matrixRotate(&f16, rot, 1.f, 0.f, 0.f); + storeMatrix(3, 0, &f16); //materialDiffuse(con, 0.0f, 0.0f, 0.0f, 1.0f); //materialSpecular(con, 0.5f, 0.5f, 0.5f, 0.5f); //materialShininess(intToFloat(20)); //lightPosition(con, 0.2f, -0.2f, -2.0f, 0.0f); //enable(con, GL_LIGHTING); - renderTriangleMesh(NAMED_mesh); + drawTriangleMesh(NAMED_mesh); //int imgId = 0; - contextBindProgramFragmentStore(NAMED_PFImages); - contextBindProgramFragment(NAMED_PFSImages); + bindProgramFragmentStore(NAMED_PFImages); + bindProgramFragment(NAMED_PFSImages); //focusPos = loadF(1, 2); //focusID = 0; diff --git a/libs/rs/java/Rollo/res/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c index 70b48fa..d338d0d 100644 --- a/libs/rs/java/Rollo/res/raw/rollo.c +++ b/libs/rs/java/Rollo/res/raw/rollo.c @@ -84,7 +84,7 @@ int main(void* con, int ft, int launchID) for (y = rowCount -1; (y >= 0) && iconCount; y--) { float ty1 = ((y * 3.0f) - 4.5f) * scale; float ty2 = ty1 + scale * 2.f; - pfBindTexture(NAMED_PF, 0, loadI32(1, y)); + bindTexture(NAMED_PF, 0, loadI32(1, y)); color(1.0f, 1.0f, 1.0f, 1.0f); if (done && (index != selectedID)) { color(0.4f, 0.4f, 0.4f, 1.0f); diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java index eefebf8..b5e02af 100644 --- a/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java @@ -175,7 +175,7 @@ public class RolloView extends RSSurfaceView { // icon control if(act != ev.ACTION_UP) { if(mFlingMode) { - mColumn += (mFlingX - nx) * 5; + mColumn += (mFlingX - nx) * 4; setColumn(true); } mFlingMode = true; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index e9fc4d0..e0928c3 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -46,413 +46,6 @@ ScriptC::~ScriptC() } } -extern "C" float fixedToFloat(int32_t f) -{ - return ((float)f) / 0x10000; -} - -extern "C" float intToFloat(int32_t f) -{ - return (float)f; -} - -extern "C" void matrixLoadIdentity(rsc_Matrix *mat) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->loadIdentity(); -} - -extern "C" void matrixLoadFloat(rsc_Matrix *mat, const float *f) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->load(f); -} - -extern "C" void matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->load(reinterpret_cast<const Matrix *>(newmat)); -} - -extern "C" void matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->loadRotate(rot, x, y, z); -} - -extern "C" void matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->loadScale(x, y, z); -} - -extern "C" void matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->loadTranslate(x, y, z); -} - -extern "C" void matrixLoadMultiply(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)); -} - -extern "C" void matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->multiply(reinterpret_cast<const Matrix *>(rhs)); -} - -extern "C" void matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->rotate(rot, x, y, z); -} - -extern "C" void matrixScale(rsc_Matrix *mat, float x, float y, float z) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->scale(x, y, z); -} - -extern "C" void matrixTranslate(rsc_Matrix *mat, float x, float y, float z) -{ - Matrix *m = reinterpret_cast<Matrix *>(mat); - m->translate(x, y, z); -} - - -extern "C" const void * loadVp(uint32_t bank, uint32_t offset) -{ - GET_TLS(); - return &static_cast<const uint8_t *>(sc->mSlots[bank]->getPtr())[offset]; -} - -static float SC_loadF(uint32_t bank, uint32_t offset) -{ - GET_TLS(); - float f = static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset]; - //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]); - return f; -} - -static int32_t SC_loadI32(uint32_t bank, uint32_t offset) -{ - GET_TLS(); - int32_t t = static_cast<const int32_t *>(sc->mSlots[bank]->getPtr())[offset]; - //LOGE("loadI32 %i %i = %i", bank, offset, t); - return t; -} - -static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) -{ - GET_TLS(); - return static_cast<const uint32_t *>(sc->mSlots[bank]->getPtr())[offset]; -} - -extern "C" void loadEnvVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v) -{ - GET_TLS(); - memcpy(v, &static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset], sizeof(rsc_Vector4)); -} - -extern "C" void loadEnvMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m) -{ - GET_TLS(); - memcpy(m, &static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset], sizeof(rsc_Matrix)); -} - - -static void SC_storeF(uint32_t bank, uint32_t offset, float v) -{ - //LOGE("storeF %i %i %f", bank, offset, v); - GET_TLS(); - static_cast<float *>(sc->mSlots[bank]->getPtr())[offset] = v; -} - -static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v) -{ - GET_TLS(); - static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; -} - -static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v) -{ - GET_TLS(); - static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; -} - -extern "C" void storeEnvVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v) -{ - GET_TLS(); - memcpy(&static_cast<float *>(sc->mSlots[bank]->getPtr())[offset], v, sizeof(rsc_Vector4)); -} - -extern "C" void storeEnvMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) -{ - GET_TLS(); - memcpy(&static_cast<float *>(sc->mSlots[bank]->getPtr())[offset], m, sizeof(rsc_Matrix)); -} - - -static void SC_color(float r, float g, float b, float a) -{ - glColor4f(r, g, b, a); -} - -extern "C" void renderTriangleMesh(RsTriangleMesh mesh) -{ - GET_TLS(); - rsi_TriangleMeshRender(rsc, mesh); -} - -extern "C" void renderTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count) -{ - GET_TLS(); - rsi_TriangleMeshRenderRange(rsc, mesh, start, count); -} - -extern "C" void materialDiffuse(float r, float g, float b, float a) -{ - float v[] = {r, g, b, a}; - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); -} - -extern "C" void materialSpecular(float r, float g, float b, float a) -{ - float v[] = {r, g, b, a}; - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); -} - -extern "C" void lightPosition(float x, float y, float z, float w) -{ - float v[] = {x, y, z, w}; - glLightfv(GL_LIGHT0, GL_POSITION, v); -} - -extern "C" void materialShininess(float s) -{ - glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); -} - -extern "C" void uploadToTexture(RsAllocation va, uint32_t baseMipLevel) -{ - GET_TLS(); - rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); -} - -extern "C" void enable(uint32_t p) -{ - glEnable(p); -} - -extern "C" void disable(uint32_t p) -{ - glDisable(p); -} - -static float SC_randf(float max) -{ - float r = (float)rand(); - return r / RAND_MAX * max; -} - -// Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a -static void SC_drawTriangleArray(int ialloc, uint32_t count) -{ - GET_TLS(); - RsAllocation alloc = (RsAllocation)ialloc; - - const Allocation *a = (const Allocation *)alloc; - const uint32_t *ptr = (const uint32_t *)a->getPtr(); - - rsc->setupCheck(); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); - - glEnableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - glVertexPointer(2, GL_FIXED, 12, ptr + 1); - //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1); - glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); - - glDrawArrays(GL_TRIANGLES, 0, count * 3); -} - -extern "C" void drawRect(int32_t x1, int32_t x2, int32_t y1, int32_t y2) -{ - GET_TLS(); - x1 = (x1 << 16); - x2 = (x2 << 16); - y1 = (y1 << 16); - y2 = (y2 << 16); - - int32_t vtx[] = {x1,y1, x1,y2, x2,y1, x2,y2}; - static const int32_t tex[] = {0,0, 0,0x10000, 0x10000,0, 0x10000,0x10000}; - - - rsc->setupCheck(); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glVertexPointer(2, GL_FIXED, 8, vtx); - glTexCoordPointer(2, GL_FIXED, 8, tex); - //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -} - -static void SC_drawQuad(float x1, float y1, float z1, - float x2, float y2, float z2, - float x3, float y3, float z3, - float x4, float y4, float z4) -{ - GET_TLS(); - - //LOGE("Quad"); - //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); - //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); - //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); - //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); - - float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; - static const float tex[] = {0,1, 1,1, 1,0, 0,0}; - - - rsc->setupCheck(); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, vtx); - - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, tex); - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, tex); - glClientActiveTexture(GL_TEXTURE0); - - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); -} - -extern "C" void pfClearColor(float r, float g, float b, float a) -{ - //LOGE("c %f %f %f %f", r, g, b, a); - GET_TLS(); - sc->mEnviroment.mClearColor[0] = r; - sc->mEnviroment.mClearColor[1] = g; - sc->mEnviroment.mClearColor[2] = b; - sc->mEnviroment.mClearColor[3] = a; -} - -extern "C" void pfBindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) -{ - GET_TLS(); - rsi_ProgramFragmentBindTexture(rsc, - static_cast<ProgramFragment *>(vpf), - slot, - static_cast<Allocation *>(va)); - -} - -extern "C" void pfBindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) -{ - GET_TLS(); - rsi_ProgramFragmentBindSampler(rsc, - static_cast<ProgramFragment *>(vpf), - slot, - static_cast<Sampler *>(vs)); - -} - -extern "C" void contextBindProgramFragmentStore(RsProgramFragmentStore pfs) -{ - GET_TLS(); - rsi_ContextBindProgramFragmentStore(rsc, pfs); - -} - -extern "C" void contextBindProgramFragment(RsProgramFragment pf) -{ - GET_TLS(); - rsi_ContextBindProgramFragment(rsc, pf); - -} - - -static rsc_FunctionTable scriptCPtrTable; -/* = { - loadVp, - SC_loadF, - SC_loadI32, - SC_loadU32, - loadEnvVec4, - loadEnvMatrix, - - SC_storeF, - SC_storeI32, - SC_storeU32, - storeEnvVec4, - storeEnvMatrix, - - matrixLoadIdentity, - matrixLoadFloat, - matrixLoadMat, - matrixLoadRotate, - matrixLoadScale, - matrixLoadTranslate, - matrixLoadMultiply, - matrixMultiply, - matrixRotate, - matrixScale, - matrixTranslate, - - SC_color, - - pfBindTexture, - pfBindSampler, - - materialDiffuse, - materialSpecular, - lightPosition, - materialShininess, - uploadToTexture, - enable, - disable, - - SC_randf, - contextBindProgramFragment, - contextBindProgramFragmentStore, - - - renderTriangleMesh, - renderTriangleMeshRange, - - SC_drawTriangleArray, - drawRect - -}; -*/ bool ScriptC::run(Context *rsc, uint32_t launchIndex) { @@ -469,9 +62,11 @@ bool ScriptC::run(Context *rsc, uint32_t launchIndex) rsc->setVertex(mEnviroment.mVertex.get()); } + bool ret = false; tls->mScript = this; - return mProgram.mScript(launchIndex, &scriptCPtrTable) != 0; + ret = mProgram.mScript(launchIndex) != 0; tls->mScript = NULL; + return ret; } ScriptCState::ScriptCState() @@ -505,47 +100,6 @@ void ScriptCState::clear() } -ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { - // IO - { "loadI32", (void *)&SC_loadI32, "int loadI32(int, int)" }, - //{ "loadU32", (void *)&SC_loadU32, "unsigned int loadU32(int, int)" }, - { "loadF", (void *)&SC_loadF, "float loadF(int, int)" }, - { "storeI32", (void *)&SC_storeI32, "void storeI32(int, int, int)" }, - //{ "storeU32", (void *)&SC_storeU32, "void storeU32(int, int, unsigned int)" }, - { "storeF", (void *)&SC_storeF, "void storeF(int, int, float)" }, - - // math - { "sinf", (void *)&sinf, "float sinf(float)" }, - { "cosf", (void *)&cosf, "float cosf(float)" }, - { "fabs", (void *)&fabs, "float fabs(float)" }, - { "randf", (void *)&SC_randf, "float randf(float)" }, - - // context - { "drawQuad", (void *)&SC_drawQuad, "void drawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" }, - { "contextBindProgramFragmentStore", (void *)&contextBindProgramFragmentStore, "void contextBindProgramFragmentStore(int)" }, - { "pfClearColor", (void *)&pfClearColor, "void pfClearColor(float, float, float, float)" }, - { "pfBindTexture", (void *)&pfBindTexture, "void pfBindTexture(int, int, int)" }, - - { "color", (void *)&SC_color, "void color(float, float, float, float)" }, - { "drawTriangleArray", (void *)&SC_drawTriangleArray, "void drawTriangleArray(int ialloc, int count)" }, - - - { NULL, NULL, NULL } -}; - -const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) -{ - ScriptCState::SymbolTable_t *syms = gSyms; - - while (syms->mPtr) { - if (!strcmp(syms->mName, sym)) { - return syms; - } - syms++; - } - return NULL; -} - static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) { const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name); @@ -560,16 +114,6 @@ static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) return NULL; } -void ScriptCState::appendDecls(String8 *str) -{ - ScriptCState::SymbolTable_t *syms = gSyms; - while (syms->mPtr) { - str->append(syms->mDecl); - str->append(";\n"); - syms++; - } -} - void ScriptCState::runCompiler(Context *rsc) { mAccScript = accCreateScript(); @@ -711,7 +255,7 @@ void rsi_ScriptCAddType(Context * rsc, RsType vt) void rsi_ScriptCSetScript(Context * rsc, void *vp) { ScriptCState *ss = &rsc->mScriptC; - ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp); + ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp); } void rsi_ScriptCSetRoot(Context * rsc, bool isRoot) diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h index 3a3f2f7..860b4d1 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -32,6 +32,7 @@ namespace renderscript { class ScriptC : public Script { public: + typedef int (*RunScript_t)(uint32_t launchIndex); ScriptC(); virtual ~ScriptC(); @@ -44,7 +45,7 @@ public: int mVersionMajor; int mVersionMinor; - rsc_RunScript mScript; + RunScript_t mScript; }; Program_t mProgram; @@ -73,7 +74,8 @@ public: struct SymbolTable_t { const char * mName; void * mPtr; - const char * mDecl; + const char * mRet; + const char * mParam; }; static SymbolTable_t gSyms[]; static const SymbolTable_t * lookupSymbol(const char *); diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp new file mode 100644 index 0000000..59d8e5f --- /dev/null +++ b/libs/rs/rsScriptC_Lib.cpp @@ -0,0 +1,523 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rsContext.h" +#include "rsScriptC.h" +#include "rsMatrix.h" + +#include "acc/acc.h" +#include "utils/String8.h" + +#include <GLES/gl.h> +#include <GLES/glext.h> + +using namespace android; +using namespace android::renderscript; + +#define GET_TLS() Context::ScriptTLSStruct * tls = \ + (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ + Context * rsc = tls->mContext; \ + ScriptC * sc = (ScriptC *) tls->mScript + + +////////////////////////////////////////////////////////////////////////////// +// IO routines +////////////////////////////////////////////////////////////////////////////// + +static float SC_loadF(uint32_t bank, uint32_t offset) +{ + GET_TLS(); + const void *vp = sc->mSlots[bank]->getPtr(); + const float *f = static_cast<const float *>(vp); + //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]); + return f[offset]; +} + +static int32_t SC_loadI32(uint32_t bank, uint32_t offset) +{ + GET_TLS(); + const void *vp = sc->mSlots[bank]->getPtr(); + const int32_t *i = static_cast<const int32_t *>(vp); + //LOGE("loadI32 %i %i = %i", bank, offset, t); + return i[offset]; +} + +static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) +{ + GET_TLS(); + const void *vp = sc->mSlots[bank]->getPtr(); + const uint32_t *i = static_cast<const uint32_t *>(vp); + return i[offset]; +} + +static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v) +{ + GET_TLS(); + const void *vp = sc->mSlots[bank]->getPtr(); + const float *f = static_cast<const float *>(vp); + memcpy(v, &f[offset], sizeof(rsc_Vector4)); +} + +static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m) +{ + GET_TLS(); + const void *vp = sc->mSlots[bank]->getPtr(); + const float *f = static_cast<const float *>(vp); + memcpy(m, &f[offset], sizeof(rsc_Matrix)); +} + + +static void SC_storeF(uint32_t bank, uint32_t offset, float v) +{ + //LOGE("storeF %i %i %f", bank, offset, v); + GET_TLS(); + void *vp = sc->mSlots[bank]->getPtr(); + float *f = static_cast<float *>(vp); + f[offset] = v; +} + +static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v) +{ + GET_TLS(); + void *vp = sc->mSlots[bank]->getPtr(); + int32_t *f = static_cast<int32_t *>(vp); + static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; +} + +static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v) +{ + GET_TLS(); + void *vp = sc->mSlots[bank]->getPtr(); + uint32_t *f = static_cast<uint32_t *>(vp); + static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; +} + +static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v) +{ + GET_TLS(); + void *vp = sc->mSlots[bank]->getPtr(); + float *f = static_cast<float *>(vp); + memcpy(&f[offset], v, sizeof(rsc_Vector4)); +} + +static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) +{ + GET_TLS(); + void *vp = sc->mSlots[bank]->getPtr(); + float *f = static_cast<float *>(vp); + memcpy(&f[offset], m, sizeof(rsc_Matrix)); +} + + +////////////////////////////////////////////////////////////////////////////// +// Math routines +////////////////////////////////////////////////////////////////////////////// + +static float SC_randf(float max) +{ + float r = (float)rand(); + return r / RAND_MAX * max; +} + + + + + +////////////////////////////////////////////////////////////////////////////// +// Matrix routines +////////////////////////////////////////////////////////////////////////////// + + +static void SC_matrixLoadIdentity(rsc_Matrix *mat) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->loadIdentity(); +} + +static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->load(f); +} + +static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->load(reinterpret_cast<const Matrix *>(newmat)); +} + +static void SC_matrixLoadRotate(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 SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->loadScale(x, y, z); +} + +static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->loadTranslate(x, y, z); +} + +static void SC_matrixLoadMultiply(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 SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->multiply(reinterpret_cast<const Matrix *>(rhs)); +} + +static void SC_matrixRotate(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 SC_matrixScale(rsc_Matrix *mat, float x, float y, float z) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->scale(x, y, z); +} + +static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z) +{ + Matrix *m = reinterpret_cast<Matrix *>(mat); + m->translate(x, y, z); +} + + + + +////////////////////////////////////////////////////////////////////////////// +// Context +////////////////////////////////////////////////////////////////////////////// + +static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) +{ + GET_TLS(); + rsi_ProgramFragmentBindTexture(rsc, + static_cast<ProgramFragment *>(vpf), + slot, + static_cast<Allocation *>(va)); + +} + +static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) +{ + GET_TLS(); + rsi_ProgramFragmentBindSampler(rsc, + static_cast<ProgramFragment *>(vpf), + slot, + static_cast<Sampler *>(vs)); + +} + +static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs) +{ + GET_TLS(); + rsi_ContextBindProgramFragmentStore(rsc, pfs); + +} + +static void SC_bindProgramFragment(RsProgramFragment pf) +{ + GET_TLS(); + rsi_ContextBindProgramFragment(rsc, pf); + +} + + +////////////////////////////////////////////////////////////////////////////// +// Drawing +////////////////////////////////////////////////////////////////////////////// + +static void SC_drawTriangleMesh(RsTriangleMesh mesh) +{ + GET_TLS(); + rsi_TriangleMeshRender(rsc, mesh); +} + +static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count) +{ + GET_TLS(); + rsi_TriangleMeshRenderRange(rsc, mesh, start, count); +} + +// Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a +static void SC_drawTriangleArray(int ialloc, uint32_t count) +{ + GET_TLS(); + RsAllocation alloc = (RsAllocation)ialloc; + + const Allocation *a = (const Allocation *)alloc; + const uint32_t *ptr = (const uint32_t *)a->getPtr(); + + rsc->setupCheck(); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); + + glEnableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glVertexPointer(2, GL_FIXED, 12, ptr + 1); + //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1); + glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); + + glDrawArrays(GL_TRIANGLES, 0, count * 3); +} + +static void SC_drawQuad(float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3, + float x4, float y4, float z4) +{ + GET_TLS(); + + //LOGE("Quad"); + //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); + //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); + //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); + //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); + + float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; + static const float tex[] = {0,1, 1,1, 1,0, 0,0}; + + + rsc->setupCheck(); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, vtx); + + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, tex); + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, tex); + glClientActiveTexture(GL_TEXTURE0); + + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); +} + +////////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////////// + +extern "C" const void * loadVp(uint32_t bank, uint32_t offset) +{ + GET_TLS(); + return &static_cast<const uint8_t *>(sc->mSlots[bank]->getPtr())[offset]; +} + + + +static void SC_color(float r, float g, float b, float a) +{ + glColor4f(r, g, b, a); +} + + +extern "C" void materialDiffuse(float r, float g, float b, float a) +{ + float v[] = {r, g, b, a}; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); +} + +extern "C" void materialSpecular(float r, float g, float b, float a) +{ + float v[] = {r, g, b, a}; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); +} + +extern "C" void lightPosition(float x, float y, float z, float w) +{ + float v[] = {x, y, z, w}; + glLightfv(GL_LIGHT0, GL_POSITION, v); +} + +extern "C" void materialShininess(float s) +{ + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); +} + +extern "C" void uploadToTexture(RsAllocation va, uint32_t baseMipLevel) +{ + GET_TLS(); + rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); +} + +extern "C" void enable(uint32_t p) +{ + glEnable(p); +} + +extern "C" void disable(uint32_t p) +{ + glDisable(p); +} + + + +static void SC_ClearColor(float r, float g, float b, float a) +{ + //LOGE("c %f %f %f %f", r, g, b, a); + GET_TLS(); + sc->mEnviroment.mClearColor[0] = r; + sc->mEnviroment.mClearColor[1] = g; + sc->mEnviroment.mClearColor[2] = b; + sc->mEnviroment.mClearColor[3] = a; +} + + + +////////////////////////////////////////////////////////////////////////////// +// Class implementation +////////////////////////////////////////////////////////////////////////////// + +ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { + // IO + { "loadI32", (void *)&SC_loadI32, + "int", "(int, int)" }, + //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" }, + { "loadF", (void *)&SC_loadF, + "float", "(int, int)" }, + { "loadVec4", (void *)&SC_loadVec4, + "void", "(int, int, float *)" }, + { "loadMatrix", (void *)&SC_loadMatrix, + "void", "(int, int, float *)" }, + { "storeI32", (void *)&SC_storeI32, + "void", "(int, int, int)" }, + //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" }, + { "storeF", (void *)&SC_storeF, + "void", "(int, int, float)" }, + { "storeVec4", (void *)&SC_storeVec4, + "void", "(int, int, float *)" }, + { "storeMatrix", (void *)&SC_storeMatrix, + "void", "(int, int, float *)" }, + + // math + { "sinf", (void *)&sinf, + "float", "(float)" }, + { "cosf", (void *)&cosf, + "float", "(float)" }, + { "fabs", (void *)&fabs, + "float", "(float)" }, + { "randf", (void *)&SC_randf, + "float", "(float)" }, + + // matrix + { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity, + "void", "(float *mat)" }, + { "matrixLoadFloat", (void *)&SC_matrixLoadFloat, + "void", "(float *mat, float *f)" }, + { "matrixLoadMat", (void *)&SC_matrixLoadMat, + "void", "(float *mat, float *newmat)" }, + { "matrixLoadRotate", (void *)&SC_matrixLoadRotate, + "void", "(float *mat, float rot, float x, float y, float z)" }, + { "matrixLoadScale", (void *)&SC_matrixLoadScale, + "void", "(float *mat, float x, float y, float z)" }, + { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate, + "void", "(float *mat, float x, float y, float z)" }, + { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply, + "void", "(float *mat, float *lhs, float *rhs)" }, + { "matrixMultiply", (void *)&SC_matrixMultiply, + "void", "(float *mat, float *rhs)" }, + { "matrixRotate", (void *)&SC_matrixRotate, + "void", "(float *mat, float rot, float x, float y, float z)" }, + { "matrixScale", (void *)&SC_matrixScale, + "void", "(float *mat, float x, float y, float z)" }, + { "matrixTranslate", (void *)&SC_matrixTranslate, + "void", "(float *mat, float x, float y, float z)" }, + + // context + { "bindProgramFragment", (void *)&SC_bindProgramFragment, + "void", "(int)" }, + { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore, + "void", "(int)" }, + { "bindSampler", (void *)&SC_bindSampler, + "void", "(int, int, int)" }, + { "bindTexture", (void *)&SC_bindTexture, + "void", "(int, int, int)" }, + + // drawing + { "drawQuad", (void *)&SC_drawQuad, + "void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" }, + { "drawTriangleArray", (void *)&SC_drawTriangleArray, + "void", "(int ialloc, int count)" }, + { "drawTriangleMesh", (void *)&SC_drawTriangleMesh, + "void", "(int mesh)" }, + { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange, + "void", "(int mesh, int start, int count)" }, + + + // misc + { "pfClearColor", (void *)&SC_ClearColor, + "void", "(float, float, float, float)" }, + + { "color", (void *)&SC_color, + "void", "(float, float, float, float)" }, + + { NULL, NULL, NULL, NULL } +}; + +const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) +{ + ScriptCState::SymbolTable_t *syms = gSyms; + + while (syms->mPtr) { + if (!strcmp(syms->mName, sym)) { + return syms; + } + syms++; + } + return NULL; +} + +void ScriptCState::appendDecls(String8 *str) +{ + ScriptCState::SymbolTable_t *syms = gSyms; + while (syms->mPtr) { + str->append(syms->mRet); + str->append(" "); + str->append(syms->mName); + str->append(syms->mParam); + str->append(";\n"); + syms++; + } +} + + |