安卓高手之路之 GDI图形引擎篇
1.底层C++
SufaceFlinger类图的静态结构
2.上层Java的调用流程。
首先,直接从WindowManagerService入手:
public int relayoutWindow(Session session, IWindow client, int seq,
WindowManager.LayoutParams attrs, int requestedWidth,
int requestedHeight, int viewVisibility, int flags,
Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Configuration outConfig, Surface outSurface)
这个方法中有一句:
创建Surface,然后继续跟下去,跟到了jni(android_view_Surface.cpp)的如下方法:
static void Surface_init(
JNIEnv* env, jobject clazz,
jobject session,
jint, jstring jname, jint dpy, jint w, jint h, jint format, jint flags)
{
if (session == NULL) {
doThrowNPE(env);
return;
}
SurfaceComposerClient* client =
(SurfaceComposerClient*)env->GetIntField(session, sso.client);
sp<SurfaceControl> surface;
if (jname == NULL) {
surface = client->createSurface(dpy, w, h, format, flags);
} else {
const jchar* str = env->GetStringCritical(jname, 0);
const String8 name(str, env->GetStringLength(jname));
env->ReleaseStringCritical(jname, str);
surface = client->createSurface(name, dpy, w, h, format, flags);
}
if (surface == 0) {
jniThrowException(env, OutOfResourcesException, NULL);
return;
}
setSurfaceControl(env, clazz, surface);
}
郁闷的是这个session又是如何初始化的,同样在android_view_Surface.cpp中:
static void SurfaceSession_init(JNIEnv* env, jobject clazz)
{
sp<SurfaceComposerClient> client = new SurfaceComposerClient;
client->incStrong(clazz);
env->SetIntField(clazz, sso.client, (int)client.get());
}
public class SurfaceSession {
/** Create a new connection with the surface flinger. */
public SurfaceSession() {
init();
}
/** Forcibly detach native resources associated with this object.
* Unlike destroy(), after this call any surfaces that were created
* from the session will no longer work. The session itself is destroyed.
*/
public native void kill();
/* no user serviceable parts here ... */
@Override
protected void finalize() throws Throwable {
destroy();
}
private native void init();
private native void destroy();
private int mClient;
}
好了,现在回到java层继续看Surface。现在的概念应该很明确了,从本质上来说,Surface是由SurfaceSession创建的。那么SurfaceSession 又是由谁创建的呢? 既然SurfaceSession 是Session的成员变量,那么就顺藤摸瓜去看:
void windowAddedLocked() {
if (mSurfaceSession == null) {
if (WindowManagerService.localLOGV) Slog.v(
WindowManagerService.TAG, "First window added to " + this + ", creating SurfaceSession");
mSurfaceSession = new SurfaceSession();
if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
WindowManagerService.TAG, " NEW SURFACE SESSION " + mSurfaceSession);
mService.mSessions.add(this);
}
mNumWindow++;
}
那么windowAddedLocked又是谁调用的呢?在WIndowState.java中:
void attach() {
if (WindowManagerService.localLOGV) Slog.v(
WindowManagerService.TAG, "Attaching " + this + " token=" + mToken
+ ", list=" + mToken.windows);
mSession.windowAddedLocked();
}
那么这个attach又是谁调用的呢?WindowManagerService.java的一个方法,如下:
public int addWindow(Session session, IWindow client, int seq,
WindowManager.LayoutParams attrs, int viewVisibility,
Rect outContentInsets, InputChannel outInputChannel)
由于这个方法比较长,就不贴了,只看其中最关键的地方,其中有这么一句话:
- 大小: 54 KB
- 查看图片附件
安卓高手之路之 GDI图形引擎篇相关推荐
- 安卓高手之路之ClassLoader(总结篇)
安卓系统对ClassLoader的设计可谓别有用心.前面分析过,赋值的地方如下: const char* envStr = getenv("CLASSPATH"); if (env ...
- 安卓高手之路 图形系统(2)----------------基于Binder的架构思路)
在学习安卓的时候最迷惑的就是Binder.图形框架的理解与Binder的理解分不开.前面一篇 [ 安卓高手之路之java层Binder 从代码角度分析了Java层Binder的实现原理.在C++层,这 ...
- 安卓高手之路 图形系统(4 Measure的算法)
安卓高手之路 图形系统(4 Measure的算法) - 修补C++ - ITeye技术网站 Java代码 /** * Does the hard part of measureChildren: ...
- 安卓高手之路之 ClassLoader
我不喜欢那些泛泛而谈的去讲那些形而上学的道理,更不喜欢记那些既定的东西.靠记忆去弥补思考的人,容易陷入人云亦云的境地,最后必定被记忆所围困,而最终消亡的是创造力.希望这个高手之路系列能够记录我学习安卓 ...
- 安卓高手之路之 图形系统之 图形框架(1)
安卓图形系统理解起来并不容易.那是因为系统对于数据的封装非常多,图形模块与输入输出,应用程序管理等模块参杂在一起.让开发者很难摸清其中的脉络.下面先给出最简单的一张图. 这张图 ...
- 安卓高手之路之 应用篇
1. 安装应用流程: PackageManagerService的installPackage 调用 InstallArgs的copyAPK完成了安装.如果在SD卡中,那么调用SdInstallArg ...
- 安卓高手之路之图形系统(6)ListView继续
综述: 本篇首先介绍了ListView的实现细节.然后介绍了Gallery,ListView,ViewPager的效率对比分析.以及效率低下的原因.最后给出了一些解决方案. 1.在上一篇讨论了requ ...
- [置顶] 安卓高手之路之ClassLoader(二)
因为ClassLoader一定与虚拟机的启动有关系,那么必须从Zygote的启动开始看代码.下面就分析一下这些代码,行数不多: int main(int argc, const char* const ...
- [置顶] 安卓高手之路之 WindowManager
安卓中的画面不是纯粹由window组成.而是改成了window+view的组织模式.window是一个顶层窗口的概念.view就相当于在window内的控件.而subwindow则是依附于window ...
最新文章
- OBJECT subcommand [arguments [arguments ...]]
- 干货 | 你真的了解 Convolutional Neural Networks 么
- Android香露刀之SeekBar之双管齐下
- CodeForces - 1516D Cut(思维+倍增)
- VS2015 中使用 MVC4
- 复旦的NLP——fudanNLP
- 闪聚支付前端部署指南
- 获取字符串中 图片路径
- Life's A Struggle
- 标题利用pwdump、lc7、hashcat工具破解用户口令(基于win7环境下)
- 使用Houdini快速将图片转换成文字模型
- numpy.array和python列表的转换
- JavaScript常用的工具函数,不全面大家补充哦
- 推荐多款免费的开源建站系统和内容管理系统
- FileProvider路径记录
- 无法启动Outlook,无法打开Outlook…
- python 读写json文件
- 验证身份证号 格式问题
- 小程序之基于canvas绘制高铁线路图
- Ubuntu-卸载Docker
热门文章
- 大工14春《计算机应用基础》在线测试2,大工14春《计算机应用基础》在线测试2...
- 大物实验总结模板_高考化学实验题答题模板归类总结!
- 上传附件每次都是上传中。_起标题头疼?每次卡在标题上 我都回顾这7种方法 创作灵感就来了...
- C++知识点10——函数指针
- MFC多线程同步互斥
- 超详细 Nginx 极简教程,傻瓜一看也会!
- Redis Sentinel--运维管理
- find、sed、awk、grep命令总结
- Atitit.eclipse 4.3 4.4 4.5 4.6新特性
- 从架构演进的角度聊聊Spring Cloud都做了些什么?