main_surfaceflinger.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <sys/resource.h>
  17. #include <cutils/sched_policy.h>
  18. #include <binder/IServiceManager.h>
  19. #include <binder/IPCThreadState.h>
  20. #include <binder/ProcessState.h>
  21. #include <binder/IServiceManager.h>
  22. #include "SurfaceFlinger.h"
  23. #include "DisplayUtils.h"
  24. using namespace android;
  25. int main(int, char**) {
  26. // When SF is launched in its own process, limit the number of
  27. // binder threads to 4.
  28. ProcessState::self()->setThreadPoolMaxThreadCount(4);
  29. // start the thread pool
  30. sp<ProcessState> ps(ProcessState::self());
  31. ps->startThreadPool();
  32. // instantiate surfaceflinger
  33. sp<SurfaceFlinger> flinger = DisplayUtils::getInstance()->getSFInstance();
  34. setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
  35. set_sched_policy(0, SP_FOREGROUND);
  36. #ifdef ENABLE_CPUSETS
  37. // Put most SurfaceFlinger threads in the system-background cpuset
  38. // Keeps us from unnecessarily using big cores
  39. // Do this after the binder thread pool init
  40. set_cpuset_policy(0, SP_SYSTEM);
  41. #endif
  42. // initialize before clients can connect
  43. flinger->init();
  44. // publish surface flinger
  45. sp<IServiceManager> sm(defaultServiceManager());
  46. sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);
  47. // run in this thread
  48. flinger->run();
  49. return 0;
  50. }