Android焦点之SurfaceFlinger的apply

接animate()的openSurfaceTransaction(),prepareSurfaces(),closeSurfaceTransaction()

  1. mService.openSurfaceTransaction(),通过SurfaceControl来通知native开始一个Transaction;

  2. 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
相关推荐
五味香37 分钟前
Java学习,查找List最大最小值
android·java·开发语言·python·学习·golang·kotlin
graceyun6 小时前
C语言进阶习题【1】指针和数组(4)——指针笔试题3
android·java·c语言
2401_8979160611 小时前
Android 自定义 View _ 扭曲动效
android
天花板之恋11 小时前
Android AutoMotive --CarService
android·aaos·automotive
susu108301891114 小时前
Android Studio打包APK
android·ide·android studio
2401_8979078615 小时前
Android 存储进化:分区存储
android
Dwyane031 天前
Android实战经验篇-AndroidScrcpyClient投屏一
android
FlyingWDX1 天前
Android 拖转改变视图高度
android
_可乐无糖1 天前
Appium 检查安装的驱动
android·ui·ios·appium·自动化
一名技术极客1 天前
Python 进阶 - Excel 基本操作
android·python·excel