Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 1 | /* |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 2 | * Copyright (C) 2024 The Android Open Source Project |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 3 | * |
| 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 Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 18 | #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 Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 25 | #include "hwc3/ComposerClient.h" |
| 26 | #include "hwc3/Utils.h" |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 27 | #include "utils/log.h" |
Tim Van Patten | 16933c3 | 2024-11-08 16:41:39 -0700 | [diff] [blame] | 28 | #include "utils/properties.h" |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 29 | |
| 30 | namespace aidl::android::hardware::graphics::composer3::impl { |
| 31 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 32 | ndk::ScopedAStatus Composer::createClient( |
| 33 | std::shared_ptr<IComposerClient>* out_client) { |
| 34 | DEBUG_FUNC(); |
| 35 | |
Dennis Tsiang | 1a96620 | 2024-01-24 12:46:33 +0000 | [diff] [blame] | 36 | if (!client_.expired()) { |
| 37 | return ToBinderStatus(hwc3::Error::kNoResources); |
| 38 | } |
| 39 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 40 | auto client = ndk::SharedRefBase::make<ComposerClient>(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 41 | if (!client || !client->Init()) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 42 | *out_client = nullptr; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 43 | return ToBinderStatus(hwc3::Error::kNoResources); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | *out_client = client; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 47 | client_ = client; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 48 | |
| 49 | return ndk::ScopedAStatus::ok(); |
| 50 | } |
| 51 | |
| 52 | binder_status_t Composer::dump(int fd, const char** /*args*/, |
| 53 | uint32_t /*numArgs*/) { |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 54 | std::stringstream output; |
| 55 | output << "hwc3-drm\n\n"; |
| 56 | |
| 57 | auto client_instance = client_.lock(); |
| 58 | if (!client_instance) { |
| 59 | return STATUS_OK; |
| 60 | } |
| 61 | |
| 62 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) |
| 63 | auto* client = static_cast<ComposerClient*>(client_instance.get()); |
| 64 | output << client->Dump(); |
| 65 | |
| 66 | auto output_str = output.str(); |
| 67 | write(fd, output_str.c_str(), output_str.size()); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 68 | return STATUS_OK; |
| 69 | } |
| 70 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 71 | ndk::ScopedAStatus Composer::getCapabilities(std::vector<Capability>* caps) { |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 72 | DEBUG_FUNC(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 73 | /* No capabilities advertised */ |
| 74 | caps->clear(); |
Tim Van Patten | 16933c3 | 2024-11-08 16:41:39 -0700 | [diff] [blame] | 75 | |
| 76 | if (Properties::IsPresentFenceNotReliable()) { |
| 77 | caps->emplace_back(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
| 78 | } |
| 79 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 80 | return ndk::ScopedAStatus::ok(); |
| 81 | } |
| 82 | |
| 83 | ::ndk::SpAIBinder Composer::createBinder() { |
| 84 | auto binder = BnComposer::createBinder(); |
| 85 | AIBinder_setInheritRt(binder.get(), true); |
| 86 | return binder; |
| 87 | } |
| 88 | |
| 89 | } // namespace aidl::android::hardware::graphics::composer3::impl |