快速理解SurfaceFlinger 一、编译

1.代码路径

android 7.1  frameworks/native/services/surfaceflinger

1.1代码结构:

.
├── Android.mk
├── Barrier.h
├── Client.cpp
├── Client.h
├── clz.h
├── Colorizer.h
├── DdmConnection.cpp
├── DdmConnection.h
├── DisplayDevice.cpp
├── DisplayDevice.h
├── DisplayHardware
│   ├── DisplaySurface.h
│   ├── FloatRect.h
│   ├── FramebufferSurface.cpp
│   ├── FramebufferSurface.h
│   ├── HWC2.cpp
│   ├── HWC2.h
│   ├── HWC2On1Adapter.cpp
│   ├── HWC2On1Adapter.h
│   ├── HWComposer.cpp
│   ├── HWComposer.h
│   ├── HWComposer_hwc1.cpp
│   ├── HWComposer_hwc1.h
│   ├── PowerHAL.cpp
│   ├── PowerHAL.h
│   ├── VirtualDisplaySurface.cpp
│   └── VirtualDisplaySurface.h
├── DispSync.cpp
├── DispSync.h
├── Effects
│   ├── Daltonizer.cpp
│   └── Daltonizer.h
├── EventControlThread.cpp
├── EventControlThread.h
├── EventLog
│   ├── EventLog.cpp
│   ├── EventLog.h
│   └── EventLogTags.logtags
├── EventThread.cpp
├── EventThread.h
├── FenceTracker.cpp
├── FenceTracker.h
├── FrameTracker.cpp
├── FrameTracker.h
├── GpuService.cpp
├── GpuService.h
├── Layer.cpp
├── LayerDim.cpp
├── LayerDim.h
├── Layer.h
├── main_surfaceflinger.cpp
├── MessageQueue.cpp
├── MessageQueue.h
├── MODULE_LICENSE_APACHE2
├── MonitoredProducer.cpp
├── MonitoredProducer.h
├── RenderEngine
│   ├── Description.cpp
│   ├── Description.h
│   ├── GLES10RenderEngine.cpp
│   ├── GLES10RenderEngine.h
│   ├── GLES11RenderEngine.cpp
│   ├── GLES11RenderEngine.h
│   ├── GLES20RenderEngine.cpp
│   ├── GLES20RenderEngine.h
│   ├── GLExtensions.cpp
│   ├── GLExtensions.h
│   ├── Mesh.cpp
│   ├── Mesh.h
│   ├── ProgramCache.cpp
│   ├── ProgramCache.h
│   ├── Program.cpp
│   ├── Program.h
│   ├── RenderEngine.cpp
│   ├── RenderEngine.h
│   ├── Texture.cpp
│   └── Texture.h
├── SurfaceFlingerConsumer.cpp
├── SurfaceFlingerConsumer.h
├── SurfaceFlinger.cpp
├── SurfaceFlinger.h
├── SurfaceFlinger_hwc1.cpp
├── surfaceflinger.rc
├── tests
│   ├── Android.mk
│   ├── Transaction_test.cpp
│   ├── vsync
│   │   ├── Android.mk
│   │   └── vsync.cpp
│   └── waitforvsync
│       ├── Android.mk
│       └── waitforvsync.cpp
├── Transform.cpp
└── Transform.h
 

1.2 编译使用Android.mk

快速理解SurfaceFlinger 一、编译_第1张图片

生成SurfaceFlinger 依赖库,so文件。android通用模式,对native服务生成so库,在main函数中使用,或者其他client端使用。

快速理解SurfaceFlinger 一、编译_第2张图片

LOCAL_SHARED_LIBRARIES := \
    libsurfaceflinger

对上述so库引用。

LOCAL_SRC_FILES := \
    main_surfaceflinger.cpp

主进程入口,使用此文件编译成可执行文件。

main_surfaceflinger.cpp :

int main(int, char**) {
    signal(SIGPIPE, SIG_IGN);
    // When SF is launched in its own process, limit the number of
    // binder threads to 4.
    ProcessState::self()->setThreadPoolMaxThreadCount(4);//设置线程最大数

    // start the thread pool
    sp ps(ProcessState::self());
    ps->startThreadPool();

    // instantiate surfaceflinger
    sp flinger = new SurfaceFlinger();//实例化

    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);

    set_sched_policy(0, SP_FOREGROUND);

#ifdef ENABLE_CPUSETS
    // Put most SurfaceFlinger threads in the system-background cpuset
    // Keeps us from unnecessarily using big cores
    // Do this after the binder thread pool init
    set_cpuset_policy(0, SP_SYSTEM);
#endif

    // initialize before clients can connect
    flinger->init();

    // publish surface flinger
    sp sm(defaultServiceManager());
    sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);//这里很明显是注册服务,提供给client调动

    // publish GpuService
    sp gpuservice = new GpuService();//一起注册GpuService,耦合性高
    sm->addService(String16(GpuService::SERVICE_NAME), gpuservice, false);

    struct sched_param param = {0};
    param.sched_priority = 2;
    if (sched_setscheduler(0, SCHED_FIFO, ¶m) != 0) {
        ALOGE("Couldn't set SCHED_FIFO");
    }

    // run surface flinger in this thread
    flinger->run();//跑起来

    return 0;
}

 

 

你可能感兴趣的:(显示系统)