android flinger 源码分析

来源:互联网 发布:北京php程序员工资 编辑:程序博客网 时间:2024/05/22 06:19

一、Flinger 类图结构

二、 surfaceSession_init 流程,surface_init流程,Surface_lockCanvas流程,Surface_unlockCanvasAndPost流程


一、SurfaceFlinger 服务启动过程:

一、启动过程:

1、frameworks\base\cmds\app_process\app_main.cpp    app_process进程

int main()

{

        runtime.start("com.android.internal.os.ZygoteInit",

                startSystemServer ?"start-system-server" : "");

}

 

2. frameworks\base\core\java\com\android\internal\os\ZygoteInit.java

public static void main(String argv[]) {

                startSystemServer();}

 

startSystemServer()

{

        Stringargs[] = {

           "--runtime-init",

           "--nice-name=system_server",

           "com.android.server.SystemServer",

        };

 

            /*Request to fork the system server process */

            pid= Zygote.forkSystemServer();

 

}

 

3. frameworks\base\services\java\com\android\server\SystemServer.java

Main{}

{

       System.loadLibrary("android_servers");

        init1(args);

}

 

    native public static void init1(String[] args);

 

4. frameworks\base\services\jni\com_android_server_SystemServer.cpp

static JNINativeMethod gMethods[] = {

    /* name,signature, funcPtr */

    { "init1", "([Ljava/lang/String;)V",(void*) android_server_SystemServer_init1 },

};

 

static void android_server_SystemServer_init1(JNIEnv*env, jobject clazz)

{

    system_init();

}

 

5. frameworks\base\cmds\system_server\library\system_init.cpp

extern "C" status_t system_init()

{

        SurfaceFlinger::instantiate();

}

 

6. frameworks\base\include\binder\BinderService.h

 

    static void instantiate() { publish(); }

 

    staticstatus_t publish() {

       sp<IServiceManager> sm(defaultServiceManager());

        returnsm->addService(String16(SERVICE::getServiceName()),new SERVICE());

    }

 

 

 

二、surfaceflinger code:

1. JNI:  (frameworks\base\core\jni\android_view_Surface.cpp)

 

static JNINativeMethod gSurfaceSessionMethods[]= {

   {"init",    "()V", (void*)SurfaceSession_init },

   {"destroy", "()V", (void*)SurfaceSession_destroy },

   {"kill",    "()V", (void*)SurfaceSession_kill },

};

static JNINativeMethod gSurfaceMethods[]= {

{"nativeClassInit",     "()V",  (void*)nativeClassInit },

    {"init",               "(Landroid/view/SurfaceSession;ILjava/lang/String;IIIII)V",  (void*)Surface_init },

    {"lockCanvasNative",   "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;",  (void*)Surface_lockCanvas },

    {"show",                "()V",  (void*)Surface_show },

    {"freeze",              "()V",  (void*)Surface_freeze },

 

 

二、Client code:

 

1. SurfaceSession_init();

static void SurfaceSession_init() {

   sp<SurfaceComposerClient> client = newSurfaceComposerClient;

 

}

void SurfaceComposerClient::onFirstRef() {

       sp<ISurfaceComposerClient> conn = sm->createConnection();

            mClient =conn;

}

 

2. Surface_init ();

 

static void Surface_init(

        surface = client->createSurface(dpy, w, h, format,flags);

}

sp<SurfaceControl>SurfaceComposerClient::createSurface(

mClient->createSurface();

}

 

 

 

 


原创粉丝点击