am a1c3681f: am decc139b: Merge change I7a824efc into eclair

Merge commit 'a1c3681fb84e9baa3055709a18c635dc77c1b041' into eclair-mr2-plus-aosp

* commit 'a1c3681fb84e9baa3055709a18c635dc77c1b041':
  Support applications changing the surface attached to the RS.
This commit is contained in:
Jason Sams
2009-11-03 16:22:02 -08:00
committed by Android Git Automerger
6 changed files with 73 additions and 21 deletions

View File

@@ -80,6 +80,9 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
*/ */
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return // Surface will be destroyed when we return
if (mRS != null) {
mRS.contextSetSurface(null);
}
//Log.v(RenderScript.LOG_TAG, "surfaceDestroyed"); //Log.v(RenderScript.LOG_TAG, "surfaceDestroyed");
} }
@@ -88,6 +91,9 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* not normally called or subclassed by clients of RSSurfaceView. * not normally called or subclassed by clients of RSSurfaceView.
*/ */
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mRS != null) {
mRS.contextSetSurface(holder.getSurface());
}
//Log.v(RenderScript.LOG_TAG, "surfaceChanged"); //Log.v(RenderScript.LOG_TAG, "surfaceChanged");
} }

View File

@@ -64,6 +64,7 @@ public class RenderScript {
native void nDeviceSetConfig(int dev, int param, int value); native void nDeviceSetConfig(int dev, int param, int value);
native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth); native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
native void nContextDestroy(int con); native void nContextDestroy(int con);
native void nContextSetSurface(Surface sur);
native void nContextBindRootScript(int script); native void nContextBindRootScript(int script);
native void nContextBindSampler(int sampler, int slot); native void nContextBindSampler(int sampler, int slot);
@@ -276,6 +277,11 @@ public class RenderScript {
mMessageThread.start(); mMessageThread.start();
} }
public void contextSetSurface(Surface sur) {
mSurface = sur;
nContextSetSurface(mSurface);
}
public void destroy() { public void destroy() {
nContextDeinitToClient(); nContextDeinitToClient();
mMessageThread.mRun = false; mMessageThread.mRun = false;

View File

@@ -170,6 +170,24 @@ nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver, jbo
return (jint)rsContextCreate((RsDevice)dev, window, ver, useDepth); return (jint)rsContextCreate((RsDevice)dev, window, ver, useDepth);
} }
static void
nContextSetSurface(JNIEnv *_env, jobject _this, jobject wnd)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
LOG_API("nContextSetSurface, con(%p), surface(%p)", con, (Surface *)wnd);
Surface * window = NULL;
if (wnd == NULL) {
} else {
jclass surface_class = _env->FindClass("android/view/Surface");
jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I");
window = (Surface*)_env->GetIntField(wnd, surfaceFieldID);
}
rsContextSetSurface(con, window);
}
static void static void
nContextDestroy(JNIEnv *_env, jobject _this, jint con) nContextDestroy(JNIEnv *_env, jobject _this, jint con)
{ {
@@ -1328,6 +1346,7 @@ static JNINativeMethod methods[] = {
{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, {"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
{"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 },
{"nContextSetSurface", "(Landroid/view/Surface;)V", (void*)nContextSetSurface },
{"nContextDestroy", "(I)V", (void*)nContextDestroy }, {"nContextDestroy", "(I)V", (void*)nContextDestroy },
{"nContextPause", "()V", (void*)nContextPause }, {"nContextPause", "()V", (void*)nContextPause },
{"nContextResume", "()V", (void*)nContextResume }, {"nContextResume", "()V", (void*)nContextResume },

View File

@@ -36,6 +36,10 @@ ContextPause {
ContextResume { ContextResume {
} }
ContextSetSurface {
param void *sur
}
AssignName { AssignName {
param void *obj param void *obj
param const char *name param const char *name

View File

@@ -85,17 +85,6 @@ void Context::initEGL()
} }
//eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs); //eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
if (mWndSurface) {
mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
} else {
mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig,
android_createDisplaySurface(),
NULL);
}
checkEglError("eglCreateWindowSurface");
if (mEGL.mSurface == EGL_NO_SURFACE) {
LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
}
mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL); mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
checkEglError("eglCreateContext"); checkEglError("eglCreateContext");
@@ -104,10 +93,10 @@ void Context::initEGL()
} }
gGLContextCount++; gGLContextCount++;
EGLBoolean ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext); if (mWndSurface) {
checkEglError("eglCreateContext", ret); setSurface(mWndSurface);
if (mEGL.mContext == EGL_NO_CONTEXT) { } else {
LOGE("eglCreateContext returned EGL_NO_CONTEXT"); setSurface((Surface *)android_createDisplaySurface());
} }
eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth); eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
@@ -134,12 +123,7 @@ void Context::initEGL()
void Context::deinitEGL() void Context::deinitEGL()
{ {
EGLBoolean ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); setSurface(NULL);
checkEglError("eglCreateContext", ret);
if (mEGL.mContext == EGL_NO_CONTEXT) {
LOGE("eglCreateContext returned EGL_NO_CONTEXT");
}
eglDestroyContext(mEGL.mDisplay, mEGL.mContext); eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
checkEglError("eglDestroyContext"); checkEglError("eglDestroyContext");
@@ -311,6 +295,7 @@ void * Context::threadProc(void *vrsc)
while (!rsc->mExit) { while (!rsc->mExit) {
mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw); mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw);
mDraw &= (rsc->mRootScript.get() != NULL); mDraw &= (rsc->mRootScript.get() != NULL);
mDraw &= (rsc->mWndSurface != NULL);
if (mDraw) { if (mDraw) {
mDraw = rsc->runRootScript() && !rsc->mPaused; mDraw = rsc->runRootScript() && !rsc->mPaused;
@@ -441,6 +426,32 @@ Context::~Context()
objDestroyOOBDestroy(); objDestroyOOBDestroy();
} }
void Context::setSurface(Surface *sur)
{
EGLBoolean ret;
if (mEGL.mSurface != NULL) {
ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
checkEglError("eglMakeCurrent", ret);
ret = eglDestroySurface(mEGL.mDisplay, mEGL.mSurface);
checkEglError("eglDestroySurface", ret);
mEGL.mSurface = NULL;
}
mWndSurface = sur;
if (mWndSurface != NULL) {
mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
checkEglError("eglCreateWindowSurface");
if (mEGL.mSurface == EGL_NO_SURFACE) {
LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
}
ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
checkEglError("eglMakeCurrent", ret);
}
}
void Context::pause() void Context::pause()
{ {
mPaused = true; mPaused = true;
@@ -756,6 +767,11 @@ void rsi_ContextResume(Context *rsc)
rsc->resume(); rsc->resume();
} }
void rsi_ContextSetSurface(Context *rsc, void *sur)
{
rsc->setSurface((Surface *)sur);
}
} }
} }

View File

@@ -94,6 +94,7 @@ public:
void pause(); void pause();
void resume(); void resume();
void setSurface(Surface *sur);
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);