summaryrefslogtreecommitdiffstats
path: root/opengl/java/android
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2010-10-26 18:19:14 -0700
committerJack Palevich <jackpal@google.com>2010-10-26 18:19:14 -0700
commit2ff6a824619ac6849ba9f36d97590acf74f62518 (patch)
treec08fc1534f9639cab6f03d786613e14b742d3dc1 /opengl/java/android
parent9440083be22ec13e252aa347e654911d33e50086 (diff)
downloadframeworks_base-2ff6a824619ac6849ba9f36d97590acf74f62518.zip
frameworks_base-2ff6a824619ac6849ba9f36d97590acf74f62518.tar.gz
frameworks_base-2ff6a824619ac6849ba9f36d97590acf74f62518.tar.bz2
Allow a GLSurfaceView to be reattached to a window.
This approach is more backwards-compatible than the previous attempt. The onDetachedFromWindow case is unchanged from the "classic" GLSurfaceView behavior, except that we don't throw a NPE if the renderer has never been set. Change-Id: Ia8103a73366ddb13be44f16b789c929e75ddc792
Diffstat (limited to 'opengl/java/android')
-rw-r--r--opengl/java/android/opengl/GLSurfaceView.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java
index c937b06..0d85404 100644
--- a/opengl/java/android/opengl/GLSurfaceView.java
+++ b/opengl/java/android/opengl/GLSurfaceView.java
@@ -155,6 +155,8 @@ import android.view.SurfaceView;
*
*/
public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
+ private final static String TAG = "GLSurfaceView";
+ private final static boolean LOG_ATTACH_DETACH = false;
private final static boolean LOG_THREADS = false;
private final static boolean LOG_PAUSE_RESUME = false;
private final static boolean LOG_SURFACE = false;
@@ -306,6 +308,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
if (mEGLWindowSurfaceFactory == null) {
mEGLWindowSurfaceFactory = new DefaultWindowSurfaceFactory();
}
+ mRenderer = renderer;
mGLThread = new GLThread(renderer);
mGLThread.start();
}
@@ -525,10 +528,34 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
/**
* This method is used as part of the View class and is not normally
* called or subclassed by clients of GLSurfaceView.
+ */
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ if (LOG_ATTACH_DETACH) {
+ Log.d(TAG, "onAttachedToWindow reattach =" + mDetached);
+ }
+ if (mDetached && (mRenderer != null)) {
+ mGLThread = new GLThread(mRenderer);
+ mGLThread.start();
+ }
+ mDetached = false;
+ }
+
+ /**
+ * This method is used as part of the View class and is not normally
+ * called or subclassed by clients of GLSurfaceView.
* Must not be called before a renderer has been set.
*/
@Override
protected void onDetachedFromWindow() {
+ if (LOG_ATTACH_DETACH) {
+ Log.d(TAG, "onDetachedFromWindow");
+ }
+ if (mGLThread != null) {
+ mGLThread.requestExitAndWait();
+ }
+ mDetached = true;
super.onDetachedFromWindow();
}
@@ -1726,6 +1753,8 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
private boolean mSizeChanged = true;
private GLThread mGLThread;
+ private Renderer mRenderer;
+ private boolean mDetached;
private EGLConfigChooser mEGLConfigChooser;
private EGLContextFactory mEGLContextFactory;
private EGLWindowSurfaceFactory mEGLWindowSurfaceFactory;