Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2024 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "drmhwc" |
| 19 | #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) |
| 20 | |
| 21 | #include "ComposerResources.h" |
| 22 | |
| 23 | #include <aidlcommonsupport/NativeHandle.h> |
| 24 | |
| 25 | #include "hardware/hwcomposer2.h" |
| 26 | #include "hwc3/Utils.h" |
| 27 | |
Roman Stratiienko | 7079334 | 2025-01-24 14:45:14 +0200 | [diff] [blame^] | 28 | namespace { |
| 29 | using Hwc2Display = ::android::hardware::graphics::composer::V2_1::Display; |
| 30 | using Hwc2Layer = ::android::hardware::graphics::composer::V2_1::Layer; |
| 31 | |
| 32 | auto ToHwc2Display(uint64_t display_id) -> Hwc2Display { |
| 33 | return static_cast<Hwc2Display>(display_id); |
| 34 | } |
| 35 | |
| 36 | auto ToHwc2Layer(int64_t layer_id) -> Hwc2Layer { |
| 37 | return static_cast<Hwc2Layer>(layer_id); |
| 38 | } |
| 39 | } // namespace |
| 40 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 41 | namespace aidl::android::hardware::graphics::composer3::impl { |
| 42 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 43 | std::unique_ptr<ComposerResourceReleaser> |
| 44 | ComposerResources::CreateResourceReleaser(bool is_buffer) { |
| 45 | return std::make_unique<ComposerResourceReleaser>(is_buffer); |
| 46 | } |
| 47 | |
| 48 | std::unique_ptr<ComposerResources> ComposerResources::Create() { |
| 49 | auto instance = std::unique_ptr<ComposerResources>(new ComposerResources); |
| 50 | if (instance->resources_ == nullptr) { |
| 51 | ALOGE("%s: Failed to initialise ComposerResources", __func__); |
| 52 | return nullptr; |
| 53 | } |
| 54 | |
| 55 | return instance; |
| 56 | } |
| 57 | |
| 58 | hwc3::Error ComposerResources::GetLayerBuffer( |
| 59 | uint64_t display_id, int64_t layer_id, const Buffer& buffer, |
| 60 | buffer_handle_t* out_buffer_handle, |
| 61 | ComposerResourceReleaser* buf_releaser) { |
| 62 | auto display = ToHwc2Display(display_id); |
| 63 | auto layer = ToHwc2Layer(layer_id); |
| 64 | |
| 65 | const bool use_cache = !buffer.handle.has_value(); |
| 66 | buffer_handle_t buffer_handle = nullptr; |
| 67 | if (buffer.handle.has_value()) { |
| 68 | buffer_handle = ::android::makeFromAidl(*buffer.handle); |
| 69 | } |
| 70 | |
| 71 | auto err = resources_->getLayerBuffer(display, layer, buffer.slot, use_cache, |
| 72 | buffer_handle, out_buffer_handle, |
| 73 | buf_releaser->GetReplacedHandle()); |
| 74 | |
| 75 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 76 | } |
| 77 | |
| 78 | hwc3::Error ComposerResources::GetLayerSidebandStream( |
| 79 | uint64_t display_id, int64_t layer_id, |
| 80 | const aidl::android::hardware::common::NativeHandle& handle, |
| 81 | buffer_handle_t* out_handle, ComposerResourceReleaser* releaser) { |
| 82 | auto display = ToHwc2Display(display_id); |
| 83 | auto layer = ToHwc2Layer(layer_id); |
| 84 | |
| 85 | auto err = resources_->getLayerSidebandStream(display, layer, |
| 86 | ::android::makeFromAidl(handle), |
| 87 | out_handle, |
| 88 | releaser->GetReplacedHandle()); |
| 89 | |
| 90 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 91 | } |
| 92 | |
| 93 | hwc3::Error ComposerResources::AddLayer(uint64_t display_id, int64_t layer_id, |
| 94 | uint32_t buffer_cache_size) { |
| 95 | auto display = ToHwc2Display(display_id); |
| 96 | auto layer = ToHwc2Layer(layer_id); |
| 97 | |
| 98 | auto err = resources_->addLayer(display, layer, buffer_cache_size); |
| 99 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 100 | } |
| 101 | |
| 102 | hwc3::Error ComposerResources::RemoveLayer(uint64_t display_id, |
| 103 | int64_t layer_id) { |
| 104 | auto display = ToHwc2Display(display_id); |
| 105 | auto layer = ToHwc2Layer(layer_id); |
| 106 | |
| 107 | auto err = resources_->removeLayer(display, layer); |
| 108 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 109 | } |
| 110 | |
| 111 | bool ComposerResources::HasDisplay(uint64_t display_id) { |
| 112 | auto display = ToHwc2Display(display_id); |
| 113 | return resources_->hasDisplay(display); |
| 114 | } |
| 115 | |
| 116 | hwc3::Error ComposerResources::AddPhysicalDisplay(uint64_t display_id) { |
| 117 | auto display = ToHwc2Display(display_id); |
| 118 | auto err = resources_->addPhysicalDisplay(display); |
| 119 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 120 | } |
| 121 | |
| 122 | hwc3::Error ComposerResources::AddVirtualDisplay( |
| 123 | uint64_t display, uint32_t output_buffer_cache_size) { |
| 124 | auto err = resources_->addVirtualDisplay(display, output_buffer_cache_size); |
| 125 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 126 | } |
| 127 | |
| 128 | hwc3::Error ComposerResources::RemoveDisplay(uint64_t display_id) { |
| 129 | auto display = ToHwc2Display(display_id); |
| 130 | auto err = resources_->removeDisplay(display); |
| 131 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 132 | } |
| 133 | |
| 134 | void ComposerResources::SetDisplayMustValidateState(uint64_t display_id, |
| 135 | bool must_validate) { |
| 136 | auto display = ToHwc2Display(display_id); |
| 137 | resources_->setDisplayMustValidateState(display, must_validate); |
| 138 | } |
| 139 | |
| 140 | bool ComposerResources::MustValidateDisplay(uint64_t display_id) { |
| 141 | auto display = ToHwc2Display(display_id); |
| 142 | return resources_->mustValidateDisplay(display); |
| 143 | } |
| 144 | |
| 145 | hwc3::Error ComposerResources::GetDisplayClientTarget( |
| 146 | uint64_t display_id, const Buffer& buffer, buffer_handle_t* out_handle, |
| 147 | ComposerResourceReleaser* releaser) { |
| 148 | auto display = ToHwc2Display(display_id); |
| 149 | |
| 150 | const bool use_cache = !buffer.handle.has_value(); |
| 151 | buffer_handle_t buffer_handle = nullptr; |
| 152 | if (buffer.handle.has_value()) { |
| 153 | buffer_handle = ::android::makeFromAidl(*buffer.handle); |
| 154 | } |
| 155 | |
| 156 | auto err = resources_->getDisplayClientTarget(display, buffer.slot, use_cache, |
| 157 | buffer_handle, out_handle, |
| 158 | releaser->GetReplacedHandle()); |
| 159 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 160 | } |
| 161 | |
| 162 | hwc3::Error ComposerResources::SetDisplayClientTargetCacheSize( |
| 163 | uint64_t display_id, uint32_t client_target_cache_size) { |
| 164 | auto display = ToHwc2Display(display_id); |
| 165 | auto err = resources_ |
| 166 | ->setDisplayClientTargetCacheSize(display, |
| 167 | client_target_cache_size); |
| 168 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 169 | } |
| 170 | |
| 171 | hwc3::Error ComposerResources::GetDisplayClientTargetCacheSize( |
| 172 | uint64_t display_id, size_t* out_cache_size) { |
| 173 | auto display = ToHwc2Display(display_id); |
| 174 | auto err = resources_->getDisplayClientTargetCacheSize(display, |
| 175 | out_cache_size); |
| 176 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 177 | } |
| 178 | |
| 179 | hwc3::Error ComposerResources::GetDisplayOutputBufferCacheSize( |
| 180 | uint64_t display_id, size_t* out_cache_size) { |
| 181 | auto display = ToHwc2Display(display_id); |
| 182 | auto err = resources_->getDisplayOutputBufferCacheSize(display, |
| 183 | out_cache_size); |
| 184 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 185 | } |
| 186 | |
| 187 | hwc3::Error ComposerResources::GetDisplayOutputBuffer( |
| 188 | uint64_t display_id, const Buffer& buffer, buffer_handle_t* out_handle, |
| 189 | ComposerResourceReleaser* releaser) { |
| 190 | auto display = ToHwc2Display(display_id); |
| 191 | const bool use_cache = !buffer.handle.has_value(); |
| 192 | |
| 193 | buffer_handle_t buffer_handle = nullptr; |
| 194 | if (buffer.handle.has_value()) { |
| 195 | buffer_handle = ::android::makeFromAidl(*buffer.handle); |
| 196 | } |
| 197 | |
| 198 | auto err = resources_->getDisplayOutputBuffer(display, buffer.slot, use_cache, |
| 199 | buffer_handle, out_handle, |
| 200 | releaser->GetReplacedHandle()); |
| 201 | return Hwc2toHwc3Error(static_cast<HWC2::Error>(err)); |
| 202 | } |
| 203 | } // namespace aidl::android::hardware::graphics::composer3::impl |