From 4c2e4c80ce519e09e5b00fd7533e64a834d70639 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Tue, 7 Feb 2012 15:32:08 -0800 Subject: Implement RS VSync on new vsync infrastructure. Change-Id: I662159a086a56e28732dd64a3a3cb30f8d4b72b1 Replace lockless fifo from server to client with sockets. Change-Id: I99a4ab4f18496c0fbac96ee7b8099797af4712ea --- libs/rs/rsContext.cpp | 84 +++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 36 deletions(-) (limited to 'libs/rs/rsContext.cpp') diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index ad2ff0ff0dac..04284dd964b0 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -18,6 +18,7 @@ #include "rsContext.h" #include "rsThreadIO.h" #include +#include #include #include @@ -245,42 +246,55 @@ void * Context::threadProc(void *vrsc) { } rsc->mRunning = true; - bool mDraw = true; - bool doWait = true; - - uint64_t targetTime = rsc->getTime(); - while (!rsc->mExit) { - uint64_t waitTime = 0; - uint64_t now = rsc->getTime(); - if (!doWait) { - if (now < targetTime) { - waitTime = targetTime - now; - doWait = true; - } + if (!rsc->mIsGraphicsContext) { + while (!rsc->mExit) { + rsc->mIO.playCoreCommands(rsc, true, -1); } + } else { +#ifndef ANDROID_RS_SERIALIZE + DisplayEventReceiver displayEvent; + DisplayEventReceiver::Event eventBuffer[1]; +#endif + int vsyncRate = 0; + int targetRate = 0; - mDraw |= rsc->mIO.playCoreCommands(rsc, doWait, waitTime); - mDraw &= (rsc->mRootScript.get() != NULL); - mDraw &= rsc->mHasSurface; - - if (mDraw && rsc->mIsGraphicsContext) { - uint64_t delay = rsc->runRootScript() * 1000000; - targetTime = rsc->getTime() + delay; - doWait = (delay == 0); + bool drawOnce = false; + while (!rsc->mExit) { + rsc->timerSet(RS_TIMER_IDLE); - if (rsc->props.mLogVisual) { - rsc->displayDebugStats(); +#ifndef ANDROID_RS_SERIALIZE + if (vsyncRate != targetRate) { + displayEvent.setVsyncRate(targetRate); + vsyncRate = targetRate; + } + if (targetRate) { + drawOnce |= rsc->mIO.playCoreCommands(rsc, true, displayEvent.getFd()); + while (displayEvent.getEvents(eventBuffer, 1) != 0) { + //ALOGE("vs2 time past %lld", (rsc->getTime() - eventBuffer[0].header.timestamp) / 1000000); + } + } else +#endif + { + drawOnce |= rsc->mIO.playCoreCommands(rsc, true, -1); } - mDraw = !rsc->mPaused; - rsc->timerSet(RS_TIMER_CLEAR_SWAP); - rsc->mHal.funcs.swap(rsc); - rsc->timerFrame(); - rsc->timerSet(RS_TIMER_INTERNAL); - rsc->timerPrint(); - rsc->timerReset(); - } else { - doWait = true; + if ((rsc->mRootScript.get() != NULL) && rsc->mHasSurface && + (targetRate || drawOnce) && !rsc->mPaused) { + + drawOnce = false; + targetRate = ((rsc->runRootScript() + 15) / 16); + + if (rsc->props.mLogVisual) { + rsc->displayDebugStats(); + } + + rsc->timerSet(RS_TIMER_CLEAR_SWAP); + rsc->mHal.funcs.swap(rsc); + rsc->timerFrame(); + rsc->timerSet(RS_TIMER_INTERNAL); + rsc->timerPrint(); + rsc->timerReset(); + } } } @@ -315,8 +329,8 @@ void Context::destroyWorkerThreadResources() { mFBOCache.deinit(this); } ObjectBase::freeAllChildren(this); - //ALOGV("destroyWorkerThreadResources 2"); mExit = true; + //ALOGV("destroyWorkerThreadResources 2"); } void Context::printWatchdogInfo(void *ctx) { @@ -382,7 +396,7 @@ bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { pthread_mutex_lock(&gInitMutex); mIO.init(); - mIO.setTimoutCallback(printWatchdogInfo, this, 2e9); + mIO.setTimeoutCallback(printWatchdogInfo, this, 2e9); dev->addContext(this); mDev = dev; @@ -434,14 +448,12 @@ Context::~Context() { ALOGV("%p Context::~Context", this); if (!mIsContextLite) { - mIO.coreFlush(); - rsAssert(mExit); - mExit = true; mPaused = false; void *res; mIO.shutdown(); int status = pthread_join(mThreadId, &res); + rsAssert(mExit); if (mHal.funcs.shutdownDriver) { mHal.funcs.shutdownDriver(this); -- cgit v1.2.3-59-g8ed1b