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

Commit b332d485 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

[sf] Release the currently presented buffer when setBuffer is called with null

Update callers to explictly unset the buffer when they mean to drop the buffer
from the transaction instead of passing a null buffer.

Bug: 241271897
Test: presubmit
Change-Id: I6d90810be40f96d2a62d21a3d7e769c2a5c3098d
parent 494c104c
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -220,6 +220,7 @@ public final class SurfaceControl implements Parcelable {
            long newParentNativeObject);
    private static native void nativeSetBuffer(long transactionObj, long nativeObject,
            HardwareBuffer buffer, long fencePtr, Consumer<SyncFence> releaseCallback);
    private static native void nativeUnsetBuffer(long transactionObj, long nativeObject);
    private static native void nativeSetBufferTransform(long transactionObj, long nativeObject,
            int transform);
    private static native void nativeSetDataSpace(long transactionObj, long nativeObject,
@@ -3663,6 +3664,22 @@ public final class SurfaceControl implements Parcelable {
            return setBuffer(sc, buffer, null);
        }

        /**
         * Unsets the buffer for the SurfaceControl in the current Transaction. This will not clear
         * the buffer being rendered, but resets the buffer state in the Transaction only. The call
         * will also invoke the release callback.
         *
         * Note, this call is different from passing a null buffer to
         * {@link SurfaceControl.Transaction#setBuffer} which will release the last displayed
         * buffer.
         *
         * @hide
         */
        public Transaction unsetBuffer(SurfaceControl sc) {
            nativeUnsetBuffer(mNativeObject, sc.mNativeObject);
            return this;
        }

        /**
         * Updates the HardwareBuffer displayed for the SurfaceControl.
         *
@@ -3682,7 +3699,8 @@ public final class SurfaceControl implements Parcelable {
         * until all presentation fences have signaled, ensuring the transaction remains consistent.
         *
         * @param sc The SurfaceControl to update
         * @param buffer The buffer to be displayed
         * @param buffer The buffer to be displayed. Pass in a null buffer to release the last
         * displayed buffer.
         * @param fence The presentation fence. If null or invalid, this is equivalent to
         *              {@link #setBuffer(SurfaceControl, HardwareBuffer)}
         * @return this
+8 −0
Original line number Diff line number Diff line
@@ -613,6 +613,12 @@ static void nativeSetBuffer(JNIEnv* env, jclass clazz, jlong transactionObj, jlo
                           genReleaseCallback(env, releaseCallback));
}

static void nativeUnsetBuffer(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject) {
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
    SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
    transaction->unsetBuffer(ctrl);
}

static void nativeSetBufferTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
                                     jlong nativeObject, jint transform) {
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
@@ -2195,6 +2201,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeSetGeometry },
    {"nativeSetBuffer", "(JJLandroid/hardware/HardwareBuffer;JLjava/util/function/Consumer;)V",
            (void*)nativeSetBuffer },
    {"nativeUnsetBuffer", "(JJ)V", (void*)nativeUnsetBuffer },

    {"nativeSetBufferTransform", "(JJI)V", (void*) nativeSetBufferTransform},
    {"nativeSetDataSpace", "(JJI)V",
            (void*)nativeSetDataSpace },
+1 −1
Original line number Diff line number Diff line
@@ -5602,7 +5602,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    private void dropBufferFrom(Transaction t) {
        SurfaceControl viewSurface = getClientViewRootSurface();
        if (viewSurface == null) return;
        t.setBuffer(viewSurface, (android.hardware.HardwareBuffer) null);
        t.unsetBuffer(viewSurface);
    }

    @Override