1 /*
2 * Copyright 2021, 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 <binder/ProcessState.h>
21 #include <sched.h>
22
23 #include "Composer.h"
24
25 using aidl::android::hardware::graphics::composer3::impl::Composer;
26 using aidl::android::hardware::graphics::composer3::impl::IComposerHal;
27
28 using android::base::InitLogging;
29 using android::base::StderrLogger;
30 using android::sp;
31
main(int,char * argv[])32 int main(int /*argc*/, char* argv[]) {
33 InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
34 LOG(INFO) << "hwc3 starting up";
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, ¶m) != 0) {
40 LOG(ERROR) << "Couldn't set SCHED_FIFO: " << errno;
41 }
42
43 std::shared_ptr<Composer> composer = ndk::SharedRefBase::make<Composer>();
44 CHECK(composer != nullptr);
45
46 const std::string instance = std::string() + Composer::descriptor + "/default";
47 binder_status_t status =
48 AServiceManager_addService(composer->asBinder().get(), instance.c_str());
49 CHECK(status == STATUS_OK);
50
51 // Thread pool for vendor libbinder for internal vendor services
52 android::ProcessState::self()->setThreadPoolMaxThreadCount(2);
53 android::ProcessState::self()->startThreadPool();
54
55 // Thread pool for system libbinder (via libbinder_ndk) for aidl services
56 // IComposer and IDisplay
57 ABinderProcess_setThreadPoolMaxThreadCount(5);
58 ABinderProcess_startThreadPool();
59 ABinderProcess_joinThreadPool();
60
61 return EXIT_FAILURE; // should not reach
62 }
63