diff options
author | Jason Sams <rjsams@android.com> | 2009-11-12 15:10:25 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-11-12 15:10:47 -0800 |
commit | 3bc47d438171dce294e816366d53bc9eca772c5b (patch) | |
tree | 58c41bf03b538359d7dd70fcd8362195a5405445 /libs/rs | |
parent | b602c328c24f82d61038ac1222bd40a3cc7bc900 (diff) | |
download | frameworks_base-3bc47d438171dce294e816366d53bc9eca772c5b.zip frameworks_base-3bc47d438171dce294e816366d53bc9eca772c5b.tar.gz frameworks_base-3bc47d438171dce294e816366d53bc9eca772c5b.tar.bz2 |
Defer EGL init until the surface changed call comes in. Pass w,h along with surface for verification of driver state.
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/RenderScript.h | 2 | ||||
-rw-r--r-- | libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java | 3 | ||||
-rw-r--r-- | libs/rs/rs.spec | 6 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 98 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 7 | ||||
-rw-r--r-- | libs/rs/rsLocklessFifo.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsUtils.h | 2 |
7 files changed, 76 insertions, 44 deletions
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 9b04393..3ca8b15 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -55,7 +55,7 @@ RsDevice rsDeviceCreate(); void rsDeviceDestroy(RsDevice); 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 rsObjDestroyOOB(RsContext, void *); diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index b1facfc..334fd9c 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -126,13 +126,14 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + mRS.contextSetSurface(width, height, holder.getSurface()); } public void surfaceDestroyed(SurfaceHolder holder) { } private Script.Invokable createScript() { - mRS = new RenderScript(mSurfaceView.getHolder().getSurface(), false, false); + mRS = new RenderScript(false, false); mRS.mMessageCallback = new FilterCallback(); mParamsType = Type.createFromClass(mRS, Params.class, 1, "Parameters"); diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 865e435..da25a27 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -37,9 +37,15 @@ ContextResume { } ContextSetSurface { + param uint32_t width + param uint32_t height param void *sur } +ContextSetPriority { + param uint32_t priority + } + AssignName { param void *obj param const char *name diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 3e4cc36..ab3809d 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -92,38 +92,12 @@ void Context::initEGL() LOGE("eglCreateContext returned EGL_NO_CONTEXT"); } 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() { - setSurface(NULL); + LOGV("deinitEGL"); + setSurface(0, 0, NULL); eglDestroyContext(mEGL.mDisplay, mEGL.mContext); checkEglError("eglDestroyContext"); @@ -265,9 +239,9 @@ void * Context::threadProc(void *vrsc) rsc->props.mLogScripts = getProp("debug.rs.script"); rsc->props.mLogObjects = getProp("debug.rs.objects"); - pthread_mutex_lock(&gInitMutex); - rsc->initEGL(); - pthread_mutex_unlock(&gInitMutex); + //pthread_mutex_lock(&gInitMutex); + //rsc->initEGL(); + //pthread_mutex_unlock(&gInitMutex); ScriptTLSStruct *tlsStruct = new ScriptTLSStruct; if (!tlsStruct) { @@ -342,7 +316,7 @@ void * Context::threadProc(void *vrsc) return NULL; } -Context::Context(Device *dev, Surface *sur, bool useDepth) +Context::Context(Device *dev, bool useDepth) { pthread_mutex_lock(&gInitMutex); @@ -353,6 +327,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth) mUseDepth = useDepth; mPaused = false; mObjHead = NULL; + memset(&mEGL, 0, sizeof(mEGL)); int status; pthread_attr_t threadAttr; @@ -380,7 +355,7 @@ Context::Context(Device *dev, Surface *sur, bool useDepth) sparam.sched_priority = ANDROID_PRIORITY_DISPLAY; pthread_attr_setschedparam(&threadAttr, &sparam); - mWndSurface = sur; + mWndSurface = NULL; objDestroyOOBInit(); timerInit(); @@ -426,8 +401,10 @@ Context::~Context() 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; if (mEGL.mSurface != NULL) { 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); mEGL.mSurface = NULL; + mEGL.mWidth = 0; + mEGL.mHeight = 0; + mWidth = 0; + mHeight = 0; } mWndSurface = sur; 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); checkEglError("eglCreateWindowSurface"); 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); 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(); } -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); - Context *rsc = new Context(dev, (Surface *)sur, useDepth); + Context *rsc = new Context(dev, useDepth); return rsc; } diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index bffc55b..f3803a5 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -49,7 +49,7 @@ namespace renderscript { class Context { public: - Context(Device *, Surface *, bool useDepth); + Context(Device *, bool useDepth); ~Context(); static pthread_key_t gThreadTLSKey; @@ -94,7 +94,7 @@ public: void pause(); 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 removeName(ObjectBase *obj); @@ -189,6 +189,9 @@ protected: } mGL; + uint32_t mWidth; + uint32_t mHeight; + bool mRunning; bool mExit; bool mUseDepth; diff --git a/libs/rs/rsLocklessFifo.cpp b/libs/rs/rsLocklessFifo.cpp index 085a81e..c796520 100644 --- a/libs/rs/rsLocklessFifo.cpp +++ b/libs/rs/rsLocklessFifo.cpp @@ -57,7 +57,7 @@ bool LocklessCommandFifo::init(uint32_t sizeInBytes) mPut = mBuffer; mGet = mBuffer; mEnd = mBuffer + (sizeInBytes) - 1; - dumpState("init"); + //dumpState("init"); return true; } diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h index 63d73a1..07f8933 100644 --- a/libs/rs/rsUtils.h +++ b/libs/rs/rsUtils.h @@ -18,7 +18,7 @@ #define ANDROID_RS_UTILS_H #define LOG_NDEBUG 0 -#define LOG_TAG "rs" +#define LOG_TAG "RenderScript" #include <utils/Log.h> #include <utils/Vector.h> #include <utils/KeyedVector.h> |