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

Commit 19b23d6c authored by Melody Hsu's avatar Melody Hsu
Browse files

Start buffer stuffing recovery based on time blocked in dequeueBuffer

Start buffer stuffing recovery only when severely buffer stuffed.
Determined based on how long BBQ waits on buffer release. Waits
shorter than this may simply be false positives for buffer stuffing
recovery due to timing and should be ignored.

Bug: b/294922229
Test: Manually check perfetto traces, presubmit, SysUi performance tests
Flag: android.view.flags.buffer_stuffing_recovery
Change-Id: Ic8c01edaebd599724fc7a9a67630069c05b567c1
parent 17c69415
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -250,12 +250,15 @@ public final class Choreographer {

    /**
     * Set flag to indicate that client is blocked waiting for buffer release and
     * buffer stuffing recovery should soon begin.
     * buffer stuffing recovery should soon begin. This is provided with the
     * duration of time in nanoseconds that the client was blocked for.
     * @hide
     */
    public void onWaitForBufferRelease() {
    public void onWaitForBufferRelease(long durationNanos) {
        if (durationNanos > mLastFrameIntervalNanos / 2) {
            mBufferStuffingState.isStuffed.set(true);
        }
    }

    /**
     * Contains information about the current frame for jank-tracking,
+7 −4
Original line number Diff line number Diff line
@@ -107,10 +107,11 @@ public:
        }
    }

    void onWaitForBufferRelease() {
    void onWaitForBufferRelease(const nsecs_t durationNanos) {
        JNIEnv* env = getenv(mVm);
        getenv(mVm)->CallVoidMethod(mWaitForBufferReleaseObject,
                                    gWaitForBufferReleaseCallback.onWaitForBufferRelease);
                                    gWaitForBufferReleaseCallback.onWaitForBufferRelease,
                                    durationNanos);
        DieIfException(env, "Uncaught exception in WaitForBufferReleaseCallback.");
    }

@@ -255,7 +256,9 @@ static void nativeSetWaitForBufferReleaseCallback(JNIEnv* env, jclass clazz, jlo
    } else {
        sp<WaitForBufferReleaseCallbackWrapper> wrapper =
                new WaitForBufferReleaseCallbackWrapper{env, waitForBufferReleaseCallback};
        queue->setWaitForBufferReleaseCallback([wrapper]() { wrapper->onWaitForBufferRelease(); });
        queue->setWaitForBufferReleaseCallback([wrapper](const nsecs_t durationNanos) {
            wrapper->onWaitForBufferRelease(durationNanos);
        });
    }
}

@@ -305,7 +308,7 @@ int register_android_graphics_BLASTBufferQueue(JNIEnv* env) {
    jclass waitForBufferReleaseClass =
            FindClassOrDie(env, "android/graphics/BLASTBufferQueue$WaitForBufferReleaseCallback");
    gWaitForBufferReleaseCallback.onWaitForBufferRelease =
            GetMethodIDOrDie(env, waitForBufferReleaseClass, "onWaitForBufferRelease", "()V");
            GetMethodIDOrDie(env, waitForBufferReleaseClass, "onWaitForBufferRelease", "(J)V");

    return 0;
}
+3 −1
Original line number Diff line number Diff line
@@ -61,8 +61,10 @@ public final class BLASTBufferQueue {
        /**
         * Indicates that the client is waiting on buffer release
         * due to no free buffers being available to render into.
         * @param durationNanos The length of time in nanoseconds
         * that the client was blocked on buffer release.
         */
        void onWaitForBufferRelease();
        void onWaitForBufferRelease(long durationNanos);
    }

    /** Create a new connection with the surface flinger. */