接animate()的openSurfaceTransaction(),prepareSurfaces(),closeSurfaceTransaction()
-
mService.openSurfaceTransaction(),通过SurfaceControl来通知native开始一个Transaction;
-
mService.closeSurfaceTransaction(),通过SurfaceControl来通知native(SurfaceFlinger)关闭一个Transaction最终来执行合成显示等工作;
WMS#openSurfaceTransaction:New出GlobalTransactionWrapper 接animate()的dc.prepareSurfaces();
DisplayContent#prepareSurfaces:将SurfaceControl提交在了mPendingTransaction上。然后完成遍历后,将mPendingTransaction合并到全局Transaction对象上提交给SurfaceFlinger。
mergeToGlobalTransaction将提供的Transaction合并提交,然后接animate()调Wms的closeSurfaceTransaction()
WMS#closeSurfaceTransaction: 再调用SurfaceControl的内部类GlobalTransactionWrapper#applyGlobalTransaction
SurfaceComposerClient#apply: 再调用android_view_SurfaceControl.cpp的nativeApplyTransaction方法,
apply方法主要就是收集之前通过transaction属性设置方法设置所有信息都需要收集起来,比如最重要的composerStates,然后调用sf的跨进程方法setTransactionState传递到sf中。
java
@frameworks/base/services/core/java/com/android/server/wm/WindowAnimator.java
private void animate(long frameTimeNs) {
@frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
mService.openSurfaceTransaction();
@frameworks/base/core/java/android/view/SurfaceControl.java
SurfaceControl.openTransaction();
sGlobalTransaction = new GlobalTransactionWrapper();
@frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
dc.prepareSurfaces();
@frameworks/base/core/java/android/view/SurfaceControl.java
SurfaceControl.mergeToGlobalTransaction(transaction);
sGlobalTransaction.merge(t);
@frameworks/base/core/jni/android_view_SurfaceControl.cpp
nativeMergeTransaction(mNativeObject, other.mNativeObject);
transaction->merge(std::move(*otherTransaction));
mService.closeSurfaceTransaction("WindowAnimator");
@frameworks/base/core/java/android/view/SurfaceControl.java
SurfaceControl.closeTransaction();
else if (--sTransactionNestCount > 0) { //open和close一一对应,保证 sTransactionNestCount 数量
sGlobalTransaction.applyGlobalTransaction(false);
@frameworks/base/core/jni/android_view_SurfaceControl.cpp
nativeApplyTransaction(mNativeObject, sync);
@frameworks/native/libs/gui/SurfaceComposerClient.cpp
transaction->apply(sync);
for (auto const& kv : mComposerStates){ composerStates.add(kv.second); } // 遍历mComposerStates,其中包含了所有的InputWindow
displayStates = std::move(mDisplayStates);
//最后把上面收集的Transaction相关信息,调用sf的setTransactionState进行跨进程传递到sf进程
sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags, applyToken,mInputWindowCommands, mDesiredPresentTime, mIsAutoTimestamp,hasListenerCallbacks, listenerCallbacks, mId)
clear();//apply后就需要把Transaction进行clear