summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/rsContext.cpp60
-rw-r--r--libs/rs/rsContext.h8
-rw-r--r--libs/rs/rsScript.h2
-rw-r--r--libs/rs/rsScriptC.cpp6
-rw-r--r--libs/rs/rsScriptC.h2
5 files changed, 45 insertions, 33 deletions
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 3d2caff..f815badb 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -124,14 +124,14 @@ void Context::deinitEGL()
}
-bool Context::runScript(Script *s, uint32_t launchID)
+uint32_t Context::runScript(Script *s, uint32_t launchID)
{
ObjectBaseRef<ProgramFragment> frag(mFragment);
ObjectBaseRef<ProgramVertex> vtx(mVertex);
ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore);
ObjectBaseRef<ProgramRaster> raster(mRaster);
- bool ret = s->run(this, launchID);
+ uint32_t ret = s->run(this, launchID);
mFragment.set(frag);
mVertex.set(vtx);
@@ -141,11 +141,9 @@ bool Context::runScript(Script *s, uint32_t launchID)
}
-bool Context::runRootScript()
+uint32_t Context::runRootScript()
{
- if (props.mLogTimes) {
- timerSet(RS_TIMER_CLEAR_SWAP);
- }
+ timerSet(RS_TIMER_CLEAR_SWAP);
rsAssert(mRootScript->mEnviroment.mIsRoot);
eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
@@ -165,11 +163,9 @@ bool Context::runRootScript()
glClear(GL_COLOR_BUFFER_BIT);
}
- if (this->props.mLogTimes) {
- timerSet(RS_TIMER_SCRIPT);
- }
+ timerSet(RS_TIMER_SCRIPT);
mStateFragmentStore.mLast.clear();
- bool ret = runScript(mRootScript.get(), 0);
+ uint32_t ret = runScript(mRootScript.get(), 0);
GLenum err = glGetError();
if (err != GL_NO_ERROR) {
@@ -223,13 +219,19 @@ void Context::timerPrint()
total += mTimers[ct];
}
uint64_t frame = mTimeFrame - mTimeLastFrame;
+ mTimeMSLastFrame = frame / 1000000;
+ mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000;
+ mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000;
- LOGV("RS: Frame (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli), Idle %2.1f (%lli), Internal %2.1f (%lli)",
- frame / 1000000,
- 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000,
- 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimers[RS_TIMER_CLEAR_SWAP] / 1000000,
- 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
- 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
+
+ if (props.mLogTimes) {
+ LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli)",
+ mTimeMSLastFrame,
+ 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript,
+ 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap,
+ 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
+ 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
+ }
}
void Context::setupCheck()
@@ -263,6 +265,7 @@ void * Context::threadProc(void *vrsc)
rsc->mNativeThreadId = gettid();
setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
+ rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
rsc->props.mLogTimes = getProp("debug.rs.profile");
rsc->props.mLogScripts = getProp("debug.rs.script");
@@ -297,22 +300,26 @@ void * Context::threadProc(void *vrsc)
mDraw &= (rsc->mRootScript.get() != NULL);
mDraw &= (rsc->mWndSurface != NULL);
+ uint32_t targetTime = 0;
if (mDraw) {
- mDraw = rsc->runRootScript() && !rsc->mPaused;
- if (rsc->props.mLogTimes) {
- rsc->timerSet(RS_TIMER_CLEAR_SWAP);
- }
+ targetTime = rsc->runRootScript();
+ mDraw = targetTime && !rsc->mPaused;
+ rsc->timerSet(RS_TIMER_CLEAR_SWAP);
eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
- if (rsc->props.mLogTimes) {
- rsc->timerFrame();
- rsc->timerSet(RS_TIMER_INTERNAL);
- rsc->timerPrint();
- rsc->timerReset();
- }
+ rsc->timerFrame();
+ rsc->timerSet(RS_TIMER_INTERNAL);
+ rsc->timerPrint();
+ rsc->timerReset();
}
if (rsc->mObjDestroy.mNeedToEmpty) {
rsc->objDestroyOOBRun();
}
+ if (rsc->mThreadPriority > 0 && targetTime) {
+ int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000;
+ if (t > 0) {
+ usleep(t);
+ }
+ }
}
LOGV("RS Thread exiting");
@@ -348,6 +355,7 @@ void Context::setPriority(int32_t p)
// the wallpapers can become completly unresponsive at times.
// This is probably not what we want for something the user is actively
// looking at.
+ mThreadPriority = p;
#if 0
SchedPolicy pol = SP_FOREGROUND;
if (p > 0) {
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index a5e73da..708551c 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -108,7 +108,7 @@ public:
uint32_t getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait);
bool sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace);
- bool runScript(Script *s, uint32_t launchID);
+ uint32_t runScript(Script *s, uint32_t launchID);
void initToClient();
void deinitToClient();
@@ -197,6 +197,7 @@ protected:
uint32_t mWidth;
uint32_t mHeight;
+ int32_t mThreadPriority;
bool mRunning;
bool mExit;
@@ -229,7 +230,7 @@ private:
void initEGL(bool useGL2);
void deinitEGL();
- bool runRootScript();
+ uint32_t runRootScript();
static void * threadProc(void *);
@@ -244,6 +245,9 @@ private:
uint64_t mTimeLast;
uint64_t mTimeFrame;
uint64_t mTimeLastFrame;
+ uint32_t mTimeMSLastFrame;
+ uint32_t mTimeMSLastScript;
+ uint32_t mTimeMSLastSwap;
};
}
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index bc40854..5f4a536 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -70,7 +70,7 @@ public:
virtual void setupScript() = 0;
- virtual bool run(Context *, uint32_t launchID) = 0;
+ virtual uint32_t run(Context *, uint32_t launchID) = 0;
};
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 073d98b..f11b862 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -60,7 +60,7 @@ void ScriptC::setupScript()
}
-bool ScriptC::run(Context *rsc, uint32_t launchIndex)
+uint32_t ScriptC::run(Context *rsc, uint32_t launchIndex)
{
Context::ScriptTLSStruct * tls =
(Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey);
@@ -85,9 +85,9 @@ bool ScriptC::run(Context *rsc, uint32_t launchIndex)
}
setupScript();
- bool ret = false;
+ uint32_t ret = 0;
tls->mScript = this;
- ret = mProgram.mScript(launchIndex) != 0;
+ ret = mProgram.mScript(launchIndex);
tls->mScript = NULL;
return ret;
}
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 69afc18..35abadf 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -55,7 +55,7 @@ public:
ACCscript* mAccScript;
virtual void setupScript();
- virtual bool run(Context *, uint32_t launchID);
+ virtual uint32_t run(Context *, uint32_t launchID);
};
class ScriptCState