1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 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 "Composer.h"
21*0a9764feSAndroid Build Coastguard Worker
22*0a9764feSAndroid Build Coastguard Worker #include <android-base/logging.h>
23*0a9764feSAndroid Build Coastguard Worker #include <android/binder_ibinder_platform.h>
24*0a9764feSAndroid Build Coastguard Worker
25*0a9764feSAndroid Build Coastguard Worker #include "hwc3/ComposerClient.h"
26*0a9764feSAndroid Build Coastguard Worker #include "hwc3/Utils.h"
27*0a9764feSAndroid Build Coastguard Worker #include "utils/log.h"
28*0a9764feSAndroid Build Coastguard Worker #include "utils/properties.h"
29*0a9764feSAndroid Build Coastguard Worker
30*0a9764feSAndroid Build Coastguard Worker namespace aidl::android::hardware::graphics::composer3::impl {
31*0a9764feSAndroid Build Coastguard Worker
createClient(std::shared_ptr<IComposerClient> * out_client)32*0a9764feSAndroid Build Coastguard Worker ndk::ScopedAStatus Composer::createClient(
33*0a9764feSAndroid Build Coastguard Worker std::shared_ptr<IComposerClient>* out_client) {
34*0a9764feSAndroid Build Coastguard Worker DEBUG_FUNC();
35*0a9764feSAndroid Build Coastguard Worker
36*0a9764feSAndroid Build Coastguard Worker if (!client_.expired()) {
37*0a9764feSAndroid Build Coastguard Worker return ToBinderStatus(hwc3::Error::kNoResources);
38*0a9764feSAndroid Build Coastguard Worker }
39*0a9764feSAndroid Build Coastguard Worker
40*0a9764feSAndroid Build Coastguard Worker auto client = ndk::SharedRefBase::make<ComposerClient>();
41*0a9764feSAndroid Build Coastguard Worker if (!client || !client->Init()) {
42*0a9764feSAndroid Build Coastguard Worker *out_client = nullptr;
43*0a9764feSAndroid Build Coastguard Worker return ToBinderStatus(hwc3::Error::kNoResources);
44*0a9764feSAndroid Build Coastguard Worker }
45*0a9764feSAndroid Build Coastguard Worker
46*0a9764feSAndroid Build Coastguard Worker *out_client = client;
47*0a9764feSAndroid Build Coastguard Worker client_ = client;
48*0a9764feSAndroid Build Coastguard Worker
49*0a9764feSAndroid Build Coastguard Worker return ndk::ScopedAStatus::ok();
50*0a9764feSAndroid Build Coastguard Worker }
51*0a9764feSAndroid Build Coastguard Worker
dump(int fd,const char **,uint32_t)52*0a9764feSAndroid Build Coastguard Worker binder_status_t Composer::dump(int fd, const char** /*args*/,
53*0a9764feSAndroid Build Coastguard Worker uint32_t /*numArgs*/) {
54*0a9764feSAndroid Build Coastguard Worker std::stringstream output;
55*0a9764feSAndroid Build Coastguard Worker output << "hwc3-drm\n\n";
56*0a9764feSAndroid Build Coastguard Worker
57*0a9764feSAndroid Build Coastguard Worker auto client_instance = client_.lock();
58*0a9764feSAndroid Build Coastguard Worker if (!client_instance) {
59*0a9764feSAndroid Build Coastguard Worker return STATUS_OK;
60*0a9764feSAndroid Build Coastguard Worker }
61*0a9764feSAndroid Build Coastguard Worker
62*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
63*0a9764feSAndroid Build Coastguard Worker auto* client = static_cast<ComposerClient*>(client_instance.get());
64*0a9764feSAndroid Build Coastguard Worker output << client->Dump();
65*0a9764feSAndroid Build Coastguard Worker
66*0a9764feSAndroid Build Coastguard Worker auto output_str = output.str();
67*0a9764feSAndroid Build Coastguard Worker write(fd, output_str.c_str(), output_str.size());
68*0a9764feSAndroid Build Coastguard Worker return STATUS_OK;
69*0a9764feSAndroid Build Coastguard Worker }
70*0a9764feSAndroid Build Coastguard Worker
getCapabilities(std::vector<Capability> * caps)71*0a9764feSAndroid Build Coastguard Worker ndk::ScopedAStatus Composer::getCapabilities(std::vector<Capability>* caps) {
72*0a9764feSAndroid Build Coastguard Worker DEBUG_FUNC();
73*0a9764feSAndroid Build Coastguard Worker /* No capabilities advertised */
74*0a9764feSAndroid Build Coastguard Worker caps->clear();
75*0a9764feSAndroid Build Coastguard Worker
76*0a9764feSAndroid Build Coastguard Worker if (Properties::IsPresentFenceNotReliable()) {
77*0a9764feSAndroid Build Coastguard Worker caps->emplace_back(Capability::PRESENT_FENCE_IS_NOT_RELIABLE);
78*0a9764feSAndroid Build Coastguard Worker }
79*0a9764feSAndroid Build Coastguard Worker
80*0a9764feSAndroid Build Coastguard Worker return ndk::ScopedAStatus::ok();
81*0a9764feSAndroid Build Coastguard Worker }
82*0a9764feSAndroid Build Coastguard Worker
createBinder()83*0a9764feSAndroid Build Coastguard Worker ::ndk::SpAIBinder Composer::createBinder() {
84*0a9764feSAndroid Build Coastguard Worker auto binder = BnComposer::createBinder();
85*0a9764feSAndroid Build Coastguard Worker AIBinder_setInheritRt(binder.get(), true);
86*0a9764feSAndroid Build Coastguard Worker return binder;
87*0a9764feSAndroid Build Coastguard Worker }
88*0a9764feSAndroid Build Coastguard Worker
89*0a9764feSAndroid Build Coastguard Worker } // namespace aidl::android::hardware::graphics::composer3::impl
90