diff options
| -rw-r--r-- | graphics/java/android/renderscript/RSSurfaceView.java | 11 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 10 | ||||
| -rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 18 | ||||
| -rw-r--r-- | libs/rs/rs.spec | 6 | ||||
| -rw-r--r-- | libs/rs/rsContext.cpp | 24 | ||||
| -rw-r--r-- | libs/rs/rsContext.h | 4 |
6 files changed, 70 insertions, 3 deletions
diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java index 3d6acc9..b46a749 100644 --- a/graphics/java/android/renderscript/RSSurfaceView.java +++ b/graphics/java/android/renderscript/RSSurfaceView.java @@ -36,6 +36,7 @@ import android.view.SurfaceView; **/ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mSurfaceHolder; + private RenderScript mRS; /** * 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. */ public void onPause() { + if(mRS != null) { + mRS.pause(); + } 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. */ public void onResume() { + if(mRS != null) { + mRS.resume(); + } Log.v(RenderScript.LOG_TAG, "onResume"); } @@ -138,8 +145,8 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback while ((sur == null) || (mSurfaceHolder == null)) { sur = getHolder().getSurface(); } - RenderScript rs = new RenderScript(sur, useDepth, forceSW); - return rs; + mRS = new RenderScript(sur, useDepth, forceSW); + return mRS; } public RenderScript createRenderScript(boolean useDepth) { diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index b7cd21b..f815f52 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -73,6 +73,8 @@ public class RenderScript { native void nContextBindProgramRaster(int pr); native void nContextAddDefineI32(String name, int value); native void nContextAddDefineF(String name, float value); + native void nContextPause(); + native void nContextResume(); native void nAssignName(int obj, byte[] name); native void nObjDestroy(int id); @@ -217,6 +219,14 @@ public class RenderScript { mDev = 0; } + void pause() { + nContextPause(); + } + + void resume() { + nContextResume(); + } + ////////////////////////////////////////////////////////////////////////////////// // File diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index f86d86a..9054b65 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -179,6 +179,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 nElementBegin(JNIEnv *_env, jobject _this) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); @@ -1282,6 +1298,8 @@ static JNINativeMethod methods[] = { {"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, {"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate }, {"nContextDestroy", "(I)V", (void*)nContextDestroy }, +{"nContextPause", "()V", (void*)nContextPause }, +{"nContextResume", "()V", (void*)nContextResume }, {"nAssignName", "(I[B)V", (void*)nAssignName }, {"nObjDestroy", "(I)V", (void*)nObjDestroy }, {"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB }, diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 8cdf2b7..a393e2f 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -30,6 +30,12 @@ ContextSetDefineI32 { param int32_t value } +ContextPause { + } + +ContextResume { + } + AssignName { param void *obj param const char *name diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index e3236c4..2fe762c 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -251,7 +251,7 @@ void * Context::threadProc(void *vrsc) mDraw &= (rsc->mRootScript.get() != NULL); if (mDraw) { - mDraw = rsc->runRootScript(); + mDraw = rsc->runRootScript() && !rsc->mPaused; if (rsc->logTimes) { rsc->timerSet(RS_TIMER_CLEAR_SWAP); } @@ -285,6 +285,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth) mRunning = false; mExit = false; mUseDepth = useDepth; + mPaused = false; int status; pthread_attr_t threadAttr; @@ -328,6 +329,7 @@ Context::~Context() { LOGV("Context::~Context"); mExit = true; + mPaused = false; void *res; mIO.shutdown(); @@ -342,6 +344,16 @@ Context::~Context() objDestroyOOBDestroy(); } +void Context::pause() +{ + mPaused = true; +} + +void Context::resume() +{ + mPaused = false; +} + void Context::setRootScript(Script *s) { mRootScript.set(s); @@ -578,6 +590,16 @@ void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value) rsc->addFloatDefine(name, value); } +void rsi_ContextPause(Context *rsc) +{ + rsc->pause(); +} + +void rsi_ContextResume(Context *rsc) +{ + rsc->resume(); +} + } } diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 8cabf87..0a886cd 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -88,6 +88,9 @@ public: void setupCheck(); void allocationCheck(const Allocation *); + void pause(); + void resume(); + void assignName(ObjectBase *obj, const char *name, uint32_t len); void removeName(ObjectBase *obj); ObjectBase * lookupName(const char *name) const; @@ -171,6 +174,7 @@ protected: bool mRunning; bool mExit; bool mUseDepth; + bool mPaused; pthread_t mThreadId; |
