Add a return value for SurfaceTextureListener#onSurfaceTextureDestroyed.
If returns true, the SurfaceTexture will be released by TextureView.
If returns false, the client needs to release the SurfaceTexture.
Change-Id: I946f71e337ad4170c168854ac27e028b82489c8c
diff --git a/api/current.txt b/api/current.txt
index bf4efea..e73cbf5 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -17930,7 +17930,7 @@
method public void destroyRenderScriptGL();
method public android.renderscript.RenderScriptGL getRenderScriptGL();
method public void onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int);
- method public void onSurfaceTextureDestroyed(android.graphics.SurfaceTexture);
+ method public boolean onSurfaceTextureDestroyed(android.graphics.SurfaceTexture);
method public void onSurfaceTextureSizeChanged(android.graphics.SurfaceTexture, int, int);
method public void onSurfaceTextureUpdated(android.graphics.SurfaceTexture);
method public void pause();
@@ -22351,7 +22351,7 @@
public static abstract interface TextureView.SurfaceTextureListener {
method public abstract void onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int);
- method public abstract void onSurfaceTextureDestroyed(android.graphics.SurfaceTexture);
+ method public abstract boolean onSurfaceTextureDestroyed(android.graphics.SurfaceTexture);
method public abstract void onSurfaceTextureSizeChanged(android.graphics.SurfaceTexture, int, int);
method public abstract void onSurfaceTextureUpdated(android.graphics.SurfaceTexture);
}
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 76aa21f..53a6bcb 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -73,9 +73,10 @@
* // Ignored, Camera does all the work for us
* }
*
- * public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ * public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
* mCamera.stopPreview();
* mCamera.release();
+ * return true;
* }
*
* public void onSurfaceTextureUpdated(SurfaceTexture surface) {
@@ -195,8 +196,9 @@
super.onDetachedFromWindow();
if (mLayer != null) {
+ boolean shouldRelease = true;
if (mListener != null) {
- mListener.onSurfaceTextureDestroyed(mSurface);
+ shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface);
}
synchronized (mNativeWindowLock) {
@@ -204,7 +206,7 @@
}
mLayer.destroy();
- mSurface.release();
+ if (shouldRelease) mSurface.release();
mSurface = null;
mLayer = null;
}
@@ -578,12 +580,12 @@
/**
* Invoked when the specified {@link SurfaceTexture} is about to be destroyed.
- * After this method is invoked, no rendering should happen inside the surface
- * texture.
+ * If returns true, no rendering should happen inside the surface texture after this method
+ * is invoked. If returns false, the client needs to call {@link SurfaceTexture#release()}.
*
* @param surface The surface about to be destroyed
*/
- public void onSurfaceTextureDestroyed(SurfaceTexture surface);
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface);
/**
* Invoked when the specified {@link SurfaceTexture} is updated through
diff --git a/graphics/java/android/renderscript/RSTextureView.java b/graphics/java/android/renderscript/RSTextureView.java
index b8dd577..30b2f99 100644
--- a/graphics/java/android/renderscript/RSTextureView.java
+++ b/graphics/java/android/renderscript/RSTextureView.java
@@ -85,13 +85,15 @@
}
@Override
- public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
//Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
mSurfaceTexture = surface;
if (mRS != null) {
mRS.setSurfaceTexture(null, 0, 0);
}
+
+ return true;
}
@Override
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/CanvasTextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/CanvasTextureViewActivity.java
index 81c22b8..bd2f68f 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/CanvasTextureViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/CanvasTextureViewActivity.java
@@ -58,8 +58,9 @@
}
@Override
- public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
if (mThread != null) mThread.stopRendering();
+ return true;
}
@Override
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java
index 949589f..e77178d 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java
@@ -110,13 +110,14 @@
}
@Override
- public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mRenderThread.finish();
try {
mRenderThread.join();
} catch (InterruptedException e) {
Log.e(RenderThread.LOG_TAG, "Could not wait for render thread");
}
+ return true;
}
@Override
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java
index f420fa0..038434a 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java
@@ -96,9 +96,10 @@
}
@Override
- public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mCamera.stopPreview();
mCamera.release();
+ return true;
}
@Override
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java
index 634e7e3a..97e2108 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java
@@ -92,9 +92,10 @@
}
@Override
- public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mCamera.stopPreview();
mCamera.release();
+ return true;
}
@Override