Skip to content

Commit 83302fc

Browse files
Jim ShargoAndroid (Google) Code Review
authored andcommitted
Merge "bufferqueues: Entirely remove support for passing GL fences into BQs" into main
2 parents 7fd4c33 + defc49e commit 83302fc

14 files changed

Lines changed: 126 additions & 52 deletions

libs/gui/BufferQueueConsumer.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,14 @@ status_t BufferQueueConsumer::attachBuffer(int* outSlot,
477477
return NO_ERROR;
478478
}
479479

480+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
481+
status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber,
482+
const sp<Fence>& releaseFence) {
483+
#else
480484
status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber,
481485
const sp<Fence>& releaseFence, EGLDisplay eglDisplay,
482486
EGLSyncKHR eglFence) {
487+
#endif
483488
ATRACE_CALL();
484489
ATRACE_BUFFER_INDEX(slot);
485490

@@ -493,27 +498,6 @@ status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber,
493498
return BAD_VALUE;
494499
}
495500

496-
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
497-
if (eglFence != EGL_NO_SYNC_KHR) {
498-
// Most platforms will be using native fences, so it's unlikely that we'll ever have to
499-
// process an eglFence. Ideally we can remove this code eventually. In the mean time, do our
500-
// best to wait for it so the buffer stays valid, otherwise return an error to the caller.
501-
//
502-
// EGL_SYNC_FLUSH_COMMANDS_BIT_KHR so that we don't wait forever on a fence that hasn't
503-
// shown up on the GPU yet.
504-
EGLint result = eglClientWaitSyncKHR(eglDisplay, eglFence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
505-
1000000000);
506-
if (result == EGL_FALSE) {
507-
BQ_LOGE("releaseBuffer: error %#x waiting for fence", eglGetError());
508-
return UNKNOWN_ERROR;
509-
} else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
510-
BQ_LOGE("releaseBuffer: timeout waiting for fence");
511-
return UNKNOWN_ERROR;
512-
}
513-
eglDestroySyncKHR(eglDisplay, eglFence);
514-
}
515-
#endif
516-
517501
sp<IProducerListener> listener;
518502
{ // Autolock scope
519503
std::lock_guard<std::mutex> lock(mCore->mMutex);

libs/gui/ConsumerBase.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,13 @@ status_t ConsumerBase::addReleaseFenceLocked(int slot,
656656
return OK;
657657
}
658658

659+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
660+
status_t ConsumerBase::releaseBufferLocked(int slot, const sp<GraphicBuffer> graphicBuffer) {
661+
#else
659662
status_t ConsumerBase::releaseBufferLocked(
660663
int slot, const sp<GraphicBuffer> graphicBuffer,
661664
EGLDisplay display, EGLSyncKHR eglFence) {
665+
#endif
662666
if (mAbandoned) {
663667
CB_LOGE("releaseBufferLocked: ConsumerBase is abandoned!");
664668
return NO_INIT;
@@ -675,8 +679,12 @@ status_t ConsumerBase::releaseBufferLocked(
675679

676680
CB_LOGV("releaseBufferLocked: slot=%d/%" PRIu64,
677681
slot, mSlots[slot].mFrameNumber);
682+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
683+
status_t err = mConsumer->releaseBuffer(slot, mSlots[slot].mFrameNumber, mSlots[slot].mFence);
684+
#else
678685
status_t err = mConsumer->releaseBuffer(slot, mSlots[slot].mFrameNumber,
679686
display, eglFence, mSlots[slot].mFence);
687+
#endif
680688
if (err == IGraphicBufferConsumer::STALE_BUFFER_SLOT) {
681689
freeBufferLocked(slot);
682690
}

libs/gui/GLConsumer.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

433433
status_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

libs/gui/IGraphicBufferConsumer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,20 @@ class BpGraphicBufferConsumer : public SafeBpInterface<IGraphicBufferConsumer> {
8585
return callRemote<Signature>(Tag::ATTACH_BUFFER, slot, buffer);
8686
}
8787

88+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
89+
status_t releaseBuffer(int buf, uint64_t frameNumber, const sp<Fence>& releaseFence) override {
90+
using Signature = status_t (IGraphicBufferConsumer::*)(int, uint64_t, const sp<Fence>&);
91+
return callRemote<Signature>(Tag::RELEASE_BUFFER, buf, frameNumber, releaseFence);
92+
}
93+
#else
8894
status_t releaseBuffer(int buf, uint64_t frameNumber,
8995
EGLDisplay display __attribute__((unused)),
9096
EGLSyncKHR fence __attribute__((unused)),
9197
const sp<Fence>& releaseFence) override {
9298
using Signature = status_t (IGraphicBufferConsumer::*)(int, uint64_t, const sp<Fence>&);
9399
return callRemote<Signature>(Tag::RELEASE_BUFFER, buf, frameNumber, releaseFence);
94100
}
101+
#endif
95102

96103
status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) override {
97104
using Signature = decltype(&IGraphicBufferConsumer::consumerConnect);

libs/gui/include/gui/BufferQueueConsumer.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ class BufferQueueConsumer : public BnGraphicBufferConsumer {
6565
// any references to the just-released buffer that it might have, as if it
6666
// had received a onBuffersReleased() call with a mask set for the released
6767
// buffer.
68-
//
69-
// Note that the dependencies on EGL will be removed once we switch to using
70-
// the Android HW Sync HAL.
68+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
69+
virtual status_t releaseBuffer(int slot, uint64_t frameNumber,
70+
const sp<Fence>& releaseFence) override;
71+
#else
7172
virtual status_t releaseBuffer(int slot, uint64_t frameNumber,
7273
const sp<Fence>& releaseFence, EGLDisplay display,
7374
EGLSyncKHR fence);
74-
75+
#endif
7576
// connect connects a consumer to the BufferQueue. Only one
7677
// consumer may be connected, and when that consumer disconnects the
7778
// BufferQueue is placed into the "abandoned" state, causing most
@@ -167,6 +168,7 @@ class BufferQueueConsumer : public BnGraphicBufferConsumer {
167168
// dump our state in a String
168169
status_t dumpState(const String8& prefix, String8* outResult) const override;
169170

171+
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
170172
// Functions required for backwards compatibility.
171173
// These will be modified/renamed in IGraphicBufferConsumer and will be
172174
// removed from this class at that time. See b/13306289.
@@ -176,6 +178,7 @@ class BufferQueueConsumer : public BnGraphicBufferConsumer {
176178
const sp<Fence>& releaseFence) {
177179
return releaseBuffer(buf, frameNumber, releaseFence, display, fence);
178180
}
181+
#endif
179182

180183
virtual status_t consumerConnect(const sp<IConsumerListener>& consumer,
181184
bool controlledByApp) {

libs/gui/include/gui/ConsumerBase.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,13 @@ class ConsumerBase : public virtual RefBase,
245245
// must take place when a buffer is released back to the BufferQueue. If
246246
// it is overridden the derived class's implementation must call
247247
// ConsumerBase::releaseBufferLocked.
248+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
249+
virtual status_t releaseBufferLocked(int slot, const sp<GraphicBuffer> graphicBuffer);
250+
#else
248251
virtual status_t releaseBufferLocked(int slot,
249252
const sp<GraphicBuffer> graphicBuffer,
250253
EGLDisplay display = EGL_NO_DISPLAY, EGLSyncKHR eglFence = EGL_NO_SYNC_KHR);
251-
254+
#endif
252255
// returns true iff the slot still has the graphicBuffer in it.
253256
bool stillTracking(int slot, const sp<GraphicBuffer> graphicBuffer);
254257

libs/gui/include/gui/GLConsumer.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class GLConsumer : public ConsumerBase {
271271
#endif
272272
// releaseBufferLocked overrides the ConsumerBase method to update the
273273
// mEglSlots array in addition to the ConsumerBase.
274+
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
274275
virtual status_t releaseBufferLocked(int slot, const sp<GraphicBuffer> graphicBuffer,
275276
EGLDisplay display = EGL_NO_DISPLAY,
276277
EGLSyncKHR eglFence = EGL_NO_SYNC_KHR) override;
@@ -279,16 +280,14 @@ class GLConsumer : public ConsumerBase {
279280
const sp<GraphicBuffer> graphicBuffer, EGLSyncKHR eglFence) {
280281
return releaseBufferLocked(slot, graphicBuffer, mEglDisplay, eglFence);
281282
}
283+
#endif
282284

283285
struct PendingRelease {
284-
PendingRelease() : isPending(false), currentTexture(-1),
285-
graphicBuffer(), display(nullptr), fence(nullptr) {}
286+
PendingRelease() : isPending(false), currentTexture(-1), graphicBuffer() {}
286287

287288
bool isPending;
288289
int currentTexture;
289290
sp<GraphicBuffer> graphicBuffer;
290-
EGLDisplay display;
291-
EGLSyncKHR fence;
292291
};
293292

294293
// This releases the buffer in the slot referenced by mCurrentTexture,
@@ -468,16 +467,18 @@ class GLConsumer : public ConsumerBase {
468467
// EGLSlot contains the information and object references that
469468
// GLConsumer maintains about a BufferQueue buffer slot.
470469
struct EglSlot {
470+
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
471471
EglSlot() : mEglFence(EGL_NO_SYNC_KHR) {}
472-
472+
#endif
473473
// mEglImage is the EGLImage created from mGraphicBuffer.
474474
sp<EglImage> mEglImage;
475-
475+
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
476476
// mFence is the EGL sync object that must signal before the buffer
477477
// associated with this buffer slot may be dequeued. It is initialized
478478
// to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
479479
// on a compile-time option) set to a new sync object in updateTexImage.
480480
EGLSyncKHR mEglFence;
481+
#endif
481482
};
482483

483484
// mEglDisplay is the EGLDisplay with which this GLConsumer is currently

libs/gui/include/gui/IGraphicBufferConsumer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,17 @@ class IGraphicBufferConsumer : public RefBase {
139139
// * the buffer slot was invalid
140140
// * the fence was NULL
141141
// * the buffer slot specified is not in the acquired state
142+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
143+
virtual status_t releaseBuffer(int buf, uint64_t frameNumber,
144+
const sp<Fence>& releaseFence) = 0;
145+
#else
142146
virtual status_t releaseBuffer(int buf, uint64_t frameNumber, EGLDisplay display,
143147
EGLSyncKHR fence, const sp<Fence>& releaseFence) = 0;
144148

145149
status_t releaseBuffer(int buf, uint64_t frameNumber, const sp<Fence>& releaseFence) {
146150
return releaseBuffer(buf, frameNumber, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, releaseFence);
147151
}
152+
#endif
148153

149154
// consumerConnect connects a consumer to the BufferQueue. Only one consumer may be connected,
150155
// and when that consumer disconnects the BufferQueue is placed into the "abandoned" state,

libs/gui/include/gui/mock/GraphicBufferConsumer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <gmock/gmock.h>
2020

21+
#include <com_android_graphics_libgui_flags.h>
2122
#include <gui/IGraphicBufferConsumer.h>
2223

2324
#include <utils/RefBase.h>
@@ -33,7 +34,11 @@ class GraphicBufferConsumer : public BnGraphicBufferConsumer, public virtual and
3334
MOCK_METHOD3(acquireBuffer, status_t(BufferItem*, nsecs_t, uint64_t));
3435
MOCK_METHOD1(detachBuffer, status_t(int));
3536
MOCK_METHOD2(attachBuffer, status_t(int*, const sp<GraphicBuffer>&));
37+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
38+
MOCK_METHOD3(releaseBuffer, status_t(int, uint64_t, const sp<Fence>&));
39+
#else
3640
MOCK_METHOD5(releaseBuffer, status_t(int, uint64_t, EGLDisplay, EGLSyncKHR, const sp<Fence>&));
41+
#endif
3742
MOCK_METHOD2(consumerConnect, status_t(const sp<IConsumerListener>&, bool));
3843
MOCK_METHOD0(consumerDisconnect, status_t());
3944
MOCK_METHOD1(getReleasedBuffers, status_t(uint64_t*));

libs/nativedisplay/include/surfacetexture/EGLConsumer.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,11 @@ class EGLConsumer {
113113

114114
protected:
115115
struct PendingRelease {
116-
PendingRelease()
117-
: isPending(false),
118-
currentTexture(-1),
119-
graphicBuffer(),
120-
display(nullptr),
121-
fence(nullptr) {}
116+
PendingRelease() : isPending(false), currentTexture(-1), graphicBuffer() {}
122117

123118
bool isPending;
124119
int currentTexture;
125120
sp<GraphicBuffer> graphicBuffer;
126-
EGLDisplay display;
127-
EGLSyncKHR fence;
128121
};
129122

130123
/**
@@ -250,20 +243,24 @@ class EGLConsumer {
250243
* EGLConsumer maintains about a BufferQueue buffer slot.
251244
*/
252245
struct EglSlot {
253-
EglSlot() : mEglFence(EGL_NO_SYNC_KHR) {}
246+
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
254247

248+
EglSlot() : mEglFence(EGL_NO_SYNC_KHR) {}
249+
#endif
255250
/**
256251
* mEglImage is the EGLImage created from mGraphicBuffer.
257252
*/
258253
sp<EglImage> mEglImage;
259254

255+
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_GL_FENCE_CLEANUP)
260256
/**
261257
* mFence is the EGL sync object that must signal before the buffer
262258
* associated with this buffer slot may be dequeued. It is initialized
263259
* to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
264260
* on a compile-time option) set to a new sync object in updateTexImage.
265261
*/
266262
EGLSyncKHR mEglFence;
263+
#endif
267264
};
268265

269266
/**

0 commit comments

Comments
 (0)