1 /*
2  * Copyright 2016 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 #define LOG_TAG "android.hardware.graphics.composer@2.1-service"
18 
19 #include <sched.h>
20 
21 #include <android/hardware/graphics/composer/2.1/IComposer.h>
22 
23 #include <binder/ProcessState.h>
24 #include <composer-passthrough/2.1/HwcLoader.h>
25 #include <hidl/LegacySupport.h>
26 
27 using android::hardware::graphics::composer::V2_1::IComposer;
28 using android::hardware::graphics::composer::V2_1::passthrough::HwcLoader;
29 
main()30 int main() {
31     // the conventional HAL might start binder services
32     android::ProcessState::initWithDriver("/dev/vndbinder");
33     android::ProcessState::self()->setThreadPoolMaxThreadCount(4);
34     android::ProcessState::self()->startThreadPool();
35 
36     // same as SF main thread
37     struct sched_param param = {0};
38     param.sched_priority = 2;
39     if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK,
40                 &param) != 0) {
41         ALOGE("Couldn't set SCHED_FIFO: %d", errno);
42     }
43 
44     android::hardware::configureRpcThreadpool(4, true /* will join */);
45 
46     android::sp<IComposer> composer = HwcLoader::load();
47     if (composer == nullptr) {
48         return 1;
49     }
50     if (composer->registerAsService() != android::NO_ERROR) {
51         ALOGE("failed to register service");
52         return 1;
53     }
54 
55     android::hardware::joinRpcThreadpool();
56 
57     ALOGE("service is terminating");
58     return 1;
59 }
60