blob: de875dbe276a7fde3854adb89d19c5a74346e075 [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"
Tim Van Patten16933c32024-11-08 16:41:39 -070028#include "utils/properties.h"
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000029
30namespace aidl::android::hardware::graphics::composer3::impl {
31
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000032ndk::ScopedAStatus Composer::createClient(
33 std::shared_ptr<IComposerClient>* out_client) {
34 DEBUG_FUNC();
35
Dennis Tsiang1a966202024-01-24 12:46:33 +000036 if (!client_.expired()) {
37 return ToBinderStatus(hwc3::Error::kNoResources);
38 }
39
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000040 auto client = ndk::SharedRefBase::make<ComposerClient>();
Roman Stratiienkoe501a972025-01-26 14:10:31 +020041 if (!client) {
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000042 *out_client = nullptr;
Drew Davenport5951b112024-08-05 09:44:27 -060043 return ToBinderStatus(hwc3::Error::kNoResources);
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000044 }
45
Roman Stratiienkoe501a972025-01-26 14:10:31 +020046 client->Init();
47
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000048 *out_client = client;
Drew Davenport5951b112024-08-05 09:44:27 -060049 client_ = client;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000050
51 return ndk::ScopedAStatus::ok();
52}
53
54binder_status_t Composer::dump(int fd, const char** /*args*/,
55 uint32_t /*numArgs*/) {
Drew Davenport5951b112024-08-05 09:44:27 -060056 std::stringstream output;
57 output << "hwc3-drm\n\n";
58
59 auto client_instance = client_.lock();
60 if (!client_instance) {
61 return STATUS_OK;
62 }
63
64 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
65 auto* client = static_cast<ComposerClient*>(client_instance.get());
66 output << client->Dump();
67
68 auto output_str = output.str();
69 write(fd, output_str.c_str(), output_str.size());
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000070 return STATUS_OK;
71}
72
Drew Davenport5951b112024-08-05 09:44:27 -060073ndk::ScopedAStatus Composer::getCapabilities(std::vector<Capability>* caps) {
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000074 DEBUG_FUNC();
Drew Davenport5951b112024-08-05 09:44:27 -060075 /* No capabilities advertised */
76 caps->clear();
Tim Van Patten16933c32024-11-08 16:41:39 -070077
78 if (Properties::IsPresentFenceNotReliable()) {
79 caps->emplace_back(Capability::PRESENT_FENCE_IS_NOT_RELIABLE);
80 }
81
Roman Stratiienko6a765202025-02-14 07:07:17 +020082#if __ANDROID_API__ >= 35
83 caps->emplace_back(Capability::LAYER_LIFECYCLE_BATCH_COMMAND);
84#endif
85
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000086 return ndk::ScopedAStatus::ok();
87}
88
89::ndk::SpAIBinder Composer::createBinder() {
90 auto binder = BnComposer::createBinder();
91 AIBinder_setInheritRt(binder.get(), true);
92 return binder;
93}
94
95} // namespace aidl::android::hardware::graphics::composer3::impl