diff options
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/view/TextureView.java | 1 | ||||
-rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 7 | ||||
-rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 20 | ||||
-rw-r--r-- | libs/gui/SurfaceTexture.cpp | 1 |
5 files changed, 30 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index d18b734..ffafd23 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8454,6 +8454,7 @@ package android.graphics { ctor public SurfaceTexture(int, boolean); method public long getTimestamp(); method public void getTransformMatrix(float[]); + method public void release(); method public void setOnFrameAvailableListener(android.graphics.SurfaceTexture.OnFrameAvailableListener); method public void updateTexImage(); } diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 96d6f09..76aa21f 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -204,6 +204,7 @@ public class TextureView extends View { } mLayer.destroy(); + mSurface.release(); mSurface = null; mLayer = null; } diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index 2de0932..ffcd1a0 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -233,6 +233,12 @@ static jlong SurfaceTexture_getTimestamp(JNIEnv* env, jobject thiz) return surfaceTexture->getTimestamp(); } +static void SurfaceTexture_release(JNIEnv* env, jobject thiz) +{ + sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz)); + surfaceTexture->abandon(); +} + // ---------------------------------------------------------------------------- static JNINativeMethod gSurfaceTextureMethods[] = { @@ -243,6 +249,7 @@ static JNINativeMethod gSurfaceTextureMethods[] = { {"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage }, {"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix }, {"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp }, + {"nativeRelease", "()V", (void*)SurfaceTexture_release }, }; int register_android_graphics_SurfaceTexture(JNIEnv* env) diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index 1647ff34..d62fd67 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -187,6 +187,25 @@ public class SurfaceTexture { return nativeGetTimestamp(); } + /** + * release() frees all the buffers and puts the SurfaceTexture into the + * 'abandoned' state. Once put in this state the SurfaceTexture can never + * leave it. When in the 'abandoned' state, all methods of the + * ISurfaceTexture interface will fail with the NO_INIT error. + * + * Note that while calling this method causes all the buffers to be freed + * from the perspective of the the SurfaceTexture, if there are additional + * references on the buffers (e.g. if a buffer is referenced by a client or + * by OpenGL ES as a texture) then those buffer will remain allocated. + * + * Always call this method when you are done with SurfaceTexture. Failing + * to do so may delay resource deallocation for a significant amount of + * time. + */ + public void release() { + nativeRelease(); + } + protected void finalize() throws Throwable { try { nativeFinalize(); @@ -232,6 +251,7 @@ public class SurfaceTexture { private native void nativeSetDefaultBufferSize(int width, int height); private native void nativeUpdateTexImage(); private native int nativeGetQueuedCount(); + private native void nativeRelease(); /* * We use a class initializer to allow the native code to cache some diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index 4f51f03..1a036ee 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -910,6 +910,7 @@ void SurfaceTexture::abandon() { Mutex::Autolock lock(mMutex); freeAllBuffers(); mAbandoned = true; + mCurrentTextureBuf.clear(); mDequeueCondition.signal(); } |