summaryrefslogtreecommitdiff
path: root/core/java/android/view/SurfaceHolder.java
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 /core/java/android/view/SurfaceHolder.java
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 'core/java/android/view/SurfaceHolder.java')
-rw-r--r--core/java/android/view/SurfaceHolder.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/core/java/android/view/SurfaceHolder.java b/core/java/android/view/SurfaceHolder.java
index a3e8312c0a64..2fd2e966dc38 100644
--- a/core/java/android/view/SurfaceHolder.java
+++ b/core/java/android/view/SurfaceHolder.java
@@ -116,9 +116,34 @@ public interface SurfaceHolder {
* size before it has been correctly drawn that way). This will
* typically be preceeded by a call to {@link #surfaceChanged}.
*
+ * As of O, {@link #surfaceRedrawNeededAsync} may be implemented
+ * to provide a non-blocking implementation. If {@link #surfaceRedrawNeededAsync}
+ * is not implemented, then this will be called instead.
+ *
* @param holder The SurfaceHolder whose surface has changed.
*/
- public void surfaceRedrawNeeded(SurfaceHolder holder);
+ void surfaceRedrawNeeded(SurfaceHolder holder);
+
+ /**
+ * An alternative to surfaceRedrawNeeded where it is not required to block
+ * until the redraw is complete. You should initiate the redraw, and return,
+ * later invoking drawingFinished when your redraw is complete.
+ *
+ * This can be useful to avoid blocking your main application thread on rendering.
+ *
+ * As of O, if this is implemented {@link #surfaceRedrawNeeded} will not be called.
+ * However it is still recommended to implement {@link #surfaceRedrawNeeded} for
+ * compatibility with older versions of the platform.
+ *
+ * @param holder The SurfaceHolder which needs redrawing.
+ * @param drawingFinished A runnable to signal completion. This may be invoked
+ * from any thread.
+ *
+ */
+ default void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingFinished) {
+ surfaceRedrawNeeded(holder);
+ drawingFinished.run();
+ }
}
/**