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 | |
| 17 | #pragma once |
| 18 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 21 | #include "aidl/android/hardware/graphics/composer3/BnComposerClient.h" |
| 22 | #include "aidl/android/hardware/graphics/composer3/LayerCommand.h" |
Drew Davenport | 14022a3 | 2025-01-15 20:12:51 -0700 | [diff] [blame] | 23 | #include "hwc2_device/HwcLayer.h" |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 24 | #include "hwc3/CommandResultWriter.h" |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 25 | #include "hwc3/Utils.h" |
| 26 | #include "utils/Mutex.h" |
| 27 | |
Huihong Luo | 012271d | 2024-10-30 13:19:10 -0700 | [diff] [blame] | 28 | using AidlHdcpLevels = aidl::android::hardware::drm::HdcpLevels; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 29 | using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat; |
| 30 | using AidlNativeHandle = aidl::android::hardware::common::NativeHandle; |
| 31 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 32 | namespace android { |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 33 | class HwcDisplay; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 34 | } // namespace android |
| 35 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 36 | namespace aidl::android::hardware::graphics::composer3::impl { |
| 37 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 38 | class DrmHwcThree; |
| 39 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 40 | class ComposerClient : public BnComposerClient { |
| 41 | public: |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 42 | ComposerClient(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 43 | ~ComposerClient() override; |
| 44 | |
Roman Stratiienko | e501a97 | 2025-01-26 14:10:31 +0200 | [diff] [blame] | 45 | void Init(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 46 | std::string Dump(); |
| 47 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 48 | // composer3 interface |
| 49 | ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count, |
| 50 | int64_t* layer) override; |
| 51 | ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height, |
| 52 | AidlPixelFormat format_hint, |
| 53 | int32_t output_buffer_slot_count, |
| 54 | VirtualDisplay* display) override; |
| 55 | ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override; |
| 56 | ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override; |
| 57 | ndk::ScopedAStatus executeCommands( |
| 58 | const std::vector<DisplayCommand>& commands, |
| 59 | std::vector<CommandResultPayload>* results) override; |
| 60 | ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override; |
| 61 | ndk::ScopedAStatus getColorModes( |
| 62 | int64_t display, std::vector<ColorMode>* color_modes) override; |
| 63 | ndk::ScopedAStatus getDataspaceSaturationMatrix( |
| 64 | common::Dataspace dataspace, std::vector<float>* matrix) override; |
| 65 | ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config, |
| 66 | DisplayAttribute attribute, |
| 67 | int32_t* value) override; |
| 68 | ndk::ScopedAStatus getDisplayCapabilities( |
| 69 | int64_t display, std::vector<DisplayCapability>* caps) override; |
| 70 | ndk::ScopedAStatus getDisplayConfigs(int64_t display, |
| 71 | std::vector<int32_t>* configs) override; |
| 72 | ndk::ScopedAStatus getDisplayConnectionType( |
| 73 | int64_t display, DisplayConnectionType* type) override; |
| 74 | ndk::ScopedAStatus getDisplayIdentificationData( |
| 75 | int64_t display, DisplayIdentification* id) override; |
| 76 | ndk::ScopedAStatus getDisplayName(int64_t display, |
| 77 | std::string* name) override; |
| 78 | ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display, |
| 79 | int32_t* vsync_period) override; |
| 80 | ndk::ScopedAStatus getDisplayedContentSample( |
| 81 | int64_t display, int64_t max_frames, int64_t timestamp, |
| 82 | DisplayContentSample* samples) override; |
| 83 | ndk::ScopedAStatus getDisplayedContentSamplingAttributes( |
| 84 | int64_t display, DisplayContentSamplingAttributes* attrs) override; |
| 85 | ndk::ScopedAStatus getDisplayPhysicalOrientation( |
| 86 | int64_t display, common::Transform* orientation) override; |
| 87 | ndk::ScopedAStatus getHdrCapabilities(int64_t display, |
| 88 | HdrCapabilities* caps) override; |
| 89 | ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override; |
| 90 | ndk::ScopedAStatus getPerFrameMetadataKeys( |
| 91 | int64_t display, std::vector<PerFrameMetadataKey>* keys) override; |
| 92 | ndk::ScopedAStatus getReadbackBufferAttributes( |
| 93 | int64_t display, ReadbackBufferAttributes* attrs) override; |
| 94 | ndk::ScopedAStatus getReadbackBufferFence( |
| 95 | int64_t display, ndk::ScopedFileDescriptor* acquire_fence) override; |
| 96 | ndk::ScopedAStatus getRenderIntents( |
| 97 | int64_t display, ColorMode mode, |
| 98 | std::vector<RenderIntent>* intents) override; |
| 99 | ndk::ScopedAStatus getSupportedContentTypes( |
| 100 | int64_t display, std::vector<ContentType>* types) override; |
| 101 | ndk::ScopedAStatus getDisplayDecorationSupport( |
| 102 | int64_t display, |
| 103 | std::optional<common::DisplayDecorationSupport>* support) override; |
| 104 | ndk::ScopedAStatus registerCallback( |
| 105 | const std::shared_ptr<IComposerCallback>& callback) override; |
| 106 | ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override; |
| 107 | ndk::ScopedAStatus setActiveConfigWithConstraints( |
| 108 | int64_t display, int32_t config, |
| 109 | const VsyncPeriodChangeConstraints& constraints, |
| 110 | VsyncPeriodChangeTimeline* timeline) override; |
| 111 | ndk::ScopedAStatus setBootDisplayConfig(int64_t display, |
| 112 | int32_t config) override; |
| 113 | ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override; |
| 114 | ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display, |
| 115 | int32_t* config) override; |
| 116 | ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override; |
| 117 | ndk::ScopedAStatus setClientTargetSlotCount(int64_t display, |
| 118 | int32_t count) override; |
| 119 | ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode, |
| 120 | RenderIntent intent) override; |
| 121 | ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override; |
| 122 | ndk::ScopedAStatus setDisplayedContentSamplingEnabled( |
| 123 | int64_t display, bool enable, FormatColorComponent component_mask, |
| 124 | int64_t max_frames) override; |
| 125 | ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override; |
| 126 | ndk::ScopedAStatus setReadbackBuffer( |
| 127 | int64_t display, const AidlNativeHandle& buffer, |
| 128 | const ndk::ScopedFileDescriptor& release_fence) override; |
| 129 | ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override; |
| 130 | ndk::ScopedAStatus setIdleTimerEnabled(int64_t display, |
| 131 | int32_t timeout) override; |
Roman Stratiienko | 445ef20 | 2024-11-27 00:24:48 +0200 | [diff] [blame] | 132 | |
| 133 | #if __ANDROID_API__ >= 34 |
| 134 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 135 | ndk::ScopedAStatus getOverlaySupport( |
| 136 | OverlayProperties* out_overlay_properties) override; |
| 137 | ndk::ScopedAStatus getHdrConversionCapabilities( |
| 138 | std::vector<common::HdrConversionCapability>* out_capabilities) override; |
| 139 | ndk::ScopedAStatus setHdrConversionStrategy( |
| 140 | const common::HdrConversionStrategy& conversion_strategy, |
| 141 | common::Hdr* out_hdr) override; |
| 142 | ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled( |
| 143 | int64_t display, bool enabled) override; |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 144 | |
Roman Stratiienko | 445ef20 | 2024-11-27 00:24:48 +0200 | [diff] [blame] | 145 | #endif |
| 146 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 147 | #if __ANDROID_API__ >= 35 |
| 148 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 149 | ndk::ScopedAStatus getDisplayConfigurations( |
| 150 | int64_t display, int32_t max_frame_interval_ns, |
| 151 | std::vector<DisplayConfiguration>* configurations) override; |
| 152 | ndk::ScopedAStatus notifyExpectedPresent( |
| 153 | int64_t display, const ClockMonotonicTimestamp& expected_present_time, |
| 154 | int32_t frame_interval_ns) override; |
Huihong Luo | 012271d | 2024-10-30 13:19:10 -0700 | [diff] [blame] | 155 | ndk::ScopedAStatus startHdcpNegotiation(int64_t display, |
| 156 | const AidlHdcpLevels& levels) override; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 157 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 158 | #endif |
| 159 | |
Brian Lindahl | e1d49f1 | 2024-10-31 08:56:11 -0600 | [diff] [blame] | 160 | ndk::ScopedAStatus getMaxLayerPictureProfiles( |
| 161 | int64_t display, int32_t* maxProfiles) override; |
Sally Qi | e39af97 | 2024-11-21 23:37:58 -0800 | [diff] [blame] | 162 | ndk::ScopedAStatus getLuts(int64_t, const std::vector<Buffer>&, |
| 163 | std::vector<Luts>* out_luts) override; |
Brian Lindahl | e1d49f1 | 2024-10-31 08:56:11 -0600 | [diff] [blame] | 164 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 165 | protected: |
| 166 | ::ndk::SpAIBinder createBinder() override; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 167 | |
| 168 | private: |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 169 | hwc3::Error ImportLayerBuffer(int64_t display_id, int64_t layer_id, |
| 170 | const Buffer& buffer, |
Drew Davenport | 14022a3 | 2025-01-15 20:12:51 -0700 | [diff] [blame] | 171 | ::android::HwcLayer::Buffer* out_buffer); |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 172 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 173 | // Layer commands |
| 174 | void DispatchLayerCommand(int64_t display_id, const LayerCommand& command); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 175 | |
| 176 | // Display commands |
| 177 | void ExecuteDisplayCommand(const DisplayCommand& command); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 178 | void ExecuteSetDisplayClientTarget(uint64_t display_id, |
| 179 | const ClientTarget& command); |
| 180 | void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 181 | |
| 182 | ::android::HwcDisplay* GetDisplay(uint64_t display_id); |
| 183 | |
| 184 | std::unique_ptr<CommandResultWriter> cmd_result_writer_; |
| 185 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 186 | std::unique_ptr<DrmHwcThree> hwc_; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | } // namespace aidl::android::hardware::graphics::composer3::impl |