main_surfaceflinger.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <sched.h>
  18. #include <android/frameworks/displayservice/1.0/IDisplayService.h>
  19. #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
  20. #include <android/hardware/graphics/allocator/2.0/IAllocator.h>
  21. #include <android/hardware/graphics/allocator/3.0/IAllocator.h>
  22. #include <binder/IPCThreadState.h>
  23. #include <binder/IServiceManager.h>
  24. #include <binder/ProcessState.h>
  25. #include <configstore/Utils.h>
  26. #include <displayservice/DisplayService.h>
  27. #include <hidl/LegacySupport.h>
  28. #include <processgroup/sched_policy.h>
  29. #include "SurfaceFlinger.h"
  30. #include "SurfaceFlingerFactory.h"
  31. #include "SurfaceFlingerProperties.h"
  32. using namespace android;
  33. static status_t startGraphicsAllocatorService() {
  34. using android::hardware::configstore::getBool;
  35. using android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
  36. if (!android::sysprop::start_graphics_allocator_service(false)) {
  37. return OK;
  38. }
  39. status_t result = hardware::registerPassthroughServiceImplementation<
  40. android::hardware::graphics::allocator::V3_0::IAllocator>();
  41. if (result == OK) {
  42. return OK;
  43. }
  44. result = hardware::registerPassthroughServiceImplementation<
  45. android::hardware::graphics::allocator::V2_0::IAllocator>();
  46. if (result != OK) {
  47. ALOGE("could not start graphics allocator service");
  48. return result;
  49. }
  50. return OK;
  51. }
  52. static status_t startDisplayService() {
  53. using android::frameworks::displayservice::V1_0::implementation::DisplayService;
  54. using android::frameworks::displayservice::V1_0::IDisplayService;
  55. sp<IDisplayService> displayservice = new DisplayService();
  56. status_t err = displayservice->registerAsService();
  57. if (err != OK) {
  58. ALOGE("Could not register IDisplayService service.");
  59. }
  60. return err;
  61. }
  62. int main(int, char**) {
  63. OtherSystemServiceLoopRun();
  64. signal(SIGPIPE, SIG_IGN);
  65. hardware::configureRpcThreadpool(1 /* maxThreads */,
  66. false /* callerWillJoin */);
  67. startGraphicsAllocatorService();
  68. // When SF is launched in its own process, limit the number of
  69. // binder threads to 4.
  70. ProcessState::self()->setThreadPoolMaxThreadCount(4);
  71. // start the thread pool
  72. sp<ProcessState> ps(ProcessState::self());
  73. ps->startThreadPool();
  74. // instantiate surfaceflinger
  75. sp<SurfaceFlinger> flinger = surfaceflinger::createSurfaceFlinger();
  76. setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
  77. set_sched_policy(0, SP_FOREGROUND);
  78. // Put most SurfaceFlinger threads in the system-background cpuset
  79. // Keeps us from unnecessarily using big cores
  80. // Do this after the binder thread pool init
  81. if (cpusets_enabled()) set_cpuset_policy(0, SP_SYSTEM);
  82. // initialize before clients can connect
  83. flinger->init();
  84. // publish surface flinger
  85. sp<IServiceManager> sm(defaultServiceManager());
  86. sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false,
  87. IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO);
  88. startDisplayService(); // dependency on SF getting registered above
  89. struct sched_param param = {0};
  90. param.sched_priority = 2;
  91. if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
  92. ALOGE("Couldn't set SCHED_FIFO");
  93. }
  94. // run surface flinger in this thread
  95. flinger->run();
  96. return 0;
  97. }