Add support for scripts to return an animation flag. This allows them to indicate they are generating changing content and the rs thread to sleep if the content is static.
diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h
index dfca56c..1bf5f22 100644
--- a/libs/rs/RenderScriptEnv.h
+++ b/libs/rs/RenderScriptEnv.h
@@ -87,7 +87,7 @@
void (*drawRect)(void *con, int32_t x1, int32_t x2, int32_t y1, int32_t y2);
} rsc_FunctionTable;
-typedef void (*rsc_RunScript)(void *con, const rsc_FunctionTable *, uint32_t launchID);
+typedef int (*rsc_RunScript)(void *con, const rsc_FunctionTable *, uint32_t launchID);
/* EnableCap */
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index 7bf5033..c9408d6 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -65,7 +65,7 @@
if (life) {
if (posy < (480 << 16)) {
- dstIdx = ct * 3 * 3;
+ dstIdx = drawCount * 9;
c = 0xffafcf | ((life >> lifeShift) << 24);
storeU32(con, 1, dstIdx, c);
@@ -79,8 +79,6 @@
storeU32(con, 1, dstIdx + 6, c);
storeI32(con, 1, dstIdx + 7, posx - 0x10000);
storeI32(con, 1, dstIdx + 8, posy + dy * 4);
-
- vertPtr = vertPtr + 36;
drawCount ++;
} else {
if (dy > 0) {
@@ -102,4 +100,5 @@
}
drawTriangleArray(con, loadI32(con, 0, 5), drawCount);
+ return 1;
}
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index c915c56..ec4a309 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -57,17 +57,19 @@
LOGE("EGL 5");
mContext = eglCreateContext(mDisplay, mConfig, NULL, NULL);
- eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
+ eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth);
eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight);
LOGE("EGL 9");
}
-void Context::runRootScript()
+bool Context::runRootScript()
{
rsAssert(mRootScript->mIsRoot);
+ glColor4f(1,1,1,1);
+ glEnable(GL_LIGHT0);
glViewport(0, 0, 320, 480);
float aspectH = 480.f / 320.f;
@@ -91,7 +93,7 @@
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glClearColor(mRootScript->mClearColor[0],
+ glClearColor(mRootScript->mClearColor[0],
mRootScript->mClearColor[1],
mRootScript->mClearColor[2],
mRootScript->mClearColor[3]);
@@ -99,8 +101,7 @@
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
- mRootScript->run(this, 0);
-
+ return mRootScript->run(this, 0);
}
void Context::setupCheck()
@@ -133,24 +134,19 @@
LOGE("TP 2");
rsc->mRunning = true;
+ bool mDraw = true;
while (!rsc->mExit) {
- gIO->playCoreCommands(rsc);
+ mDraw |= gIO->playCoreCommands(rsc);
- if (!rsc->mRootScript.get()) {
+ if (!mDraw || !rsc->mRootScript.get()) {
+ usleep(10000);
continue;
}
-
- glColor4f(1,1,1,1);
- glEnable(GL_LIGHT0);
-
if (rsc->mRootScript.get()) {
- rsc->runRootScript();
+ mDraw = rsc->runRootScript();
+ eglSwapBuffers(rsc->mDisplay, rsc->mSurface);
}
-
- eglSwapBuffers(rsc->mDisplay, rsc->mSurface);
-
- usleep(10000);
}
LOGE("TP 6");
@@ -158,9 +154,6 @@
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(rsc->mDisplay, rsc->mSurface);
eglTerminate(rsc->mDisplay);
-
- LOGE("TP 7");
-
return NULL;
}
@@ -257,7 +250,7 @@
}
///////////////////////////////////////////////////////////////////////////////////////////
-//
+//
namespace android {
namespace renderscript {
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 9d96a06..64717e4 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -108,7 +108,7 @@
void initEGL();
- void runRootScript();
+ bool runRootScript();
static void * threadProc(void *);
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index 1932870..0229860 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -46,7 +46,7 @@
ObjectBaseRef<Allocation> mSlots[16];
- virtual void run(Context *, uint32_t launchID) = 0;
+ virtual bool run(Context *, uint32_t launchID) = 0;
};
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 2c7d884..36019ab 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -387,10 +387,10 @@
};
-void ScriptC::run(Context *rsc, uint32_t launchID)
+bool ScriptC::run(Context *rsc, uint32_t launchID)
{
Env e = {rsc, this};
- mScript(&e, &scriptCPtrTable, launchID);
+ return mScript(&e, &scriptCPtrTable, launchID) != 0;
}
ScriptCState::ScriptCState()
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index c58dcf9..283007e 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -37,7 +37,7 @@
virtual ~ScriptC();
- virtual void run(Context *, uint32_t launchID);
+ virtual bool run(Context *, uint32_t launchID);
ACCscript* mAccScript;
diff --git a/libs/rs/rsThreadIO.cpp b/libs/rs/rsThreadIO.cpp
index d5ac70b..23c808a 100644
--- a/libs/rs/rsThreadIO.cpp
+++ b/libs/rs/rsThreadIO.cpp
@@ -34,12 +34,14 @@
{
}
-void ThreadIO::playCoreCommands(Context *con)
+bool ThreadIO::playCoreCommands(Context *con)
{
//LOGE("playCoreCommands 1");
uint32_t cmdID = 0;
uint32_t cmdSize = 0;
+ bool ret = false;
while(!mToCore.isEmpty()) {
+ ret = true;
//LOGE("playCoreCommands 2");
const void * data = mToCore.get(&cmdID, &cmdSize);
//LOGE("playCoreCommands 3 %i %i", cmdID, cmdSize);
@@ -50,6 +52,7 @@
mToCore.next();
//LOGE("playCoreCommands 5");
}
+ return ret;
}
diff --git a/libs/rs/rsThreadIO.h b/libs/rs/rsThreadIO.h
index f8ba37d..ae2ffc0 100644
--- a/libs/rs/rsThreadIO.h
+++ b/libs/rs/rsThreadIO.h
@@ -35,7 +35,9 @@
ThreadIO();
~ThreadIO();
- void playCoreCommands(Context *con);
+ // Plays back commands from the client.
+ // Returns true if any commands were processed.
+ bool playCoreCommands(Context *con);
LocklessCommandFifo mToCore;