xref: /aosp_15_r20/external/minigbm/cros_gralloc/aidl/Main.cpp (revision d95af8df99a05bcb8679a54dc3ab8e5cd312b38e)
1 /*
2  * Copyright 2022 The Chromium OS Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #include "Allocator.h"
8 
9 #include <android-base/logging.h>
10 #include <android/binder_manager.h>
11 #include <android/binder_process.h>
12 #include <log/log.h>
13 
14 using aidl::android::hardware::graphics::allocator::impl::Allocator;
15 
main(int,char **)16 int main(int /*argc*/, char** /*argv*/) {
17     ALOGI("Minigbm AIDL allocator starting up...");
18 
19     // same as SF main thread
20     struct sched_param param = {0};
21     param.sched_priority = 2;
22     if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
23         ALOGI("%s: failed to set priority: %s", __FUNCTION__, strerror(errno));
24     }
25 
26     auto allocator = ndk::SharedRefBase::make<Allocator>();
27     CHECK(allocator != nullptr);
28 
29     if (!allocator->init()) {
30         ALOGE("Failed to initialize Minigbm AIDL allocator.");
31         return EXIT_FAILURE;
32     }
33 
34     const std::string instance = std::string() + Allocator::descriptor + "/default";
35     binder_status_t status =
36             AServiceManager_addService(allocator->asBinder().get(), instance.c_str());
37     CHECK_EQ(status, STATUS_OK);
38 
39     ABinderProcess_setThreadPoolMaxThreadCount(4);
40     ABinderProcess_startThreadPool();
41     ABinderProcess_joinThreadPool();
42 
43     return EXIT_FAILURE;
44 }