@@ -417,18 +417,18 @@ void GLConsumer::onSlotCountChanged(int slotCount) {
417417}
418418#endif
419419
420- status_t GLConsumer::releaseBufferLocked ( int buf,
421- sp<GraphicBuffer> graphicBuffer,
422- EGLDisplay display, EGLSyncKHR eglFence) {
420+ # if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
421+ status_t GLConsumer::releaseBufferLocked ( int buf, sp<GraphicBuffer> graphicBuffer,
422+ EGLDisplay display, EGLSyncKHR eglFence) {
423423 // release the buffer if it hasn't already been discarded by the
424424 // BufferQueue. This can happen, for example, when the producer of this
425425 // buffer has reallocated the original buffer slot after this buffer
426426 // was acquired.
427- status_t err = ConsumerBase::releaseBufferLocked (
428- buf, graphicBuffer, display, eglFence);
427+ status_t err = ConsumerBase::releaseBufferLocked (buf, graphicBuffer, display, eglFence);
429428 mEglSlots [buf].mEglFence = EGL_NO_SYNC_KHR;
430429 return err;
431430}
431+ #endif
432432
433433status_t GLConsumer::updateAndReleaseLocked (const BufferItem& item,
434434 PendingRelease* pendingRelease)
@@ -490,9 +490,14 @@ status_t GLConsumer::updateAndReleaseLocked(const BufferItem& item,
490490 // release old buffer
491491 if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
492492 if (pendingRelease == nullptr ) {
493+ #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
494+ status_t status =
495+ releaseBufferLocked (mCurrentTexture , mCurrentTextureImage ->graphicBuffer ());
496+ #else
493497 status_t status = releaseBufferLocked (
494498 mCurrentTexture , mCurrentTextureImage ->graphicBuffer (),
495499 mEglDisplay , mEglSlots [mCurrentTexture ].mEglFence );
500+ #endif
496501 if (status < NO_ERROR) {
497502 GLC_LOGE (" updateAndRelease: failed to release buffer: %s (%d)" ,
498503 strerror (-status), status);
@@ -501,10 +506,7 @@ status_t GLConsumer::updateAndReleaseLocked(const BufferItem& item,
501506 }
502507 } else {
503508 pendingRelease->currentTexture = mCurrentTexture ;
504- pendingRelease->graphicBuffer =
505- mCurrentTextureImage ->graphicBuffer ();
506- pendingRelease->display = mEglDisplay ;
507- pendingRelease->fence = mEglSlots [mCurrentTexture ].mEglFence ;
509+ pendingRelease->graphicBuffer = mCurrentTextureImage ->graphicBuffer ();
508510 pendingRelease->isPending = true ;
509511 }
510512 }
@@ -744,6 +746,11 @@ status_t GLConsumer::syncForReleaseLocked(EGLDisplay dpy) {
744746 return err;
745747 }
746748 } else if (mUseFenceSync && SyncFeatures::getInstance ().useFenceSync ()) {
749+ #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
750+ // Basically all clients are using native fence syncs. If they aren't, we lose nothing
751+ // by waiting here, because the alternative can cause deadlocks (b/339705065).
752+ glFinish ();
753+ #else
747754 EGLSyncKHR fence = mEglSlots [mCurrentTexture ].mEglFence ;
748755 if (fence != EGL_NO_SYNC_KHR) {
749756 // There is already a fence for the current slot. We need to
@@ -773,6 +780,7 @@ status_t GLConsumer::syncForReleaseLocked(EGLDisplay dpy) {
773780 }
774781 glFlush ();
775782 mEglSlots [mCurrentTexture ].mEglFence = fence;
783+ #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
776784 }
777785 }
778786
0 commit comments