@@ -1221,16 +1221,12 @@ class BBQBufferQueueProducer : public BufferQueueProducer {
12211221#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
12221222 status_t waitForBufferRelease (std::unique_lock<std::mutex>& bufferQueueLock,
12231223 nsecs_t timeout) const override {
1224+ const auto startTime = std::chrono::steady_clock::now ();
12241225 sp<BLASTBufferQueue> bbq = mBLASTBufferQueue .promote ();
12251226 if (!bbq) {
12261227 return OK;
12271228 }
12281229
1229- // Provide a callback for Choreographer to start buffer stuffing recovery when blocked
1230- // on buffer release.
1231- std::function<void ()> callbackCopy = bbq->getWaitForBufferReleaseCallback ();
1232- if (callbackCopy) callbackCopy ();
1233-
12341230 // BufferQueue has already checked if we have a free buffer. If there's an unread interrupt,
12351231 // we want to ignore it. This must be done before unlocking the BufferQueue lock to ensure
12361232 // we don't miss an interrupt.
@@ -1252,6 +1248,14 @@ class BBQBufferQueueProducer : public BufferQueueProducer {
12521248 }
12531249
12541250 bbq->releaseBufferCallback (id, fence, maxAcquiredBufferCount);
1251+ const nsecs_t durationNanos = std::chrono::duration_cast<std::chrono::nanoseconds>(
1252+ std::chrono::steady_clock::now () - startTime)
1253+ .count ();
1254+ // Provide a callback for Choreographer to start buffer stuffing recovery when blocked
1255+ // on buffer release.
1256+ std::function<void (const nsecs_t )> callbackCopy = bbq->getWaitForBufferReleaseCallback ();
1257+ if (callbackCopy) callbackCopy (durationNanos);
1258+
12551259 return OK;
12561260 }
12571261#endif
@@ -1343,12 +1347,13 @@ void BLASTBufferQueue::setApplyToken(sp<IBinder> applyToken) {
13431347 mApplyToken = std::move (applyToken);
13441348}
13451349
1346- void BLASTBufferQueue::setWaitForBufferReleaseCallback (std::function<void ()> callback) {
1350+ void BLASTBufferQueue::setWaitForBufferReleaseCallback (
1351+ std::function<void (const nsecs_t )> callback) {
13471352 std::lock_guard _lock{mWaitForBufferReleaseMutex };
13481353 mWaitForBufferReleaseCallback = std::move (callback);
13491354}
13501355
1351- std::function<void ()> BLASTBufferQueue::getWaitForBufferReleaseCallback () const {
1356+ std::function<void (const nsecs_t )> BLASTBufferQueue::getWaitForBufferReleaseCallback () const {
13521357 std::lock_guard _lock{mWaitForBufferReleaseMutex };
13531358 return mWaitForBufferReleaseCallback ;
13541359}
0 commit comments