1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker * Copyright 2024, The Android Open Source Project
3*0a9764feSAndroid Build Coastguard Worker *
4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*0a9764feSAndroid Build Coastguard Worker *
8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*0a9764feSAndroid Build Coastguard Worker *
10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*0a9764feSAndroid Build Coastguard Worker * limitations under the License.
15*0a9764feSAndroid Build Coastguard Worker */
16*0a9764feSAndroid Build Coastguard Worker
17*0a9764feSAndroid Build Coastguard Worker #define LOG_TAG "drmhwc"
18*0a9764feSAndroid Build Coastguard Worker #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
19*0a9764feSAndroid Build Coastguard Worker
20*0a9764feSAndroid Build Coastguard Worker #include <android/binder_manager.h>
21*0a9764feSAndroid Build Coastguard Worker #include <android/binder_process.h>
22*0a9764feSAndroid Build Coastguard Worker #include <sched.h>
23*0a9764feSAndroid Build Coastguard Worker
24*0a9764feSAndroid Build Coastguard Worker #include "Composer.h"
25*0a9764feSAndroid Build Coastguard Worker #include "utils/log.h"
26*0a9764feSAndroid Build Coastguard Worker
27*0a9764feSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::impl::Composer;
28*0a9764feSAndroid Build Coastguard Worker
main(int,char * argv[])29*0a9764feSAndroid Build Coastguard Worker int main(int /*argc*/, char* argv[]) {
30*0a9764feSAndroid Build Coastguard Worker (void)argv;
31*0a9764feSAndroid Build Coastguard Worker ALOGI("hwc3-drm starting up");
32*0a9764feSAndroid Build Coastguard Worker
33*0a9764feSAndroid Build Coastguard Worker // same as SF main thread
34*0a9764feSAndroid Build Coastguard Worker struct sched_param param = {0};
35*0a9764feSAndroid Build Coastguard Worker param.sched_priority = 2;
36*0a9764feSAndroid Build Coastguard Worker if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, ¶m) != 0) {
37*0a9764feSAndroid Build Coastguard Worker ALOGE("Couldn't set SCHED_FIFO: %d", errno);
38*0a9764feSAndroid Build Coastguard Worker }
39*0a9764feSAndroid Build Coastguard Worker
40*0a9764feSAndroid Build Coastguard Worker auto composer = ndk::SharedRefBase::make<Composer>();
41*0a9764feSAndroid Build Coastguard Worker if (!composer) {
42*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to create composer");
43*0a9764feSAndroid Build Coastguard Worker return -ENOMEM;
44*0a9764feSAndroid Build Coastguard Worker }
45*0a9764feSAndroid Build Coastguard Worker
46*0a9764feSAndroid Build Coastguard Worker const std::string instance = std::string() + Composer::descriptor +
47*0a9764feSAndroid Build Coastguard Worker "/default";
48*0a9764feSAndroid Build Coastguard Worker ALOGI("HWC3 service name %s", instance.c_str());
49*0a9764feSAndroid Build Coastguard Worker #if __ANDROID_API__ >= 34
50*0a9764feSAndroid Build Coastguard Worker auto status = AServiceManager_addServiceWithFlags(
51*0a9764feSAndroid Build Coastguard Worker composer->asBinder().get(), instance.c_str(),
52*0a9764feSAndroid Build Coastguard Worker AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED);
53*0a9764feSAndroid Build Coastguard Worker #else
54*0a9764feSAndroid Build Coastguard Worker auto status = AServiceManager_addService(composer->asBinder().get(),
55*0a9764feSAndroid Build Coastguard Worker instance.c_str());
56*0a9764feSAndroid Build Coastguard Worker #endif
57*0a9764feSAndroid Build Coastguard Worker if (status != STATUS_OK) {
58*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to register service. Error %d", (int)status);
59*0a9764feSAndroid Build Coastguard Worker return -EINVAL;
60*0a9764feSAndroid Build Coastguard Worker }
61*0a9764feSAndroid Build Coastguard Worker
62*0a9764feSAndroid Build Coastguard Worker ABinderProcess_joinThreadPool();
63*0a9764feSAndroid Build Coastguard Worker return EXIT_FAILURE; // should not reach
64*0a9764feSAndroid Build Coastguard Worker }
65