Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec46b4e1 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Add a 'release' method to the SurfaceTexture public Java API

Bug: 5063618
Change-Id: I689cb0c01c14e597ccfb4eb0972e64fa570bd4e8
parent b923066d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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();
  }
+1 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ public class TextureView extends View {
            }

            mLayer.destroy();
            mSurface.release();
            mSurface = null;
            mLayer = null;
        }
+7 −0
Original line number Diff line number Diff line
@@ -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)
+20 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -910,6 +910,7 @@ void SurfaceTexture::abandon() {
    Mutex::Autolock lock(mMutex);
    freeAllBuffers();
    mAbandoned = true;
    mCurrentTextureBuf.clear();
    mDequeueCondition.signal();
}