status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
if (mStatus != NO_ERROR) {
return mStatus;
}
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
bool hasListenerCallbacks = !mListenerCallbacks.empty();
std::vector<ListenerCallbacks> listenerCallbacks;
// For every listener with registered callbacks
for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
auto& [callbackIds, surfaceControls] = callbackInfo;
if (callbackIds.empty()) {
continue;
}
if (surfaceControls.empty()) {
listenerCallbacks.emplace_back(IInterface::asBinder(listener), std::move(callbackIds));
} else {
// If the listener has any SurfaceControls set on this Transaction update the surface
// state
for (const auto& surfaceControl : surfaceControls) {
layer_state_t* s = getLayerState(surfaceControl);
if (!s) {
ALOGE("failed to get layer state");
continue;
}
std::vector<CallbackId> callbacks(callbackIds.begin(), callbackIds.end());
s->what |= layer_state_t::eHasListenerCallbacksChanged;
s->listeners.emplace_back(IInterface::asBinder(listener), callbacks);
}
}
}
surfaceControls
是空的,把 callbackIds
存到 listenerCallbacks
,ListenerCallbacks 向量。surfaceControls
,向 layer_state_t 的 listeners
写入 ListenerCallbacks。给每一个 layer_state_t
都写入 callbackIds
不是冗余的吗?没有副作用吗?surfaceControls
是在 Transaction::registerSurfaceControlForCallback() 中设置的。 cacheBuffers();
Transaction::cacheBuffers() 缓存 buffer,为了减少 GraphicBuffer 跨进程传递成本。
Vector<ComposerState> composerStates;
Vector<DisplayState> displayStates;
uint32_t flags = 0;
mForceSynchronous |= synchronous;
for (auto const& kv : mComposerStates){
composerStates.add(kv.second);
}
displayStates = std::move(mDisplayStates);
if (mForceSynchronous) {
flags |= ISurfaceComposer::eSynchronous;
}
if (mAnimation) {
flags |= ISurfaceComposer::eAnimation;
}
// If both mEarlyWakeupStart and mEarlyWakeupEnd are set
// it is equivalent for none
if (mEarlyWakeupStart && !mEarlyWakeupEnd) {
flags |= ISurfaceComposer::eEarlyWakeupStart;
}
if (mEarlyWakeupEnd && !mEarlyWakeupStart) {
flags |= ISurfaceComposer::eEarlyWakeupEnd;
}
sp<IBinder> applyToken = mApplyToken
? mApplyToken
: IInterface::asBinder(TransactionCompletedListener::getIInstance());
拷贝 composerStates
和 displayStates
,并根据属性操作 flags
。
sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags, applyToken,
mInputWindowCommands, mDesiredPresentTime, mIsAutoTimestamp,
{} /*uncacheBuffer - only set in doUncacheBufferTransaction*/,
hasListenerCallbacks, listenerCallbacks, mId);
mId = generateId();
// Clear the current states and flags
clear();
mStatus = NO_ERROR;
return NO_ERROR;
}
调用 setTransactionState()
调用 SurfaceFlinger::setTransactionState()。最后调用 Transaction::clear()。