summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishnu Nair <vishnun@google.com>2021-08-30 15:01:29 -0700
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-09-20 22:30:51 +0000
commit90a90b2bdca10c9c758e8da2b031858fa8f71164 (patch)
tree1ed70916097fb958bfef5f0dfc05eaae140ab81f
parentf7a13b00e3ab25a17f4252953a6bbcd9b305d0ca (diff)
downloadbase-90a90b2bdca10c9c758e8da2b031858fa8f71164.tar.gz
Surface: Release references to BlastBufferQueue and SurfaceControl on Surface#destroy
SurfaceView clients may hold on to surface references. In S this means they would extend the lifetime of the SurfaceControl resulting in "leaking" buffers until the references are cleared or the app is terminated. Fix this by calling a new destroy function on Surface which will explicitly remove references to the SurfaceControl and BBQ it holds. This is safe because SurfaceView controls the lifecycle of the Surface and knows when the Surface will become invalid. Once invalid, the Surface cannot become valid again. Test: repro steps in bug Bug: 198133921 Change-Id: I5c7e43736f025fc0965eae2f19719ba40df3cb70 Merged-In: I5c7e43736f025fc0965eae2f19719ba40df3cb70 (cherry picked from commit 43b0f37a70b36e0dd3b47352d3b5ecdd594e1551)
-rw-r--r--core/java/android/view/Surface.java4
-rw-r--r--core/java/android/view/SurfaceView.java2
-rw-r--r--core/jni/android_view_Surface.cpp6
3 files changed, 11 insertions, 1 deletions
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index ff2d2eb3d334..fa7330fb84eb 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -98,6 +98,7 @@ public class Surface implements Parcelable {
private static native int nativeSetFrameRate(
long nativeObject, float frameRate, int compatibility, int changeFrameRateStrategy);
+ private static native void nativeDestroy(long nativeObject);
public static final @android.annotation.NonNull Parcelable.Creator<Surface> CREATOR =
new Parcelable.Creator<Surface>() {
@@ -339,6 +340,9 @@ public class Surface implements Parcelable {
*/
@UnsupportedAppUsage
public void destroy() {
+ if (mNativeObject != 0) {
+ nativeDestroy(mNativeObject);
+ }
release();
}
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index c1956e45653b..4b8b607de089 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -903,7 +903,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
mSurfaceAlpha = 1f;
synchronized (mSurfaceControlLock) {
- mSurface.release();
+ mSurface.destroy();
if (mBlastBufferQueue != null) {
mBlastBufferQueue.destroy();
mBlastBufferQueue = null;
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 0957067de603..869b53df2837 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -449,6 +449,11 @@ static jint nativeSetFrameRate(JNIEnv* env, jclass clazz, jlong nativeObject, jf
int(changeFrameRateStrategy));
}
+static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
+ sp<Surface> surface(reinterpret_cast<Surface*>(nativeObject));
+ surface->destroy();
+}
+
// ----------------------------------------------------------------------------
static const JNINativeMethod gSurfaceMethods[] = {
@@ -477,6 +482,7 @@ static const JNINativeMethod gSurfaceMethods[] = {
{"nativeSetAutoRefreshEnabled", "(JZ)I", (void*)nativeSetAutoRefreshEnabled},
{"nativeSetFrameRate", "(JFII)I", (void*)nativeSetFrameRate},
{"nativeGetFromBlastBufferQueue", "(JJ)J", (void*)nativeGetFromBlastBufferQueue},
+ {"nativeDestroy", "(J)V", (void*)nativeDestroy},
};
int register_android_view_Surface(JNIEnv* env)