am da8bb292: am 59175ac2: Merge change I81b1421a into eclair

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

* commit 'da8bb292db289bdd0e02b672daec09e2a3f9f462':
  Defer EGL init until the surface changed call comes in.  Pass w,h along with surface for verification of driver state.
This commit is contained in:
Jason Sams
2009-11-13 09:26:09 -08:00
committed by Android Git Automerger
10 changed files with 106 additions and 83 deletions

View File

@ -80,10 +80,10 @@ 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
Log.v(RenderScript.LOG_TAG, "surfaceDestroyed");
if (mRS != null) { if (mRS != null) {
mRS.contextSetSurface(null); mRS.contextSetSurface(0, 0, null);
} }
//Log.v(RenderScript.LOG_TAG, "surfaceDestroyed");
} }
/** /**
@ -91,10 +91,10 @@ 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) {
Log.v(RenderScript.LOG_TAG, "surfaceChanged");
if (mRS != null) { if (mRS != null) {
mRS.contextSetSurface(holder.getSurface()); mRS.contextSetSurface(w, h, holder.getSurface());
} }
//Log.v(RenderScript.LOG_TAG, "surfaceChanged");
} }
/** /**
@ -147,11 +147,8 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public RenderScript createRenderScript(boolean useDepth, boolean forceSW) { public RenderScript createRenderScript(boolean useDepth, boolean forceSW) {
Surface sur = null; Log.v(RenderScript.LOG_TAG, "createRenderScript");
while ((sur == null) || (mSurfaceHolder == null)) { mRS = new RenderScript(useDepth, forceSW);
sur = getHolder().getSurface();
}
mRS = new RenderScript(sur, useDepth, forceSW);
return mRS; return mRS;
} }
@ -160,6 +157,7 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
} }
public void destroyRenderScript() { public void destroyRenderScript() {
Log.v(RenderScript.LOG_TAG, "destroyRenderScript");
mRS.destroy(); mRS.destroy();
mRS = null; mRS = null;
} }

View File

@ -30,10 +30,12 @@ import android.view.Surface;
* *
**/ **/
public class RenderScript { public class RenderScript {
static final String LOG_TAG = "libRS_jni"; static final String LOG_TAG = "RenderScript_jni";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
@SuppressWarnings({"UnusedDeclaration", "deprecation"}) @SuppressWarnings({"UnusedDeclaration", "deprecation"})
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
int mWidth;
int mHeight;
@ -62,9 +64,9 @@ public class RenderScript {
native int nDeviceCreate(); native int nDeviceCreate();
native void nDeviceDestroy(int dev); native void nDeviceDestroy(int dev);
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, int ver, boolean useDepth);
native void nContextDestroy(int con); native void nContextDestroy(int con);
native void nContextSetSurface(Surface sur); native void nContextSetSurface(int w, int h, 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);
@ -259,27 +261,31 @@ public class RenderScript {
mRS.mMessageCallback.mID = msg; mRS.mMessageCallback.mID = msg;
mRS.mMessageCallback.run(); mRS.mMessageCallback.run();
} }
//Log.d("rs", "MessageThread msg " + msg + " v1 " + rbuf[0] + " v2 " + rbuf[1] + " v3 " +rbuf[2]); //Log.d(LOG_TAG, "MessageThread msg " + msg + " v1 " + rbuf[0] + " v2 " + rbuf[1] + " v3 " +rbuf[2]);
} }
Log.d("rs", "MessageThread exiting."); Log.d(LOG_TAG, "MessageThread exiting.");
} }
} }
public RenderScript(Surface sur, boolean useDepth, boolean forceSW) { public RenderScript(boolean useDepth, boolean forceSW) {
mSurface = sur; mSurface = null;
mWidth = 0;
mHeight = 0;
mDev = nDeviceCreate(); mDev = nDeviceCreate();
if(forceSW) { if(forceSW) {
nDeviceSetConfig(mDev, 0, 1); nDeviceSetConfig(mDev, 0, 1);
} }
mContext = nContextCreate(mDev, mSurface, 0, useDepth); mContext = nContextCreate(mDev, 0, useDepth);
Element.initPredefined(this); Element.initPredefined(this);
mMessageThread = new MessageThread(this); mMessageThread = new MessageThread(this);
mMessageThread.start(); mMessageThread.start();
} }
public void contextSetSurface(Surface sur) { public void contextSetSurface(int w, int h, Surface sur) {
mSurface = sur; mSurface = sur;
nContextSetSurface(mSurface); mWidth = w;
mHeight = h;
nContextSetSurface(w, h, mSurface);
} }
public void destroy() { public void destroy() {

View File

@ -151,30 +151,17 @@ nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
} }
static jint static jint
nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver, jboolean useDepth) nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jboolean useDepth)
{ {
LOG_API("nContextCreate"); LOG_API("nContextCreate");
return (jint)rsContextCreate((RsDevice)dev, ver, useDepth);
if (wnd == NULL) {
not_valid_surface:
doThrow(_env, "java/lang/IllegalArgumentException",
"Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
return 0;
}
jclass surface_class = _env->FindClass("android/view/Surface");
jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I");
Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID);
if (window == NULL)
goto not_valid_surface;
return (jint)rsContextCreate((RsDevice)dev, window, ver, useDepth);
} }
static void static void
nContextSetSurface(JNIEnv *_env, jobject _this, jobject wnd) nContextSetSurface(JNIEnv *_env, jobject _this, jint width, jint height, jobject wnd)
{ {
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
LOG_API("nContextSetSurface, con(%p), surface(%p)", con, (Surface *)wnd); LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Surface * window = NULL; Surface * window = NULL;
if (wnd == NULL) { if (wnd == NULL) {
@ -185,7 +172,7 @@ nContextSetSurface(JNIEnv *_env, jobject _this, jobject wnd)
window = (Surface*)_env->GetIntField(wnd, surfaceFieldID); window = (Surface*)_env->GetIntField(wnd, surfaceFieldID);
} }
rsContextSetSurface(con, window); rsContextSetSurface(con, width, height, window);
} }
static void static void
@ -1345,8 +1332,8 @@ static JNINativeMethod methods[] = {
{"nDeviceCreate", "()I", (void*)nDeviceCreate }, {"nDeviceCreate", "()I", (void*)nDeviceCreate },
{"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", "(IIZ)I", (void*)nContextCreate },
{"nContextSetSurface", "(Landroid/view/Surface;)V", (void*)nContextSetSurface }, {"nContextSetSurface", "(IILandroid/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

@ -55,7 +55,7 @@ RsDevice rsDeviceCreate();
void rsDeviceDestroy(RsDevice); void rsDeviceDestroy(RsDevice);
void rsDeviceSetConfig(RsDevice, RsDeviceParam, int32_t value); void rsDeviceSetConfig(RsDevice, RsDeviceParam, int32_t value);
RsContext rsContextCreate(RsDevice, void *, uint32_t version, bool useDepth); RsContext rsContextCreate(RsDevice, uint32_t version, bool useDepth);
void rsContextDestroy(RsContext); void rsContextDestroy(RsContext);
void rsObjDestroyOOB(RsContext, void *); void rsObjDestroyOOB(RsContext, void *);

View File

@ -126,13 +126,14 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
} }
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mRS.contextSetSurface(width, height, holder.getSurface());
} }
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
} }
private Script.Invokable createScript() { private Script.Invokable createScript() {
mRS = new RenderScript(mSurfaceView.getHolder().getSurface(), false, false); mRS = new RenderScript(false, false);
mRS.mMessageCallback = new FilterCallback(); mRS.mMessageCallback = new FilterCallback();
mParamsType = Type.createFromClass(mRS, Params.class, 1, "Parameters"); mParamsType = Type.createFromClass(mRS, Params.class, 1, "Parameters");

View File

@ -37,9 +37,15 @@ ContextResume {
} }
ContextSetSurface { ContextSetSurface {
param uint32_t width
param uint32_t height
param void *sur param void *sur
} }
ContextSetPriority {
param uint32_t priority
}
AssignName { AssignName {
param void *obj param void *obj
param const char *name param const char *name

View File

@ -92,38 +92,12 @@ void Context::initEGL()
LOGE("eglCreateContext returned EGL_NO_CONTEXT"); LOGE("eglCreateContext returned EGL_NO_CONTEXT");
} }
gGLContextCount++; gGLContextCount++;
if (mWndSurface) {
setSurface(mWndSurface);
} else {
setSurface((Surface *)android_createDisplaySurface());
}
eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
mGL.mVersion = glGetString(GL_VERSION);
mGL.mVendor = glGetString(GL_VENDOR);
mGL.mRenderer = glGetString(GL_RENDERER);
mGL.mExtensions = glGetString(GL_EXTENSIONS);
LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
LOGV("GL Version %s", mGL.mVersion);
LOGV("GL Vendor %s", mGL.mVendor);
LOGV("GL Renderer %s", mGL.mRenderer);
LOGV("GL Extensions %s", mGL.mExtensions);
if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
LOGE("Error, OpenGL ES Lite not supported");
} else {
sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
}
} }
void Context::deinitEGL() void Context::deinitEGL()
{ {
setSurface(NULL); LOGV("deinitEGL");
setSurface(0, 0, NULL);
eglDestroyContext(mEGL.mDisplay, mEGL.mContext); eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
checkEglError("eglDestroyContext"); checkEglError("eglDestroyContext");
@ -265,9 +239,9 @@ void * Context::threadProc(void *vrsc)
rsc->props.mLogScripts = getProp("debug.rs.script"); rsc->props.mLogScripts = getProp("debug.rs.script");
rsc->props.mLogObjects = getProp("debug.rs.objects"); rsc->props.mLogObjects = getProp("debug.rs.objects");
pthread_mutex_lock(&gInitMutex); //pthread_mutex_lock(&gInitMutex);
rsc->initEGL(); //rsc->initEGL();
pthread_mutex_unlock(&gInitMutex); //pthread_mutex_unlock(&gInitMutex);
ScriptTLSStruct *tlsStruct = new ScriptTLSStruct; ScriptTLSStruct *tlsStruct = new ScriptTLSStruct;
if (!tlsStruct) { if (!tlsStruct) {
@ -342,7 +316,7 @@ void * Context::threadProc(void *vrsc)
return NULL; return NULL;
} }
Context::Context(Device *dev, Surface *sur, bool useDepth) Context::Context(Device *dev, bool useDepth)
{ {
pthread_mutex_lock(&gInitMutex); pthread_mutex_lock(&gInitMutex);
@ -353,6 +327,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth)
mUseDepth = useDepth; mUseDepth = useDepth;
mPaused = false; mPaused = false;
mObjHead = NULL; mObjHead = NULL;
memset(&mEGL, 0, sizeof(mEGL));
int status; int status;
pthread_attr_t threadAttr; pthread_attr_t threadAttr;
@ -380,7 +355,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth)
sparam.sched_priority = ANDROID_PRIORITY_DISPLAY; sparam.sched_priority = ANDROID_PRIORITY_DISPLAY;
pthread_attr_setschedparam(&threadAttr, &sparam); pthread_attr_setschedparam(&threadAttr, &sparam);
mWndSurface = sur; mWndSurface = NULL;
objDestroyOOBInit(); objDestroyOOBInit();
timerInit(); timerInit();
@ -426,8 +401,10 @@ Context::~Context()
objDestroyOOBDestroy(); objDestroyOOBDestroy();
} }
void Context::setSurface(Surface *sur) void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
{ {
LOGV("setSurface %i %i %p", w, h, sur);
EGLBoolean ret; EGLBoolean ret;
if (mEGL.mSurface != NULL) { if (mEGL.mSurface != NULL) {
ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@ -437,10 +414,22 @@ void Context::setSurface(Surface *sur)
checkEglError("eglDestroySurface", ret); checkEglError("eglDestroySurface", ret);
mEGL.mSurface = NULL; mEGL.mSurface = NULL;
mEGL.mWidth = 0;
mEGL.mHeight = 0;
mWidth = 0;
mHeight = 0;
} }
mWndSurface = sur; mWndSurface = sur;
if (mWndSurface != NULL) { if (mWndSurface != NULL) {
bool first = false;
if (!mEGL.mContext) {
first = true;
pthread_mutex_lock(&gInitMutex);
initEGL();
pthread_mutex_unlock(&gInitMutex);
}
mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL); mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
checkEglError("eglCreateWindowSurface"); checkEglError("eglCreateWindowSurface");
if (mEGL.mSurface == EGL_NO_SURFACE) { if (mEGL.mSurface == EGL_NO_SURFACE) {
@ -449,6 +438,35 @@ void Context::setSurface(Surface *sur)
ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext); ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
checkEglError("eglMakeCurrent", ret); checkEglError("eglMakeCurrent", ret);
eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
mWidth = w;
mHeight = h;
if ((int)mWidth != mEGL.mWidth || (int)mHeight != mEGL.mHeight) {
LOGE("EGL/Surface mismatch EGL (%i x %i) SF (%i x %i)", mEGL.mWidth, mEGL.mHeight, mWidth, mHeight);
}
if (first) {
mGL.mVersion = glGetString(GL_VERSION);
mGL.mVendor = glGetString(GL_VENDOR);
mGL.mRenderer = glGetString(GL_RENDERER);
mGL.mExtensions = glGetString(GL_EXTENSIONS);
//LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
LOGV("GL Version %s", mGL.mVersion);
LOGV("GL Vendor %s", mGL.mVendor);
LOGV("GL Renderer %s", mGL.mRenderer);
//LOGV("GL Extensions %s", mGL.mExtensions);
if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
LOGE("Error, OpenGL ES Lite not supported");
} else {
sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
}
}
} }
} }
@ -767,19 +785,23 @@ void rsi_ContextResume(Context *rsc)
rsc->resume(); rsc->resume();
} }
void rsi_ContextSetSurface(Context *rsc, void *sur) void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, void *sur)
{
rsc->setSurface(w, h, (Surface *)sur);
}
void rsi_ContextSetPriority(Context *rsc, uint32_t p)
{ {
rsc->setSurface((Surface *)sur);
} }
} }
} }
RsContext rsContextCreate(RsDevice vdev, void *sur, uint32_t version, bool useDepth) RsContext rsContextCreate(RsDevice vdev, uint32_t version, bool useDepth)
{ {
Device * dev = static_cast<Device *>(vdev); Device * dev = static_cast<Device *>(vdev);
Context *rsc = new Context(dev, (Surface *)sur, useDepth); Context *rsc = new Context(dev, useDepth);
return rsc; return rsc;
} }

View File

@ -49,7 +49,7 @@ namespace renderscript {
class Context class Context
{ {
public: public:
Context(Device *, Surface *, bool useDepth); Context(Device *, bool useDepth);
~Context(); ~Context();
static pthread_key_t gThreadTLSKey; static pthread_key_t gThreadTLSKey;
@ -94,7 +94,7 @@ public:
void pause(); void pause();
void resume(); void resume();
void setSurface(Surface *sur); void setSurface(uint32_t w, uint32_t h, 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);
@ -189,6 +189,9 @@ protected:
} mGL; } mGL;
uint32_t mWidth;
uint32_t mHeight;
bool mRunning; bool mRunning;
bool mExit; bool mExit;
bool mUseDepth; bool mUseDepth;

View File

@ -57,7 +57,7 @@ bool LocklessCommandFifo::init(uint32_t sizeInBytes)
mPut = mBuffer; mPut = mBuffer;
mGet = mBuffer; mGet = mBuffer;
mEnd = mBuffer + (sizeInBytes) - 1; mEnd = mBuffer + (sizeInBytes) - 1;
dumpState("init"); //dumpState("init");
return true; return true;
} }

View File

@ -18,7 +18,7 @@
#define ANDROID_RS_UTILS_H #define ANDROID_RS_UTILS_H
#define LOG_NDEBUG 0 #define LOG_NDEBUG 0
#define LOG_TAG "rs" #define LOG_TAG "RenderScript"
#include <utils/Log.h> #include <utils/Log.h>
#include <utils/Vector.h> #include <utils/Vector.h>
#include <utils/KeyedVector.h> #include <utils/KeyedVector.h>