summaryrefslogtreecommitdiff
path: root/core/java/android/view/SurfaceView.java
diff options
context:
space:
mode:
authorRobert Carr <racarr@google.com>2020-03-17 12:04:20 -0700
committerRobert Carr <racarr@google.com>2020-03-18 12:53:28 -0700
commit5af7d62e27ff7db2b185482b842df5ebda19d46c (patch)
tree6a527d8885edeffd111dfff15130d437fe2f367a /core/java/android/view/SurfaceView.java
parent243c57f079a36a4dfb6c1d2a1445cea6d454aa07 (diff)
SurfaceView: Release SurfacePackage when done
We release the SurfaceControl assosciated with a Surface package when accepting a new SurfacePackage, or at time of detached-from-window this way we don't rely on the finalize method. Bug: 149591513 Test: Existing tests pass Change-Id: Ic0f7259394836ee094ed49db73b5986b778b450f
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
-rw-r--r--core/java/android/view/SurfaceView.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 1f7c3504560f..3e1e3939d570 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -496,8 +496,17 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
updateSurface();
releaseSurfaces();
- mHaveFrame = false;
+ // We don't release this as part of releaseSurfaces as
+ // that is also called on transient visibility changes. We can't
+ // recreate this Surface, so only release it when we are fully
+ // detached.
+ if (mSurfacePackage != null) {
+ mSurfacePackage.release();
+ mSurfacePackage = null;
+ }
+
+ mHaveFrame = false;
super.onDetachedFromWindow();
}
@@ -1546,7 +1555,9 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
* Display the view-hierarchy embedded within a {@link SurfaceControlViewHost.SurfacePackage}
* within this SurfaceView. If this SurfaceView is above it's host Surface (see
* {@link #setZOrderOnTop} then the embedded Surface hierarchy will be able to receive
- * input.
+ * input. This will take ownership of the SurfaceControl contained inside the SurfacePackage
+ * and free the caller of the obligation to call
+ * {@link SurfaceControlViewHost.SurfacePackage#release}.
*
* @param p The SurfacePackage to embed.
*/
@@ -1556,6 +1567,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
mSurfacePackage.getSurfaceControl() : null;
if (mSurfaceControl != null && lastSc != null) {
mTmpTransaction.reparent(lastSc, null).apply();
+ mSurfacePackage.release();
} else if (mSurfaceControl != null) {
reparentSurfacePackage(mTmpTransaction, p);
mTmpTransaction.apply();