status_t SurfaceFlinger::setTransactionState(
const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states,
const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime,
bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) {
uint32_t permissions =
callingThreadHasUnscopedSurfaceFlingerAccess() ? Permission::ACCESS_SURFACE_FLINGER : 0;
...
constint64_t postTime = systemTime();
IPCThreadState* ipc = IPCThreadState::self();
constint originPid = ipc->getCallingPid();
constint originUid = ipc->getCallingUid();
TransactionState state{frameTimelineInfo, states,
displays, flags,
applyToken, inputWindowCommands,
desiredPresentTime, isAutoTimestamp,
uncacheBuffer, postTime,
permissions, hasListenerCallbacks,
listenerCallbacks, originPid,
originUid, transactionId};
...
queueTransaction(state);
// Check the pending state to make sure the transaction is synchronous.
if (state.transactionCommittedSignal) {
waitForSynchronousTransaction(*state.transactionCommittedSignal);
}
return NO_ERROR;
}
新建 TransactionState 结构体。
调用 SurfaceFlinger::queueTransaction() 把 TransactionState 加入队列。
在 SurfaceFlinger::queueTransaction() 中判断是否是同步事务,如果是同步事务则等待完成,最多 5 秒。
void SurfaceFlinger::queueTransaction(TransactionState& state) {
...
// Generate a CountDownLatch pending state if this is a synchronous transaction.
if ((state.flags & eSynchronous) || state.inputWindowCommands.syncInputWindows) {
state.transactionCommittedSignal = std::make_shared<CountDownLatch>(
(state.inputWindowCommands.syncInputWindows
? (CountDownLatch::eSyncInputWindows | CountDownLatch::eSyncTransaction)
: CountDownLatch::eSyncTransaction));
}