1 /*
2  * Copyright 2022, 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 
17 #include <android-base/logging.h>
18 #include <android/binder_manager.h>
19 #include <android/binder_process.h>
20 #include <sched.h>
21 
22 #include "Composer.h"
23 
24 using aidl::android::hardware::graphics::composer3::impl::Composer;
25 
main(int,char **)26 int main(int /*argc*/, char** /*argv*/) {
27     ALOGI("RanchuHWC (HWComposer3/HWC3) starting up...");
28 
29     // same as SF main thread
30     struct sched_param param = {0};
31     param.sched_priority = 2;
32     if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
33         ALOGE("%s: failed to set priority: %s", __FUNCTION__, strerror(errno));
34     }
35 
36     auto composer = ndk::SharedRefBase::make<Composer>();
37     CHECK(composer != nullptr);
38 
39     const std::string instance = std::string() + Composer::descriptor + "/default";
40     binder_status_t status =
41         AServiceManager_addService(composer->asBinder().get(), instance.c_str());
42     CHECK(status == STATUS_OK);
43 
44     // Thread pool for system libbinder (via libbinder_ndk) for aidl services
45     // IComposer and IDisplay
46     ABinderProcess_setThreadPoolMaxThreadCount(5);
47     ABinderProcess_startThreadPool();
48     ABinderProcess_joinThreadPool();
49 
50     return EXIT_FAILURE;
51 }
52