android display 笔记(八)WMS与SurfaceFlinger交互

在Android系统中由WindowManagerService也就是WMS承担窗口位置的管理。

WMS

WMS是一个系统服务,运行在system server进程,系统启动便开始启动该服务

java 复制代码
/frameworks/base/services/java/com/android/server/SystemServer.java


  // Start services.
938          try {
939              t.traceBegin("StartServices");
940              startBootstrapServices(t);
941              startCoreServices(t);
942              startOtherServices(t);
943              startApexServices(t);
944              // Only update the timeout after starting all the services so that we use
945              // the default timeout to start system server.
946              updateWatchdogTimeout(t);


在这里面启动相关服务, 在startOtherServices(t)启动 WMS服务。
  private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
1425          t.traceBegin("startOtherServices");
1426          mSystemServiceManager.updateOtherServicesStartIndex();

       t.traceBegin("StartWindowManagerService");
1604              // WMS needs sensor service ready
1605              mSystemServiceManager.startBootPhase(t, SystemService.PHASE_WAIT_FOR_SENSOR_SERVICE);
1606              wm = WindowManagerService.main(context, inputManager, !mFirstBoot,
1607                      new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager);
1608              ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false,
1609                      DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PROTO);
1610              ServiceManager.addService(Context.INPUT_SERVICE, inputManager,
1611                      /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL);
1612              t.traceEnd();

上述代码可以看到,创建了wms对象并添加到服务管理进程中。

与wms交互

应用进程通过WindowManagerGlobal与WMS建立通信连接。

java 复制代码
7      @UnsupportedAppUsage
168      public static IWindowManager getWindowManagerService() {
169          synchronized (WindowManagerGlobal.class) {
170              if (sWindowManagerService == null) {
171                  sWindowManagerService = IWindowManager.Stub.asInterface(
172                          ServiceManager.getService("window"));
173                  try {
174                      if (sWindowManagerService != null) {
175                          ValueAnimator.setDurationScale(
176                                  sWindowManagerService.getCurrentAnimatorScale());
177                          sUseBLASTAdapter = sWindowManagerService.useBLAST();
178                      }
179                  } catch (RemoteException e) {
180                      throw e.rethrowFromSystemServer();
181                  }
182              }
183              return sWindowManagerService;
184          }
185      }

      @UnsupportedAppUsage
188      public static IWindowSession getWindowSession() {
189          synchronized (WindowManagerGlobal.class) {
190              if (sWindowSession == null) {
191                  try {
192                      // Emulate the legacy behavior.  The global instance of InputMethodManager
193                      // was instantiated here.
194                      // TODO(b/116157766): Remove this hack after cleaning up @UnsupportedAppUsage
195                      InputMethodManager.ensureDefaultInstanceForDefaultDisplayIfNecessary();
196                      IWindowManager windowManager = getWindowManagerService();
197                      sWindowSession = windowManager.openSession(
198                              new IWindowSessionCallback.Stub() {
199                                  @Override
200                                  public void onAnimatorScaleChanged(float scale) {
201                                      ValueAnimator.setDurationScale(scale);
202                                  }
203                              });
204                  } catch (RemoteException e) {
205                      throw e.rethrowFromSystemServer();
206                  }
207              }
208              return sWindowSession;
209          }
210      }

通过getWindowManagerService,openSession方法获取到IWindowManager对象。应用进程通常用通过IWindowManager与WMS交互。

WMS与SurfaceFlinger交互

再上图可以看到,在system server中,通过WMS中的DisplayContent成员,创建DisplayContent对象时,也会闯将SurfaceSession对象。

然后SurfaceSeeion会通过JNI 调用nativeCreate创建SurfaceComposerClient对象,并把该对象的地址保存到mNativeClient中。

每创建一个SurfaceComposerClient对象,SurfaceFlinger进程都会创建一个Client对象与它对应。

总的来说,当WMS需要与Surfaceflinger进行交互的时候,会调用DisplayContent中的SurfaceSession取出SurfaceComposerClient对象的地址,然后在向Surfaceflinger发送请求。

相关推荐
akbar&2 分钟前
计算机三级 - 数据库技术 - 第十三章 大规模数据库架构 笔记
数据库·笔记
sixteenyy20 分钟前
学习笔记(一)
笔记·学习
miao_zz1 小时前
基于react native的锚点
android·react native·react.js
安卓美女1 小时前
Android自定义View性能优化
android·性能优化
吃什么芹菜卷2 小时前
2024.9最新:CUDA安装,pytorch库安装
人工智能·pytorch·笔记·python·深度学习
云边有个稻草人2 小时前
【刷题】Day5--数字在升序数组中出现的次数
开发语言·笔记·算法
月夕花晨3742 小时前
C++学习笔记(26)
c++·笔记·学习
Dingdangr2 小时前
Android中的四大组件
android
mg6683 小时前
安卓玩机工具-----无需root权限 卸载 禁用 删除当前机型app应用 ADB玩机工具
android
安卓机器3 小时前
Android架构组件:MVVM模式的实战应用与数据绑定技巧
android·架构