From 2b3bf720bf28584f700ad8ebb5e8e31a0e466f29 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 7 Jan 2016 17:50:48 -0800 Subject: [PATCH] Implement surfaceRedrawNeeded for GLSurfaceView GLSurfaceView was not supporting the surfaceRedrawNeeded protocol which leads to issues with report draw. Thus far this has mostly been fine as the main surface will not render a transparent hole until the SurfaceView has finished drawing. However in the case of SurfaceView replacement the hole in the parent surface will be preexisting and we must be able to tell that our new SurfaceView has actually drawn before removing the replacee. This is part of a series of fixes to 26070641. Bug: 26070641 Change-Id: Iecc16647f9979aa057449e8bafa540885881ed64 --- api/current.txt | 3 +- api/system-current.txt | 3 +- api/test-current.txt | 3 +- opengl/java/android/opengl/GLSurfaceView.java | 40 ++++++++++++++++--- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/api/current.txt b/api/current.txt index 76e44cf96617c..322aed2b47878 100644 --- a/api/current.txt +++ b/api/current.txt @@ -27138,7 +27138,7 @@ package android.opengl { ctor public GLException(int, java.lang.String); } - public class GLSurfaceView extends android.view.SurfaceView implements android.view.SurfaceHolder.Callback { + public class GLSurfaceView extends android.view.SurfaceView implements android.view.SurfaceHolder.Callback2 { ctor public GLSurfaceView(android.content.Context); ctor public GLSurfaceView(android.content.Context, android.util.AttributeSet); method public int getDebugFlags(); @@ -27162,6 +27162,7 @@ package android.opengl { method public void surfaceChanged(android.view.SurfaceHolder, int, int, int); method public void surfaceCreated(android.view.SurfaceHolder); method public void surfaceDestroyed(android.view.SurfaceHolder); + method public void surfaceRedrawNeeded(android.view.SurfaceHolder); field public static final int DEBUG_CHECK_GL_ERROR = 1; // 0x1 field public static final int DEBUG_LOG_GL_CALLS = 2; // 0x2 field public static final int RENDERMODE_CONTINUOUSLY = 1; // 0x1 diff --git a/api/system-current.txt b/api/system-current.txt index 27a16bfbf35e1..1cba6f270172c 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -29134,7 +29134,7 @@ package android.opengl { ctor public GLException(int, java.lang.String); } - public class GLSurfaceView extends android.view.SurfaceView implements android.view.SurfaceHolder.Callback { + public class GLSurfaceView extends android.view.SurfaceView implements android.view.SurfaceHolder.Callback2 { ctor public GLSurfaceView(android.content.Context); ctor public GLSurfaceView(android.content.Context, android.util.AttributeSet); method public int getDebugFlags(); @@ -29158,6 +29158,7 @@ package android.opengl { method public void surfaceChanged(android.view.SurfaceHolder, int, int, int); method public void surfaceCreated(android.view.SurfaceHolder); method public void surfaceDestroyed(android.view.SurfaceHolder); + method public void surfaceRedrawNeeded(android.view.SurfaceHolder); field public static final int DEBUG_CHECK_GL_ERROR = 1; // 0x1 field public static final int DEBUG_LOG_GL_CALLS = 2; // 0x2 field public static final int RENDERMODE_CONTINUOUSLY = 1; // 0x1 diff --git a/api/test-current.txt b/api/test-current.txt index cee8fad8e8d6a..5ce2c362df5aa 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -27138,7 +27138,7 @@ package android.opengl { ctor public GLException(int, java.lang.String); } - public class GLSurfaceView extends android.view.SurfaceView implements android.view.SurfaceHolder.Callback { + public class GLSurfaceView extends android.view.SurfaceView implements android.view.SurfaceHolder.Callback2 { ctor public GLSurfaceView(android.content.Context); ctor public GLSurfaceView(android.content.Context, android.util.AttributeSet); method public int getDebugFlags(); @@ -27162,6 +27162,7 @@ package android.opengl { method public void surfaceChanged(android.view.SurfaceHolder, int, int, int); method public void surfaceCreated(android.view.SurfaceHolder); method public void surfaceDestroyed(android.view.SurfaceHolder); + method public void surfaceRedrawNeeded(android.view.SurfaceHolder); field public static final int DEBUG_CHECK_GL_ERROR = 1; // 0x1 field public static final int DEBUG_LOG_GL_CALLS = 2; // 0x2 field public static final int RENDERMODE_CONTINUOUSLY = 1; // 0x1 diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java index 359a7a97aa81d..9c01f4f4d7a28 100644 --- a/opengl/java/android/opengl/GLSurfaceView.java +++ b/opengl/java/android/opengl/GLSurfaceView.java @@ -161,7 +161,7 @@ import android.view.SurfaceView; * * */ -public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback { +public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback2 { private final static String TAG = "GLSurfaceView"; private final static boolean LOG_ATTACH_DETACH = false; private final static boolean LOG_THREADS = false; @@ -541,6 +541,16 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback mGLThread.onWindowResize(w, h); } + /** + * This method is part of the SurfaceHolder.Callback interface, and is + * not normally called or subclassed by clients of GLSurfaceView. + */ + @Override + public void surfaceRedrawNeeded(SurfaceHolder holder) { + mGLThread.requestRenderAndWait(); + } + + /** * Inform the view that the activity is paused. The owner of this view must * call this method when the activity is paused. Calling this method will @@ -1226,6 +1236,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback mHeight = 0; mRequestRender = true; mRenderMode = RENDERMODE_CONTINUOUSLY; + mWantRenderNotification = false; mGLSurfaceViewWeakRef = glSurfaceViewWeakRef; } @@ -1271,6 +1282,8 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback mEglHelper = new EglHelper(mGLSurfaceViewWeakRef); mHaveEglContext = false; mHaveEglSurface = false; + mWantRenderNotification = false; + try { GL10 gl = null; boolean createEglContext = false; @@ -1278,7 +1291,6 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback boolean createGlInterface = false; boolean lostEglContext = false; boolean sizeChanged = false; - boolean wantRenderNotification = false; boolean doRenderNotification = false; boolean askedToReleaseEglContext = false; int w = 0; @@ -1383,7 +1395,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback if (LOG_SURFACE) { Log.i("GLThread", "sending render notification tid=" + getId()); } - wantRenderNotification = false; + mWantRenderNotification = false; doRenderNotification = false; mRenderComplete = true; sGLThreadManager.notifyAll(); @@ -1422,7 +1434,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback sizeChanged = true; w = mWidth; h = mHeight; - wantRenderNotification = true; + mWantRenderNotification = true; if (LOG_SURFACE) { Log.i("GLThread", "noticing that we want render notification tid=" @@ -1562,7 +1574,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback break; } - if (wantRenderNotification) { + if (mWantRenderNotification) { doRenderNotification = true; } } @@ -1611,6 +1623,23 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback } } + public void requestRenderAndWait() { + synchronized(sGLThreadManager) { + mWantRenderNotification = true; + mRequestRender = true; + mRenderComplete = false; + sGLThreadManager.notifyAll(); + while (!mExited && !mPaused && mRenderComplete == false) { + try { + sGLThreadManager.wait(); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } + + } + } + public void surfaceCreated() { synchronized(sGLThreadManager) { if (LOG_THREADS) { @@ -1766,6 +1795,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback private int mHeight; private int mRenderMode; private boolean mRequestRender; + private boolean mWantRenderNotification; private boolean mRenderComplete; private ArrayList mEventQueue = new ArrayList(); private boolean mSizeChanged = true;