android L 与android 4.4相同,surfaceflinger直接由init启动,不是system server。
init进程根据init.rc启动surfaceflinger服务
service surfaceflinger /system/bin/surfaceflinger class core user system group graphics drmrpc onrestart restart zygote
frameworks/native/services/surfaceflinger/main_surfaceflinger.cpp int main(int, char**) { ... // instantiate surfaceflinger sp<SurfaceFlinger> flinger = new SurfaceFlinger();//实例化SurfaceFlinger ... // initialize before clients can connect flinger->init();//初始化 // publish surface flinger sp<IServiceManager> sm(defaultServiceManager()); sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);//向service manager注册 // run in this thread flinger->run();//run起来 return 0; }
init()函数实现
frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp void SurfaceFlinger::init() { ... // initialize EGL for the default display mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(mEGLDisplay, NULL, NULL); // Initialize the H/W composer object. There may or may not be an // actual hardware composer underneath. mHwc = new HWComposer(this, *static_cast<HWComposer::EventHandler *>(this)); ... // start the EventThread sp<VSyncSource> vsyncSrc = new DispSyncSource(&mPrimaryDispSync, vsyncPhaseOffsetNs, true, "app"); mEventThread = new EventThread(vsyncSrc); sp<VSyncSource> sfVsyncSrc = new DispSyncSource(&mPrimaryDispSync, sfVsyncPhaseOffsetNs, true, "sf"); mSFEventThread = new EventThread(sfVsyncSrc); mEventQueue.setEventThread(mSFEventThread); mEventControlThread = new EventControlThread(this); mEventControlThread->run("EventControl", PRIORITY_URGENT_DISPLAY); // set a fake vsync period if there is no HWComposer if (mHwc->initCheck() != NO_ERROR) { mPrimaryDispSync.setPeriod(16666667); } // initialize our drawing state mDrawingState = mCurrentState; // set initial conditions (e.g. unblank default device) initializeDisplays(); // start boot animation startBootAnim(); }
run()函数实现如下
void SurfaceFlinger::run() { do { waitForEvent(); } while (true); }