am cc89ef3d: Merge change 26971 into eclair

Merge commit 'cc89ef3d6e9b1f9be657c9158ad04b8de104434c' into eclair-plus-aosp

* commit 'cc89ef3d6e9b1f9be657c9158ad04b8de104434c':
  Implement pause/resume for the RS thread.
This commit is contained in:
Jason Sams
2009-09-24 17:58:13 -07:00
committed by Android Git Automerger
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 {
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) {

View File

@@ -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

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
nElementBegin(JNIEnv *_env, jobject _this)
{
@@ -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 },

View File

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

View File

@@ -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();
}
}
}

View File

@@ -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;