Surfaceflinger - liuyq/android-issues GitHub Wiki

main_surfaceflinger.cpp

path is frameworks/native/services/surfaceflinger/main_surfaceflinger.cpp

main

help to start the GraphicsAllocatorService, SurfaceFlinger service, SurfaceComposerAIDL service, DisplayService, etc

int main(int, char**) {
    signal(SIGPIPE, SIG_IGN);

    hardware::configureRpcThreadpool(1 /* maxThreads */, false /* callerWillJoin */);

    startGraphicsAllocatorService();

    /*
     thread pool and schedule policy related settings
    */

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

    // publish surface flinger
    sp<IServiceManager> sm(defaultServiceManager());
    sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false,
                   IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO);

    // publish gui::ISurfaceComposer, the new AIDL interface
    sp<SurfaceComposerAIDL> composerAIDL = new SurfaceComposerAIDL(flinger);
    sm->addService(String16("SurfaceFlingerAIDL"), composerAIDL, false,
                   IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO);

    startDisplayService(); // dependency on SF getting registered above

    if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
        ALOGW("Couldn't set to SCHED_FIFO: %s", strerror(errno));
    }

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

    return 0;
}

frameworks/native/libs/gui/SurfaceComposerClient.cpp

  • ComposerServiceAIDL::getComposerService()
    /*static*/ sp<gui::ISurfaceComposer> ComposerServiceAIDL::getComposerService() {
        ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance();
        std::scoped_lock lock(instance.mMutex);
        if (instance.mComposerService == nullptr) {
            if (ComposerServiceAIDL::getInstance().connectLocked()) {
                ALOGD("ComposerServiceAIDL reconnected");
            }
        }
        return instance.mComposerService;
    }
    
  • ComposerService::ComposerService()
    const String16 name("SurfaceFlinger");
    mComposerService = waitForService<ISurfaceComposer>(name);
    
  • SurfaceComposerClient
    class DefaultComposerClient: public Singleton<DefaultComposerClient> {
        ...
    };
    ANDROID_SINGLETON_STATIC_INSTANCE(DefaultComposerClient);
    
    sp<SurfaceComposerClient> SurfaceComposerClient::getDefault() {
        return DefaultComposerClient::getComposerClient();
    }
    
  • SurfaceComposerClient::getPhysicalDisplayIds()
    std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
      std::vector<int64_t> displayIds;
      std::vector<PhysicalDisplayId> physicalDisplayIds;
      binder::Status status =
              ComposerServiceAIDL::getComposerService()->getPhysicalDisplayIds(&displayIds);
      if (status.isOk()) {
          physicalDisplayIds.reserve(displayIds.size());
          for (auto item : displayIds) {
              auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(item));
              physicalDisplayIds.push_back(*id);
          }
      }
      return physicalDisplayIds;
    }
    
  • SurfaceComposerClient::getPrimaryPhysicalDisplayId/getInternalDisplayId, etc

where SurfaceComposerClient::getPhysicalDisplayIds is called

  • frameworks/base/core/jni/android_view_SurfaceControl.cpp nativeGetPhysicalDisplayIds
  • frameworks/base/cmds/bootanimation/BootAnimation.cpp BootAnimation::readyToRun()/BootAnimation::parseOrientationProperty
  • frameworks/native/services/automotive/display/AutomotiveDisplayProxyService.cpp AutomotiveDisplayProxyService::getDisplayIdList
  • packages/services/Car/cpp/displayproxy/src/CarDisplayProxy.cpp CarDisplayProxy::getDisplayIdList
⚠️ **GitHub.com Fallback** ⚠️