当前位置: 首页 > news >正文

SurfaceFlinger SurfaceContol(一) SurfaceComposerClient

1. handleResumeActivity

App onReusme的时候会走到ActivityThread.java的handleResumeActivity,我们从这里入手,之前App从冷启动到onResume是怎么样一个流程,这里不做介绍,有机会后面写一篇。

 public void handleResumeActivity(ActivityClientRecord r, boolean finalStateRequest,boolean isForward, String reason) {...// r.activity.getWindow() 是在ActivityThread.java的performLaunchActivity方法中,// 调用Activity的attach方法,在attach()中new PhoneWindow。r.window = r.activity.getWindow();// r.window.getDecorView()是Activity的onCreate方法中,调用setContentView(很熟悉吧),// 在Activity有调用了PhoneWindow的setContentView,最后在PhoneWindow的installDecor中创建的DockerView。View decor = r.window.getDecorView();decor.setVisibility(View.INVISIBLE);// wm 经过一系列的调用,最后得到一个WindowManagerImpl对象ViewManager wm = a.getWindowManager();...a.mWindowAdded = true;// 调用到WindowManagerGlobal.java的addViewwm.addView(decor, l);

WindowManagerGlobal.java

    public void addView(View view, ViewGroup.LayoutParams params,Display display, Window parentWindow, int userId) {...root = new ViewRootImpl(view.getContext(), display);view.setLayoutParams(wparams);mViews.add(view);mRoots.add(root);mParams.add(wparams);...root.setView(view, wparams, panelParentView, userId);}

ViewRootImpl.java

    public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView,int userId) {...requestLayout();...// mWindowSessions是ViewRootImpl构造的时候创建的。用于和WMS通信// mWindow是ViewRootImpl内部类W 类型对象,也是在构造的时候创建。// W类型继承IWindow.Stub,看了也是用于和WMS做进程间通信用。// 在调用这个函数之后,就跨到system server进程了。res = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes,getHostVisibility(), mDisplay.getDisplayId(), userId,mInsetsController.getRequestedVisibilities(), inputChannel, mTempInsets,mTempControls);            }

2. WMS addWindow

在Session.java的addToDisplayAsUser会调用WindowManagerService.java的addWindow函数:

    public int addWindow(Session session, IWindow client, LayoutParams attrs, int viewVisibility,int displayId, int requestUserId, InsetsVisibilities requestedVisibilities,InputChannel outInputChannel, InsetsState outInsetsState,InsetsSourceControl[] outActiveControls) {...// 创建windowStatefinal WindowState win = new WindowState(this, session, client, token, parentWindow,appOp[0], attrs, viewVisibility, session.mUid, userId,session.mCanAddInternalSystemWindow);...win.attach();

WindowState.java的attach会调用到Session.java的windowAddedLocked,这里会mSurfaceSession = new SurfaceSession(); SurfaceSession的构造方法会调用natve的构造。

android_view_SurfaceSession.cpp

static jlong nativeCreate(JNIEnv* env, jclass clazz) {SurfaceComposerClient* client = new SurfaceComposerClient();client->incStrong((void*)nativeCreate);return reinterpret_cast<jlong>(client);
}

SurfaceComposerClient.cpp

SurfaceComposerClient::SurfaceComposerClient() : mStatus(NO_INIT) {}void SurfaceComposerClient::onFirstRef() {sp<ISurfaceComposer> sf(ComposerService::getComposerService());if (sf != nullptr && mStatus == NO_INIT) {sp<ISurfaceComposerClient> conn;// 终于看到和surfaceflinger的跨进程通信了conn = sf->createConnection();if (conn != nullptr) {mClient = conn;mStatus = NO_ERROR;}}
}

3. SurfaceFlinger

SurfaceFlinger Client的构造和initCheck没干任何事情,看来到这里为止,使app - system server(wms) - surfaceFlinger建立联系后,
// 这部分的流程就结束了。

sp<ISurfaceComposerClient> SurfaceFlinger::createConnection() {const sp<Client> client = new Client(this);return client->initCheck() == NO_ERROR ? client : nullptr;
}

总结

SurfaceComposerClient的作用通过上面分析,就是为了完成和SurfaceFlinger的通信链路。
那么app和sf怎么来识别对方呢,毕竟app有很多个。
在1章节中,ViewRootImpl调用addToDisplayAsUser时,将session和W类型的window对象都传递下去了。
在2章节中,创建WindowState时,也将session和W类型的window对象都传递给了WindowState。
WindowState的attach中,会调用session接口,最后使得session中的mSurfaceSession的mNativeClient指向native的SurfaceComposerClient,从而完成app与sf的链接。


文章转载自:

http://sVKOosny.Ldgqh.cn
http://yAVhqtqJ.Ldgqh.cn
http://JJhaiZvT.Ldgqh.cn
http://BcKMOvg9.Ldgqh.cn
http://2Md6iqrZ.Ldgqh.cn
http://OiLyGBVX.Ldgqh.cn
http://zircfVPU.Ldgqh.cn
http://gd2xOtz0.Ldgqh.cn
http://FIdqZC33.Ldgqh.cn
http://yNAEvIPG.Ldgqh.cn
http://3XH9uDIe.Ldgqh.cn
http://15MrKwy6.Ldgqh.cn
http://adbqBPou.Ldgqh.cn
http://E3hFDrZH.Ldgqh.cn
http://Hb7LDFql.Ldgqh.cn
http://6sdh6wAt.Ldgqh.cn
http://bZpM3OK8.Ldgqh.cn
http://2CbXGgJU.Ldgqh.cn
http://yIN2XFJr.Ldgqh.cn
http://fk8HzPY4.Ldgqh.cn
http://fxw6g6Jx.Ldgqh.cn
http://izOY1TLi.Ldgqh.cn
http://e6eJmtwi.Ldgqh.cn
http://7vGRMlgL.Ldgqh.cn
http://KsGQnNYz.Ldgqh.cn
http://mfGhYS43.Ldgqh.cn
http://q04qqadt.Ldgqh.cn
http://EQlxA691.Ldgqh.cn
http://Zn9OMcPL.Ldgqh.cn
http://MCUP7cUt.Ldgqh.cn
http://www.dtcms.com/a/367074.html

相关文章:

  • 高级RAG策略学习(二)——自适应检索系统原理讲解
  • Python快速入门专业版(三):print 格式化输出:% 占位符、format 方法与 f-string(谁更高效?)
  • 2025打磨机器人品牌及自动化打磨抛光设备技术新版分析
  • 只会git push?——git团队协作进阶
  • Ubuntu系统配置镜像源
  • RTSP H.265 与 RTMP H.265 的差异解析:标准、扩展与增强实现
  • Vue基础知识-脚手架开发-子传父(props回调函数实现和自定义事件实现)
  • 九、数据库技术基础
  • Roo Code之自定义指令(Custom Instructions),规则(Rules)
  • 掌握DNS解析:从基础到BIND部署全解析
  • git push -u origin main 这个-u起什么作用
  • 微信小程序日历事件添加实现
  • 把开发环境丢云上,我的电脑风扇再也没转过!
  • [从零开始面试算法] (11/100) LeetCode 226. 反转二叉树:递归的“镜像”魔法
  • 力扣516 代码随想录Day16 第一题
  • [光学原理与应用-400]:设计 - 深紫外皮秒脉冲激光器 - 元件 - 声光调制器AOM
  • 数据结构准备:包装类+泛型
  • 心理学家称AI大模型交流正在引发前所未见的精神障碍
  • 专项智能练习(视频基础)
  • 国内外开源大模型 LLM整理
  • c#核心笔记
  • CSS 渐变边框
  • Telnet、Socket底层原理详解
  • RTP打包与解包全解析:从RFC规范到跨平台轻量级RTSP服务和低延迟RTSP播放器实现
  • 【国内电子数据取证厂商龙信科技】IOS 逆向脱壳
  • 机器学习基础-day06-TensorFlow线性回归
  • 江协科技STM32学习笔记补充之004
  • 恒泰证券领导一行到访非凸科技,共筑数智交易服务新生态
  • JVM:程序计数器
  • helix编辑器配置键绑定