DO NOT MERGE: SurfaceFlinger: Don't wake for pending transactions.

When we still have pending transactions (e.g. we are waiting on the
other side of a deferred transaction), we need to set the transaction
flags on SurfaceFlinger, so SurfaceFlinger will continue to call
doTransaction and give us a chance to process them. However when
we set the transaction flags, we trigger a wake up! This isn't
desirable, as the frame might have not come in. If the frame did come
in we will get to INVALIDATE, and from INVALIDATE observe the
transaction flags. This means we can set the transaction flags without
scheduling a wakeup and rely on the incoming frame to eventually wake
us up. I also considered triggering the transaction processing from
onFrameAvailable but at that point we are too late in the composition
cycle.

Bug: 157685525
Test: Existing tests pass
Change-Id: Ia54bc9f48a80906fc8f21c46debc72fabadd3e07
This commit is contained in:
Robert Carr 2020-05-29 12:02:51 -07:00 committed by Rob Carr
parent 983e568b3c
commit 7ec777d945
3 changed files with 16 additions and 3 deletions

View file

@ -848,11 +848,14 @@ bool Layer::applyPendingStates(State* stateToCommit) {
}
}
// If we still have pending updates, wake SurfaceFlinger back up and point
// it at this layer so we can process them
// If we still have pending updates, we need to ensure SurfaceFlinger
// will keep calling doTransaction, and so we set the transaction flags.
// However, our pending states won't clear until a frame is available,
// and so there is no need to specifically trigger a wakeup. Rather
// we set the flags and wait for something else to wake us up.
if (!mPendingStates.empty()) {
setTransactionFlags(eTransactionNeeded);
mFlinger->setTransactionFlags(eTraversalNeeded);
mFlinger->setTransactionFlagsNoWake(eTraversalNeeded);
}
mCurrentState.modified = false;

View file

@ -3242,6 +3242,10 @@ uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags,
return old;
}
uint32_t SurfaceFlinger::setTransactionFlagsNoWake(uint32_t flags) {
return mTransactionFlags.fetch_or(flags);
}
bool SurfaceFlinger::flushTransactionQueues() {
// to prevent onHandleDestroyed from being called while the lock is held,
// we must keep a copy of the transactions (specifically the composer

View file

@ -628,6 +628,12 @@ private:
uint32_t peekTransactionFlags();
// Can only be called from the main thread or with mStateLock held
uint32_t setTransactionFlags(uint32_t flags);
// Set the transaction flags, but don't trigger a wakeup! We use this cases where
// there are still pending transactions but we know they won't be ready until a frame
// arrives from a different layer. So we need to ensure we performTransaction from invalidate
// but there is no need to try and wake up immediately to do it. Rather we rely on
// onFrameAvailable to wake us up.
uint32_t setTransactionFlagsNoWake(uint32_t flags);
uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart);
void commitTransaction() REQUIRES(mStateLock);
void commitOffscreenLayers();