Merge change 26971 into eclair

* changes:
  Implement pause/resume for the RS thread.
This commit is contained in:
Android (Google) Code Review
2009-09-24 20:50:39 -04:00
6 changed files with 70 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ import android.view.SurfaceView;
**/ **/
public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback { public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mSurfaceHolder; private SurfaceHolder mSurfaceHolder;
private RenderScript mRS;
/** /**
* Standard View constructor. In order to render something, you * Standard View constructor. In order to render something, you
@@ -97,6 +98,9 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* Must not be called before a renderer has been set. * Must not be called before a renderer has been set.
*/ */
public void onPause() { public void onPause() {
if(mRS != null) {
mRS.pause();
}
Log.v(RenderScript.LOG_TAG, "onPause"); Log.v(RenderScript.LOG_TAG, "onPause");
} }
@@ -108,6 +112,9 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* Must not be called before a renderer has been set. * Must not be called before a renderer has been set.
*/ */
public void onResume() { public void onResume() {
if(mRS != null) {
mRS.resume();
}
Log.v(RenderScript.LOG_TAG, "onResume"); Log.v(RenderScript.LOG_TAG, "onResume");
} }
@@ -138,8 +145,8 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
while ((sur == null) || (mSurfaceHolder == null)) { while ((sur == null) || (mSurfaceHolder == null)) {
sur = getHolder().getSurface(); sur = getHolder().getSurface();
} }
RenderScript rs = new RenderScript(sur, useDepth, forceSW); mRS = new RenderScript(sur, useDepth, forceSW);
return rs; return mRS;
} }
public RenderScript createRenderScript(boolean useDepth) { public RenderScript createRenderScript(boolean useDepth) {

View File

@@ -73,6 +73,8 @@ public class RenderScript {
native void nContextBindProgramRaster(int pr); native void nContextBindProgramRaster(int pr);
native void nContextAddDefineI32(String name, int value); native void nContextAddDefineI32(String name, int value);
native void nContextAddDefineF(String name, float value); native void nContextAddDefineF(String name, float value);
native void nContextPause();
native void nContextResume();
native void nAssignName(int obj, byte[] name); native void nAssignName(int obj, byte[] name);
native void nObjDestroy(int id); native void nObjDestroy(int id);
@@ -217,6 +219,14 @@ public class RenderScript {
mDev = 0; mDev = 0;
} }
void pause() {
nContextPause();
}
void resume() {
nContextResume();
}
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
// File // File

View File

@@ -178,6 +178,22 @@ nContextDestroy(JNIEnv *_env, jobject _this, jint con)
} }
static void
nContextPause(JNIEnv *_env, jobject _this)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
LOG_API("nContextPause, con(%p)", con);
rsContextPause(con);
}
static void
nContextResume(JNIEnv *_env, jobject _this)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
LOG_API("nContextResume, con(%p)", con);
rsContextResume(con);
}
static void static void
nElementBegin(JNIEnv *_env, jobject _this) nElementBegin(JNIEnv *_env, jobject _this)
{ {
@@ -1282,6 +1298,8 @@ static JNINativeMethod methods[] = {
{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, {"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
{"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate }, {"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate },
{"nContextDestroy", "(I)V", (void*)nContextDestroy }, {"nContextDestroy", "(I)V", (void*)nContextDestroy },
{"nContextPause", "()V", (void*)nContextPause },
{"nContextResume", "()V", (void*)nContextResume },
{"nAssignName", "(I[B)V", (void*)nAssignName }, {"nAssignName", "(I[B)V", (void*)nAssignName },
{"nObjDestroy", "(I)V", (void*)nObjDestroy }, {"nObjDestroy", "(I)V", (void*)nObjDestroy },
{"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB }, {"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB },

View File

@@ -30,6 +30,12 @@ ContextSetDefineI32 {
param int32_t value param int32_t value
} }
ContextPause {
}
ContextResume {
}
AssignName { AssignName {
param void *obj param void *obj
param const char *name param const char *name

View File

@@ -251,7 +251,7 @@ void * Context::threadProc(void *vrsc)
mDraw &= (rsc->mRootScript.get() != NULL); mDraw &= (rsc->mRootScript.get() != NULL);
if (mDraw) { if (mDraw) {
mDraw = rsc->runRootScript(); mDraw = rsc->runRootScript() && !rsc->mPaused;
if (rsc->logTimes) { if (rsc->logTimes) {
rsc->timerSet(RS_TIMER_CLEAR_SWAP); rsc->timerSet(RS_TIMER_CLEAR_SWAP);
} }
@@ -285,6 +285,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth)
mRunning = false; mRunning = false;
mExit = false; mExit = false;
mUseDepth = useDepth; mUseDepth = useDepth;
mPaused = false;
int status; int status;
pthread_attr_t threadAttr; pthread_attr_t threadAttr;
@@ -328,6 +329,7 @@ Context::~Context()
{ {
LOGV("Context::~Context"); LOGV("Context::~Context");
mExit = true; mExit = true;
mPaused = false;
void *res; void *res;
mIO.shutdown(); mIO.shutdown();
@@ -342,6 +344,16 @@ Context::~Context()
objDestroyOOBDestroy(); objDestroyOOBDestroy();
} }
void Context::pause()
{
mPaused = true;
}
void Context::resume()
{
mPaused = false;
}
void Context::setRootScript(Script *s) void Context::setRootScript(Script *s)
{ {
mRootScript.set(s); mRootScript.set(s);
@@ -578,6 +590,16 @@ void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value)
rsc->addFloatDefine(name, value); rsc->addFloatDefine(name, value);
} }
void rsi_ContextPause(Context *rsc)
{
rsc->pause();
}
void rsi_ContextResume(Context *rsc)
{
rsc->resume();
}
} }
} }

View File

@@ -88,6 +88,9 @@ public:
void setupCheck(); void setupCheck();
void allocationCheck(const Allocation *); void allocationCheck(const Allocation *);
void pause();
void resume();
void assignName(ObjectBase *obj, const char *name, uint32_t len); void assignName(ObjectBase *obj, const char *name, uint32_t len);
void removeName(ObjectBase *obj); void removeName(ObjectBase *obj);
ObjectBase * lookupName(const char *name) const; ObjectBase * lookupName(const char *name) const;
@@ -171,6 +174,7 @@ protected:
bool mRunning; bool mRunning;
bool mExit; bool mExit;
bool mUseDepth; bool mUseDepth;
bool mPaused;
pthread_t mThreadId; pthread_t mThreadId;