summaryrefslogtreecommitdiff
path: root/opengl/java/android
diff options
context:
space:
mode:
authorRobert Carr <racarr@google.com>2016-11-16 13:24:09 -0800
committerRobert Carr <racarr@google.com>2017-01-09 10:44:58 -0800
commit25cfa134835e3791bdb6572f5e25cf4599015678 (patch)
tree11e3a4ef30dca52c893bde1275b639f675453131 /opengl/java/android
parent50e0a9a396ec05ed6a73d3c09f95244038f8d8e3 (diff)
Provide non-blocking SurfaceView draw notification path.
SurfaceView needs to notify the window manager that drawing has been completed, so that animations and such can begin. Currently this is implemented through having the SurfaceView user block in surfaceRedrawNeeded (called from UI thread) until a frame has been completed. This blocking can be unnecessary serialization during startup, and also clumsy to implement for some users. Test: GLSurfaceView and takeSurface API Demos, android.server.cts.SurfaceViewTests Bug: 31850030 Change-Id: Idda02098a635f25cf392f2d59a3abbe54a1d64d4
Diffstat (limited to 'opengl/java/android')
-rw-r--r--opengl/java/android/opengl/GLSurfaceView.java41
1 files changed, 27 insertions, 14 deletions
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java
index 4154ef02772b..329514c0b7fc 100644
--- a/opengl/java/android/opengl/GLSurfaceView.java
+++ b/opengl/java/android/opengl/GLSurfaceView.java
@@ -542,16 +542,27 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
}
/**
- * This method is part of the SurfaceHolder.Callback interface, and is
+ * This method is part of the SurfaceHolder.Callback2 interface, and is
* not normally called or subclassed by clients of GLSurfaceView.
*/
@Override
- public void surfaceRedrawNeeded(SurfaceHolder holder) {
+ public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable finishDrawing) {
if (mGLThread != null) {
- mGLThread.requestRenderAndWait();
+ mGLThread.requestRenderAndNotify(finishDrawing);
}
}
+ /**
+ * This method is part of the SurfaceHolder.Callback2 interface, and is
+ * not normally called or subclassed by clients of GLSurfaceView.
+ */
+ @Deprecated
+ @Override
+ public void surfaceRedrawNeeded(SurfaceHolder holder) {
+ // Since we are part of the framework we know only surfaceRedrawNeededAsync
+ // will be called.
+ }
+
/**
* Pause the rendering thread, optionally tearing down the EGL context
@@ -1305,6 +1316,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
int w = 0;
int h = 0;
Runnable event = null;
+ Runnable finishDrawingRunnable = null;
while (true) {
synchronized (sGLThreadManager) {
@@ -1400,6 +1412,11 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
sGLThreadManager.notifyAll();
}
+ if (mFinishDrawingRunnable != null) {
+ finishDrawingRunnable = mFinishDrawingRunnable;
+ mFinishDrawingRunnable = null;
+ }
+
// Ready to draw?
if (readyToDraw()) {
@@ -1453,7 +1470,6 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
break;
}
}
-
// By design, this is the only place in a GLThread thread where we wait().
if (LOG_THREADS) {
Log.i("GLThread", "waiting tid=" + getId()
@@ -1546,6 +1562,10 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
try {
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onDrawFrame");
view.mRenderer.onDrawFrame(gl);
+ if (finishDrawingRunnable != null) {
+ finishDrawingRunnable.run();
+ finishDrawingRunnable = null;
+ }
} finally {
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
@@ -1625,7 +1645,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
}
}
- public void requestRenderAndWait() {
+ public void requestRenderAndNotify(Runnable finishDrawing) {
synchronized(sGLThreadManager) {
// If we are already on the GL thread, this means a client callback
// has caused reentrancy, for example via updating the SurfaceView parameters.
@@ -1638,17 +1658,9 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
mWantRenderNotification = true;
mRequestRender = true;
mRenderComplete = false;
+ mFinishDrawingRunnable = finishDrawing;
sGLThreadManager.notifyAll();
-
- while (!mExited && !mPaused && !mRenderComplete && ableToDraw()) {
- try {
- sGLThreadManager.wait();
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- }
-
}
}
@@ -1821,6 +1833,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
private boolean mRenderComplete;
private ArrayList<Runnable> mEventQueue = new ArrayList<Runnable>();
private boolean mSizeChanged = true;
+ private Runnable mFinishDrawingRunnable = null;
// End of member variables protected by the sGLThreadManager monitor.