layer_state_t*SurfaceComposerClient::Transaction::getLayerState(constsp<SurfaceControl>&sc){autohandle=sc->getLayerStateHandle();//获取SurfaceControl的handle,
//判断是否mComposerStates容器是否存在这个sc的相关信息,如果没有则进入添加
if(mComposerStates.count(handle)==0){// we don't have it, add an initialized layer_state to our list
ComposerStates;//初始化一个ComposerState
s.state.surface=handle;s.state.layerId=sc->getLayerId();mComposerStates[handle]=s;//把初始化的ComposerState放到map集合mComposerStates中
}//如果存在,则直接通过handle从mComposerStates获取state返回
return&(mComposerStates[handle].state);}
sp<IBinder>Layer::getHandle(){Mutex::Autolock_l(mLock);if(mGetHandleCalled){ALOGE("Get handle called twice");returnnullptr;}mGetHandleCalled=true;returnnewHandle(mFlinger,this);}
SurfaceComposerClient::Transaction&SurfaceComposerClient::Transaction::merge(Transaction&&other){for(autoconst&[handle,composerState]:other.mComposerStates){if(mComposerStates.count(handle)==0){mComposerStates[handle]=composerState;}else{if(composerState.state.what&layer_state_t::eBufferChanged){releaseBufferIfOverwriting(mComposerStates[handle].state);}mComposerStates[handle].state.merge(composerState.state);}}for(autoconst&state:other.mDisplayStates){ssize_tindex=mDisplayStates.indexOf(state);if(index<0){mDisplayStates.add(state);}else{mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);}}for(constauto&[listener,callbackInfo]:other.mListenerCallbacks){auto&[callbackIds,surfaceControls]=callbackInfo;mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(callbackIds.begin()),std::make_move_iterator(callbackIds.end()));mListenerCallbacks[listener].surfaceControls.insert(surfaceControls.begin(),surfaceControls.end());auto¤tProcessCallbackInfo=mListenerCallbacks[TransactionCompletedListener::getIInstance()];currentProcessCallbackInfo.surfaceControls.insert(std::make_move_iterator(surfaceControls.begin()),std::make_move_iterator(surfaceControls.end()));// register all surface controls for all callbackIds for this listener that is merging
for(constauto&surfaceControl:currentProcessCallbackInfo.surfaceControls){TransactionCompletedListener::getInstance()->addSurfaceControlToCallbacks(surfaceControl,currentProcessCallbackInfo.callbackIds);}}mInputWindowCommands.merge(other.mInputWindowCommands);mContainsBuffer|=other.mContainsBuffer;mEarlyWakeupStart=mEarlyWakeupStart||other.mEarlyWakeupStart;mEarlyWakeupEnd=mEarlyWakeupEnd||other.mEarlyWakeupEnd;mApplyToken=other.mApplyToken;mFrameTimelineInfo.merge(other.mFrameTimelineInfo);other.clear();return*this;}
status_tSurfaceComposerClient::Transaction::apply(boolsynchronous,booloneWay){//省略非关键
for(autoconst&kv:mComposerStates){//收集各个图层sc的ComposerState信息
composerStates.add(kv.second);}displayStates=std::move(mDisplayStates);//省略部分
//最后把上面收集的Transaction相关信息,调用sf的setTransactionState进行跨进程传递到sf进程
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();//apply后就需要把Transaction进行clear
returnNO_ERROR;}