From 8ad0010d6e3ce416cd8148a458d7457c1e59e770 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 4 Jun 2009 14:35:01 -0700 Subject: Set the RS thread priority. --- libs/rs/rsContext.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'libs/rs/rsContext.cpp') diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index abc5f456f8ea..c915c56a7246 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -179,7 +179,20 @@ Context::Context(Device *dev, Surface *sur) gCon = this; LOGE("CC 2"); - int status = pthread_create(&mThreadId, NULL, threadProc, this); + int status; + pthread_attr_t threadAttr; + + status = pthread_attr_init(&threadAttr); + if (status) { + LOGE("Failed to init thread attribute."); + return; + } + + sched_param sparam; + sparam.sched_priority = ANDROID_PRIORITY_DISPLAY; + pthread_attr_setschedparam(&threadAttr, &sparam); + + status = pthread_create(&mThreadId, &threadAttr, threadProc, this); if (status) { LOGE("Failed to start rs context thread."); } @@ -191,8 +204,7 @@ Context::Context(Device *dev, Surface *sur) } LOGE("CC 4"); - - + pthread_attr_destroy(&threadAttr); } Context::~Context() -- cgit v1.2.3-59-g8ed1b From a09f11d6c641726b61f80c15230a18d31c146fec Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 4 Jun 2009 17:58:03 -0700 Subject: 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. --- libs/rs/RenderScriptEnv.h | 2 +- libs/rs/java/Fountain/res/raw/fountain.c | 5 ++--- libs/rs/rsContext.cpp | 33 +++++++++++++------------------- libs/rs/rsContext.h | 2 +- libs/rs/rsScript.h | 2 +- libs/rs/rsScriptC.cpp | 4 ++-- libs/rs/rsScriptC.h | 2 +- libs/rs/rsThreadIO.cpp | 5 ++++- libs/rs/rsThreadIO.h | 4 +++- 9 files changed, 28 insertions(+), 31 deletions(-) (limited to 'libs/rs/rsContext.cpp') diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h index dfca56c34679..1bf5f22d35ee 100644 --- a/libs/rs/RenderScriptEnv.h +++ b/libs/rs/RenderScriptEnv.h @@ -87,7 +87,7 @@ typedef struct { 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 7bf50339a09e..c9408d6afe9b 100644 --- a/libs/rs/java/Fountain/res/raw/fountain.c +++ b/libs/rs/java/Fountain/res/raw/fountain.c @@ -65,7 +65,7 @@ main(con, ft, launchID) { 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 @@ main(con, ft, launchID) { 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 @@ main(con, ft, launchID) { } drawTriangleArray(con, loadI32(con, 0, 5), drawCount); + return 1; } diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index c915c56a7246..ec4a30928d52 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -57,17 +57,19 @@ void Context::initEGL() 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 @@ void Context::runRootScript() 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 @@ void Context::runRootScript() 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 @@ void * Context::threadProc(void *vrsc) 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 @@ void * Context::threadProc(void *vrsc) glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(rsc->mDisplay, rsc->mSurface); eglTerminate(rsc->mDisplay); - - LOGE("TP 7"); - return NULL; } @@ -257,7 +250,7 @@ void Context::setVertex(ProgramVertex *pv) } /////////////////////////////////////////////////////////////////////////////////////////// -// +// namespace android { namespace renderscript { diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 9d96a0652de5..64717e42b71a 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -108,7 +108,7 @@ private: void initEGL(); - void runRootScript(); + bool runRootScript(); static void * threadProc(void *); diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index 193287081322..0229860a15f5 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -46,7 +46,7 @@ public: ObjectBaseRef 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 2c7d88415f5c..36019abac21e 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -387,10 +387,10 @@ static rsc_FunctionTable scriptCPtrTable = { }; -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 c58dcf9d4b1b..283007ef6cab 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -37,7 +37,7 @@ public: 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 d5ac70b18409..23c808a6d4d0 100644 --- a/libs/rs/rsThreadIO.cpp +++ b/libs/rs/rsThreadIO.cpp @@ -34,12 +34,14 @@ ThreadIO::~ThreadIO() { } -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 @@ void ThreadIO::playCoreCommands(Context *con) mToCore.next(); //LOGE("playCoreCommands 5"); } + return ret; } diff --git a/libs/rs/rsThreadIO.h b/libs/rs/rsThreadIO.h index f8ba37db0d86..ae2ffc0e7525 100644 --- a/libs/rs/rsThreadIO.h +++ b/libs/rs/rsThreadIO.h @@ -35,7 +35,9 @@ public: 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; -- cgit v1.2.3-59-g8ed1b