xref: /aosp_15_r20/external/drm_hwcomposer/hwc3/service.cpp (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
1 /*
2  * Copyright 2024, 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 "drmhwc"
18 #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
19 
20 #include <android/binder_manager.h>
21 #include <android/binder_process.h>
22 #include <sched.h>
23 
24 #include "Composer.h"
25 #include "utils/log.h"
26 
27 using aidl::android::hardware::graphics::composer3::impl::Composer;
28 
main(int,char * argv[])29 int main(int /*argc*/, char* argv[]) {
30   (void)argv;
31   ALOGI("hwc3-drm starting up");
32 
33   // same as SF main thread
34   struct sched_param param = {0};
35   param.sched_priority = 2;
36   if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
37     ALOGE("Couldn't set SCHED_FIFO: %d", errno);
38   }
39 
40   auto composer = ndk::SharedRefBase::make<Composer>();
41   if (!composer) {
42     ALOGE("Failed to create composer");
43     return -ENOMEM;
44   }
45 
46   const std::string instance = std::string() + Composer::descriptor +
47                                "/default";
48   ALOGI("HWC3 service name %s", instance.c_str());
49 #if __ANDROID_API__ >= 34
50   auto status = AServiceManager_addServiceWithFlags(
51       composer->asBinder().get(), instance.c_str(),
52       AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED);
53 #else
54   auto status = AServiceManager_addService(composer->asBinder().get(),
55                                            instance.c_str());
56 #endif
57   if (status != STATUS_OK) {
58     ALOGE("Failed to register service. Error %d", (int)status);
59     return -EINVAL;
60   }
61 
62   ABinderProcess_joinThreadPool();
63   return EXIT_FAILURE;  // should not reach
64 }
65