快速理解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 依赖库,so文件。android通用模式,对native服务生成so库,在main函数中使用,或者其他client端使用。

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<ProcessState> ps(ProcessState::self());
    ps->startThreadPool();

    // instantiate surfaceflinger
    sp<SurfaceFlinger> 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<IServiceManager> sm(defaultServiceManager());
    sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);//这里很明显是注册服务,提供给client调动

    // publish GpuService
    sp<GpuService> 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, &param) != 0) {
        ALOGE("Couldn't set SCHED_FIFO");
    }

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

    return 0;
}

 

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值