SurfaceSession是Android系统中与图形表面相关的一个关键类,它提供了与SurfaceFlinger服务通信以创建和管理图形表面连接的API,SurfaceSession在WindowManagerService的addWindow时创建,构造方法如下:
1
2
3
4
5
6
| //frameworks/base/core/java/android/view/SurfaceSession.java
public final class SurfaceSession {
public SurfaceSession() {
mNativeClient = nativeCreate();
}
}
|
调用nativeCreate方法,nativeCreate是个Native方法,通过查表调用android_view_SurfaceSession.cpp的nativeCreate方法:
1
2
3
4
5
6
| //frameworks/base/core/jni/android_view_SurfaceSession.cpp
static jlong nativeCreate(JNIEnv* env, jclass clazz) {
SurfaceComposerClient* client = new SurfaceComposerClient(); //创建SurfaceComposerClient对象
client->incStrong((void*)nativeCreate);
return reinterpret_cast<jlong>(client);
}
|
通过new的方式创建SurfaceComposerClient对象,SurfaceComposerClient的构造方法如下:
1
2
3
4
| //frameworks/native/libs/gui/SurfaceComposerClient.cpp
class SurfaceComposerClient : public RefBase
SurfaceComposerClient::SurfaceComposerClient() : mStatus(NO_INIT) {}
}
|