blob: 4977a14d4ae6590d16bed197066ec3fc1fcae6dd [file] [log] [blame]
Dennis Tsiang33f0ece2023-11-29 12:45:04 +00001/*
Drew Davenport5951b112024-08-05 09:44:27 -06002 * Copyright (C) 2024 The Android Open Source Project
Dennis Tsiang33f0ece2023-11-29 12:45:04 +00003 *
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
Drew Davenport5951b112024-08-05 09:44:27 -060017#define LOG_TAG "drmhwc"
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000018#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
19
20#include "Composer.h"
21
22#include <android-base/logging.h>
23#include <android/binder_ibinder_platform.h>
24
Drew Davenport5951b112024-08-05 09:44:27 -060025#include "hwc3/ComposerClient.h"
26#include "hwc3/Utils.h"
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000027#include "utils/log.h"
28
29namespace aidl::android::hardware::graphics::composer3::impl {
30
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000031ndk::ScopedAStatus Composer::createClient(
32 std::shared_ptr<IComposerClient>* out_client) {
33 DEBUG_FUNC();
34
Dennis Tsiang1a966202024-01-24 12:46:33 +000035 if (!client_.expired()) {
36 return ToBinderStatus(hwc3::Error::kNoResources);
37 }
38
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000039 auto client = ndk::SharedRefBase::make<ComposerClient>();
Drew Davenport5951b112024-08-05 09:44:27 -060040 if (!client || !client->Init()) {
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000041 *out_client = nullptr;
Drew Davenport5951b112024-08-05 09:44:27 -060042 return ToBinderStatus(hwc3::Error::kNoResources);
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000043 }
44
45 *out_client = client;
Drew Davenport5951b112024-08-05 09:44:27 -060046 client_ = client;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000047
48 return ndk::ScopedAStatus::ok();
49}
50
51binder_status_t Composer::dump(int fd, const char** /*args*/,
52 uint32_t /*numArgs*/) {
Drew Davenport5951b112024-08-05 09:44:27 -060053 std::stringstream output;
54 output << "hwc3-drm\n\n";
55
56 auto client_instance = client_.lock();
57 if (!client_instance) {
58 return STATUS_OK;
59 }
60
61 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
62 auto* client = static_cast<ComposerClient*>(client_instance.get());
63 output << client->Dump();
64
65 auto output_str = output.str();
66 write(fd, output_str.c_str(), output_str.size());
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000067 return STATUS_OK;
68}
69
Drew Davenport5951b112024-08-05 09:44:27 -060070ndk::ScopedAStatus Composer::getCapabilities(std::vector<Capability>* caps) {
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000071 DEBUG_FUNC();
Drew Davenport5951b112024-08-05 09:44:27 -060072 /* No capabilities advertised */
73 caps->clear();
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000074 return ndk::ScopedAStatus::ok();
75}
76
77::ndk::SpAIBinder Composer::createBinder() {
78 auto binder = BnComposer::createBinder();
79 AIBinder_setInheritRt(binder.get(), true);
80 return binder;
81}
82
83} // namespace aidl::android::hardware::graphics::composer3::impl