• Android SurfaceControlViewHost介绍及使用


    目录

    概要介绍

    具体实现

    绘制进程内类图

    SurfaceControlViewHost 成员变量 

     SurfaceControlViewHost成员函数       

    surfacecontrol 层级关系

    示例代码

    host端即绘制进程

    client端即显示进程


    概要介绍

    SurfaceControlViewHost是一个辅助类, 用于帮助在其他进程中显示本进程的view。 

    SurfaceControlViewHost 为绘制进程持有,其中的SurfacePackage 通过binder调用交给另外的显示进程,SurfacePackage中持有绘制进程端的绘制surfacecontrol信息。

    在显示进程中的SurfaceView中通过SurfaceView.setChildSurfacePackage(SurfacePackage) 将绘制进程中的界面(即surfacecontrol)与surfaceview关联并进行显示。可以理解为绘制进程和显示进程中传递的实际上为surfacecontrol, 也即SurfaceFlinger端Layer的信息。在显示进程中, 在surfaceView中通过接口设定绘制进程的surface 的父surface为surfaceview自身的mSurfaceControl,并设定z order 关系,  从而在显示上看起来是显示进程的一个view。   


    具体实现

    绘制进程内类图

    如下:  

    SurfaceControlViewHost 成员变量 

    •        WindowlessWindowManager mWm, 构造时传入,或者构造时创建。为IWindowSession 子类, 该类并不将一个view加入到wms中作为窗口管理, 而是将该view作为一个子surface加入到另一个父surface中。构造时创建时, 使用本类的mSurfaceControl作为参数, 作为WindowlessWindowManager的mRootSurface。 WindowlessWindowManager类的addToDisplay是按照 WindowManager.LayoutParams 创建一个surfacecontrol, 该surfacecontrol 对应SurfaceFlinger的buffer Layer, 分配具体的绘制buffer, 绘制进程的view 即绘制在该surface上。 该surface 存入WindowlessWindowManager.State.mSurfaceControl, mRootSurface为其parent。 WindowlessWindowManager类的relayout()中按照输入高宽及LayoutParams调整WindowlessWindowManager.State.mSurfaceControl的参数。 
    •        ViewRootImpl mViewRoot;  在SurfaceControlViewHost类构造时创建, 传入的参数为WindowlessWindowManager, 构造时会调用ViewRootImpl.forceDisableBLAST(),即绘制buffer在surfaceFlinger侧分配管理, 而不是在app侧。 
    •        SurfaceControl mSurfaceControl;  //构造时创建, 名字为“SurfaceControlViewHost”, 对应SurfaceFlinger中的ContainerLayer, 作为整个绘制surface的根。 其子layer 为在WindowlessWindowManager.addToDisplay中创建的buffer layer。 mSurfaceControl也作为根layer通过SurfacePackage传递给远端显示进程。 

    SurfaceControlViewHost成员函数       

    • getSurfacePackage() :创建SurfacePackage:  new SurfacePackage(mSurfaceControl, mAccessibilityEmbeddedConnection); 其中SurfaceControlViewHost.mSurfaceControl 也作为SurfacePackage的mSurfaceControl, 会加入到显示进程中的SurfaceView中。
    • setView(View, ......): 最终调用的是mViewRoot.setView(view, attrs, null),进而调用WindowlessWindowManager.addToDisplay() 和relayout(), 将该view内容与WindowlessWindowManager.State.mSurfaceControl关联。 该mSurfaceControl即为buffer  layer。
    • surfacecontrol 层级关系

    - SurfaceControlViewHost: mSurfaceControl (contrainer layer)

            -  WindowlessWindowManager.State.mSurfaceControl (buffer laye)

    示例代码

    • host端即绘制进程

    参见: /frameworks/base/core/java/android/service/autofill/InlineSuggestionRenderService.java:170  

    1. final SurfaceControlViewHost host = new SurfaceControlViewHost(this, getDisplay(),
    2.                       hostInputToken);
    3.     host.setView(suggestionRoot, lp);
    4.     aidlClass.aidlFunction(host.getSurfacePackage());  //通过aidl接口将SurfacePackage交给显示进程即client端。 


        

    • client端即显示进程

    1.  SurfaceHolder.Callback.surfaceCreated() {
    2.      从远程host中获取SurfaceControlViewHost.SurfacePackage。 可以显示进程调用aidl接口从绘制进程获取,或绘制进程调用aidl传入到显示进程。
    3.      SurfaceView.setChildSurfacePackage(SurfacePackage);
    4. }

    Client端Surfaceview的层次结构如下:

    SurfaceView hierarchy
     - ViewRootImpl surface
          - bounds layer (crops all child surfaces to parent surface insets)
              - SurfaceView surface (drawn relative to ViewRootImpl surface)

                   - SurfaceControlViewHost.SurfacePackage surface  

              - Background color layer (drawn behind all SurfaceView surfaces)

  • 相关阅读:
    Day17:C++ WITH Easyx
    【Redis】谈谈我对Redis布隆过滤器的理解
    js录制屏幕并输出视频
    基于开源IM即时通讯框架MobileIMSDK:RainbowChat v10.0版已发布
    JUC中的AQS底层详细超详解
    SpringMVC 01: SpringMVC + 第一个SpringMVC项目
    最长序列问题(动态规划)
    Find My资讯|首款支持苹果Find My电动滑板车发布
    ocserv,anyconnect
    隧道调频广播覆盖-天线分布式部署是隧道调频广播无线覆盖系统设备介绍
  • 原文地址:https://blog.csdn.net/april_12345/article/details/133749602