App 创建window流程(android12 )

发布于:2025-02-11 ⋅ 阅读:(40) ⋅ 点赞:(0)

activity为例总结大致流程:

create activity并create 布局,window(phonewindow) 

activity resume调用之时把window添加到display才能显示,window添加到display过程:

new viewrootimpl

mWindowSession.addToDisplayAsUser(mWindow

wms.createSurfaceControl

WindowStateAnimator.createSurface

SurfaceFlinger::createLayer

有关的窗口对象

PhoneWindow ActivityThread#performLaunchActivity {Activity.attach}
Surface
  1. new ViewRootImpl 创建null对象
  2. mSurface.transferFrom(getOrCreateBLASTSurface())//填充内容
  3. 创建native层的Surface
Layer SurfaceFlinger::createLayer
RenderSurface SurfaceFlinger gpu合成layer之后的数据管理类
FramebufferSurface Framebuffer管理类,负责消费合成的layer数据,送显
SurfaceControl ViewRootImpl#relayoutWindow{mSurface.copyFrom(mSurfaceControl)}  //改变Surface buffer属性
IWindowSession new ViewRootImpl(contexst, display, WindowManagerGlobal.getWindowSession())
WindowManagerGlobal

ActivityThread#handleLaunchActivity

 {WindowManagerGlobal.initialize()}

App窗口完整创建流程

Launcher#startActivity() -> SystemServer AMS#startActivity -> zygote newProcess

->App #newActivityThread.main() -> ActivityThread#handleLaunchActivity

-> ActivityThread.performLaunchActivity

{

       WindowManagerGlobal.initialize()

       newActivity().attach(context)

}

->ActivityThread#handleResumeActivity->wm.addView(decor

->WindowManagerGlobal.addView(WindowManagerGlobal.setView

{
      new ViewRootImpl()#setView  ->  requestlayout ->  performTraversals  ->  relayoutWindow() ->  

mWindowSession.relayout(mSurfaceControl -> wms.relayout 开始创建SurfaceControl和Layer

}

创建SurfaceControl过程:

  • mWindowSession.relayout(mSurfaceControl
  • -> wms.createSurfaceControl()
  • ->mSurfaceControl = WindowStateAnimator.createSurfaceLocked//开始创建Surface
  • ->mSurface.copyFrom(mSurfaceControl) //把mSurfaceControl复制到ViewRootImpl对象的mSurface里面后续操作window使用

wms.createSurfaceLocked 调用 SurfaceComposerClient::createSurface 通知SurfaceFlinger创建一个surface,Surface创建详细流程 App申请Surface流程(Android12 )-CSDN博客

部分资料参考于:Android14 SurfaceFlinger Surface的创建_pendingbuffercounter-CSDN博客