安卓高手之路之 GDI图形引擎篇
来源:互联网 发布:mac最好的视频播放器 编辑:程序博客网 时间:2024/06/06 11:37
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 surface = win.createSurfaceLocked();
创建Surface,然后继续跟下去,跟到了jni(android_view_Surface.cpp)的如下方法:
创建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());}
非常好,那么这个client就是和java层SurfaceSession构成了一一对应关系咯?事实的确如此。看java层的
SurfaceSession的定义,里面仅有的成员变量就是这个client:
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)由于这个方法比较长,就不贴了,只看其中最关键的地方,其中有这么一句话:
win.attach();
经过这么一分析,清楚了,SurfaceSession是WindowManagerService在addWindow的时候创建的。而
Surface是在WIndowManagerService进行relayoutWindow时创建的。
阅读全文
0 0
- 安卓高手之路之 GDI图形引擎篇
- 安卓高手之路之 图形系统之 图形框架(1)
- 安卓高手之路之图形系统(6)requestLayout的流程
- 安卓高手之路之图形系统(6)requestLayout的流程
- 安卓高手之路之图形系统(6)requestLayout的流程
- 安卓高手之路之图形系统(6)requestLayout的流程
- 安卓高手之路之图形系统(6)ListView继续
- 安卓高手之路之图形系统【5】安卓ListView和EditText配合使用时的注意事项。
- 安卓高手之路之 ClassLoader
- 安卓高手之路之PackageManagerservice
- 安卓高手之路 图形系统(2)----------------基于Binder的架构思路)
- 安卓高手之路 图形系统(3 底层SurfceFlinger系统)
- 安卓高手之路 图形系统(4 Measure的算法)
- 安卓高手之路之 应用篇
- 安卓高手之路之ClassLoader(总结篇)
- 图形之GDI
- GDI+学习之路8--图形容器
- GDI+学习之路8--图形容器
- Linux内核设计与实现读书笔记
- mybatis源码阅读之SqlSessionFactory创建
- R语言版本升级
- JQuery 自动触发事件
- 关于android 经典蓝牙开发 使用UUID连接的问题
- 安卓高手之路之 GDI图形引擎篇
- 安卓高手之路之 应用篇
- DB2基础知识学习
- Linux awk 命令
- 算法——算法分析
- 安卓高手之路之 ClassLoader
- 斐波拉契数列的三种解法
- POJ1001
- 安卓高手之路之ClassLoader(二)