Skip to content

Commit e46fcc3

Browse files
patrickdwilliamsAndroid (Google) Code Review
authored andcommitted
Merge "Add warning logs when we fail to set BufferReleaseChannel" into main
2 parents 260a091 + a419faa commit e46fcc3

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

libs/gui/BLASTBufferQueue.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,7 @@ void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width,
294294
SurfaceComposerClient::Transaction t;
295295
if (surfaceControlChanged) {
296296
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
297-
// SELinux policy may prevent this process from sending the BufferReleaseChannel's file
298-
// descriptor to SurfaceFlinger, causing the entire transaction to be dropped. This
299-
// transaction is applied separately to ensure we don't lose the other updates.
300-
t.setApplyToken(mApplyToken)
301-
.setBufferReleaseChannel(mSurfaceControl, mBufferReleaseProducer)
302-
.apply(false /* synchronous */, true /* oneWay */);
297+
updateBufferReleaseProducer();
303298
#endif
304299
t.setFlags(mSurfaceControl, layer_state_t::eEnableBackpressure,
305300
layer_state_t::eEnableBackpressure);
@@ -1335,6 +1330,20 @@ void BLASTBufferQueue::setApplyToken(sp<IBinder> applyToken) {
13351330

13361331
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
13371332

1333+
void BLASTBufferQueue::updateBufferReleaseProducer() {
1334+
// SELinux policy may prevent this process from sending the BufferReleaseChannel's file
1335+
// descriptor to SurfaceFlinger, causing the entire transaction to be dropped. We send this
1336+
// transaction independently of any other updates to ensure those updates aren't lost.
1337+
SurfaceComposerClient::Transaction t;
1338+
status_t status = t.setApplyToken(mApplyToken)
1339+
.setBufferReleaseChannel(mSurfaceControl, mBufferReleaseProducer)
1340+
.apply(false /* synchronous */, true /* oneWay */);
1341+
if (status != OK) {
1342+
ALOGW("[%s] %s - failed to set buffer release channel on %s", mName.c_str(),
1343+
statusToString(status).c_str(), mSurfaceControl->getName().c_str());
1344+
}
1345+
}
1346+
13381347
void BLASTBufferQueue::drainBufferReleaseConsumer() {
13391348
ATRACE_CALL();
13401349
while (true) {

libs/gui/SurfaceComposerClient.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,21 +1347,22 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
13471347
sp<IBinder> applyToken = mApplyToken ? mApplyToken : getDefaultApplyToken();
13481348

13491349
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1350-
sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags, applyToken,
1351-
mInputWindowCommands, mDesiredPresentTime, mIsAutoTimestamp,
1352-
mUncacheBuffers, hasListenerCallbacks, listenerCallbacks, mId,
1353-
mMergedTransactionIds);
1350+
status_t binderStatus =
1351+
sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags,
1352+
applyToken, mInputWindowCommands, mDesiredPresentTime,
1353+
mIsAutoTimestamp, mUncacheBuffers, hasListenerCallbacks,
1354+
listenerCallbacks, mId, mMergedTransactionIds);
13541355
mId = generateId();
13551356

13561357
// Clear the current states and flags
13571358
clear();
13581359

1359-
if (synchronous) {
1360+
if (synchronous && binderStatus == OK) {
13601361
syncCallback->wait();
13611362
}
13621363

13631364
mStatus = NO_ERROR;
1364-
return NO_ERROR;
1365+
return binderStatus;
13651366
}
13661367

13671368
sp<IBinder> SurfaceComposerClient::Transaction::sApplyToken = new BBinder();
@@ -1375,7 +1376,7 @@ sp<IBinder> SurfaceComposerClient::Transaction::getDefaultApplyToken() {
13751376

13761377
void SurfaceComposerClient::Transaction::setDefaultApplyToken(sp<IBinder> applyToken) {
13771378
std::scoped_lock lock{sApplyTokenMutex};
1378-
sApplyToken = applyToken;
1379+
sApplyToken = std::move(applyToken);
13791380
}
13801381

13811382
status_t SurfaceComposerClient::Transaction::sendSurfaceFlushJankDataTransaction(

libs/gui/include/gui/BLASTBufferQueue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,14 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener {
325325
std::unique_ptr<gui::BufferReleaseChannel::ConsumerEndpoint> mBufferReleaseConsumer;
326326
std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> mBufferReleaseProducer;
327327

328+
void updateBufferReleaseProducer() REQUIRES(mMutex);
328329
void drainBufferReleaseConsumer();
329330

331+
// BufferReleaseReader is used to do blocking but interruptible reads from the buffer
332+
// release channel. To implement this, BufferReleaseReader owns an epoll file descriptor that
333+
// is configured to wake up when either the BufferReleaseReader::ConsumerEndpoint or an eventfd
334+
// becomes readable. Interrupts are necessary because a free buffer may become available for
335+
// reasons other than a buffer release from the producer.
330336
class BufferReleaseReader {
331337
public:
332338
explicit BufferReleaseReader(BLASTBufferQueue&);

0 commit comments

Comments
 (0)