Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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/binder_manager.h> |
| 18 | #include <android/binder_process.h> |
| 19 | #include <binder/ProcessState.h> |
| 20 | #include <sched.h> |
| 21 | |
| 22 | #include "Composer.h" |
| 23 | #include "utils/log.h" |
| 24 | |
| 25 | using aidl::android::hardware::graphics::composer3::impl::Composer; |
| 26 | |
| 27 | int main(int /*argc*/, char* argv[]) { |
| 28 | (void)argv; |
| 29 | ALOGI("hwc3-drm starting up"); |
| 30 | |
| 31 | // same as SF main thread |
| 32 | struct sched_param param = {0}; |
| 33 | param.sched_priority = 2; |
| 34 | if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, ¶m) != 0) { |
| 35 | ALOGE("Couldn't set SCHED_FIFO: %d", errno); |
| 36 | } |
| 37 | |
| 38 | auto composer = ndk::SharedRefBase::make<Composer>(); |
| 39 | if (!composer) { |
| 40 | ALOGE("Failed to create composer"); |
| 41 | return -ENOMEM; |
| 42 | } |
| 43 | |
| 44 | const std::string instance = std::string() + Composer::descriptor + |
| 45 | "/default"; |
| 46 | ALOGI("HWC3 service name %s", instance.c_str()); |
| 47 | auto status = AServiceManager_addServiceWithFlags( |
| 48 | composer->asBinder().get(), instance.c_str(), |
| 49 | AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED); |
| 50 | if (status != STATUS_OK) { |
| 51 | ALOGE("Failed to register service. Error %d", (int)status); |
| 52 | return -EINVAL; |
| 53 | } |
| 54 | |
| 55 | ABinderProcess_joinThreadPool(); |
| 56 | return EXIT_FAILURE; // should not reach |
| 57 | } |