Merge commit '8da3ac92a6a6247ef06de4d4b684f8635d8fc003' into eclair-mr2-plus-aosp * commit '8da3ac92a6a6247ef06de4d4b684f8635d8fc003': Allow a GLThread to release and reacquire the EGL Surface as needed.
This commit is contained in:
@ -983,17 +983,9 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
* accesses EGL.
|
* accesses EGL.
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
try {
|
|
||||||
sGLThreadManager.start(this);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
guardedRun();
|
guardedRun();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// fall thru and exit normally
|
// fall thru and exit normally
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
sGLThreadManager.end(this);
|
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if (LOG_THREADS) {
|
if (LOG_THREADS) {
|
||||||
@ -1004,12 +996,28 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startEgl() throws InterruptedException {
|
||||||
|
if (! mHaveEgl) {
|
||||||
|
mHaveEgl = true;
|
||||||
|
sGLThreadManager.start(this);
|
||||||
|
mEglHelper.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopEgl() {
|
||||||
|
if (mHaveEgl) {
|
||||||
|
mHaveEgl = false;
|
||||||
|
mEglHelper.destroySurface();
|
||||||
|
mEglHelper.finish();
|
||||||
|
sGLThreadManager.end(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void guardedRun() throws InterruptedException {
|
private void guardedRun() throws InterruptedException {
|
||||||
mEglHelper = new EglHelper();
|
mEglHelper = new EglHelper();
|
||||||
try {
|
try {
|
||||||
mEglHelper.start();
|
startEgl();
|
||||||
|
|
||||||
GL10 gl = null;
|
GL10 gl = null;
|
||||||
boolean tellRendererSurfaceCreated = true;
|
boolean tellRendererSurfaceCreated = true;
|
||||||
@ -1033,20 +1041,30 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
r.run();
|
r.run();
|
||||||
}
|
}
|
||||||
if (mPaused) {
|
if (mPaused) {
|
||||||
mEglHelper.destroySurface();
|
stopEgl();
|
||||||
mEglHelper.finish();
|
|
||||||
needStart = true;
|
needStart = true;
|
||||||
}
|
}
|
||||||
while (needToWait()) {
|
while(true) {
|
||||||
if (LOG_THREADS) {
|
|
||||||
Log.i("GLThread", "needToWait tid=" + getId());
|
|
||||||
}
|
|
||||||
if (!mHasSurface) {
|
if (!mHasSurface) {
|
||||||
if (!mWaitingForSurface) {
|
if (!mWaitingForSurface) {
|
||||||
mEglHelper.destroySurface();
|
stopEgl();
|
||||||
mWaitingForSurface = true;
|
mWaitingForSurface = true;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
boolean shouldHaveEgl = sGLThreadManager.shouldHaveEgl(this);
|
||||||
|
if (mHaveEgl && (!shouldHaveEgl)) {
|
||||||
|
stopEgl();
|
||||||
|
} else if ((!mHaveEgl) && shouldHaveEgl) {
|
||||||
|
startEgl();
|
||||||
|
needStart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!needToWait()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (LOG_THREADS) {
|
||||||
|
Log.i("GLThread", "needToWait tid=" + getId());
|
||||||
}
|
}
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
@ -1065,7 +1083,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needStart) {
|
if (needStart) {
|
||||||
mEglHelper.start();
|
startEgl();
|
||||||
tellRendererSurfaceCreated = true;
|
tellRendererSurfaceCreated = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@ -1097,21 +1115,16 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
/*
|
/*
|
||||||
* clean-up everything...
|
* clean-up everything...
|
||||||
*/
|
*/
|
||||||
mEglHelper.destroySurface();
|
stopEgl();
|
||||||
mEglHelper.finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean needToWait() {
|
private boolean needToWait() {
|
||||||
if (sGLThreadManager.shouldQuit(this)) {
|
|
||||||
mDone = true;
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
if (mDone) {
|
if (mDone) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPaused || (! mHasSurface)) {
|
if (mPaused || (! mHasSurface) || (! mHaveEgl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1236,6 +1249,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
private boolean mPaused;
|
private boolean mPaused;
|
||||||
private boolean mHasSurface;
|
private boolean mHasSurface;
|
||||||
private boolean mWaitingForSurface;
|
private boolean mWaitingForSurface;
|
||||||
|
private boolean mHaveEgl;
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
private int mRenderMode;
|
private int mRenderMode;
|
||||||
@ -1286,6 +1300,16 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class GLThreadManager {
|
private static class GLThreadManager {
|
||||||
|
public boolean shouldHaveEgl(GLThread thread) {
|
||||||
|
if (mMultipleGLESContextsAllowed) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
synchronized(this) {
|
||||||
|
return thread == mMostRecentGLThread || mMostRecentGLThread == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void start(GLThread thread) throws InterruptedException {
|
public void start(GLThread thread) throws InterruptedException {
|
||||||
if (! mGLESVersionCheckComplete) {
|
if (! mGLESVersionCheckComplete) {
|
||||||
mGLESVersion = SystemProperties.getInt(
|
mGLESVersion = SystemProperties.getInt(
|
||||||
@ -1338,12 +1362,6 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldQuit(GLThread thread) {
|
|
||||||
synchronized(this) {
|
|
||||||
return thread != mMostRecentGLThread;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean mGLESVersionCheckComplete;
|
private boolean mGLESVersionCheckComplete;
|
||||||
private int mGLESVersion;
|
private int mGLESVersion;
|
||||||
private GLThread mMostRecentGLThread;
|
private GLThread mMostRecentGLThread;
|
||||||
|
Reference in New Issue
Block a user