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" |
| 23 | #include "hwc3/CommandResultWriter.h" |
| 24 | #include "hwc3/ComposerResources.h" |
| 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 { |
| 33 | |
| 34 | class HwcDisplay; |
| 35 | class HwcLayer; |
| 36 | |
| 37 | } // namespace android |
| 38 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 39 | namespace aidl::android::hardware::graphics::composer3::impl { |
| 40 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 41 | class DrmHwcThree; |
| 42 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 43 | class ComposerClient : public BnComposerClient { |
| 44 | public: |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 45 | ComposerClient(); |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 46 | ~ComposerClient() override; |
| 47 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 48 | bool Init(); |
| 49 | std::string Dump(); |
| 50 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 51 | // composer3 interface |
| 52 | ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count, |
| 53 | int64_t* layer) override; |
| 54 | ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height, |
| 55 | AidlPixelFormat format_hint, |
| 56 | int32_t output_buffer_slot_count, |
| 57 | VirtualDisplay* display) override; |
| 58 | ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override; |
| 59 | ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override; |
| 60 | ndk::ScopedAStatus executeCommands( |
| 61 | const std::vector<DisplayCommand>& commands, |
| 62 | std::vector<CommandResultPayload>* results) override; |
| 63 | ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override; |
| 64 | ndk::ScopedAStatus getColorModes( |
| 65 | int64_t display, std::vector<ColorMode>* color_modes) override; |
| 66 | ndk::ScopedAStatus getDataspaceSaturationMatrix( |
| 67 | common::Dataspace dataspace, std::vector<float>* matrix) override; |
| 68 | ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config, |
| 69 | DisplayAttribute attribute, |
| 70 | int32_t* value) override; |
| 71 | ndk::ScopedAStatus getDisplayCapabilities( |
| 72 | int64_t display, std::vector<DisplayCapability>* caps) override; |
| 73 | ndk::ScopedAStatus getDisplayConfigs(int64_t display, |
| 74 | std::vector<int32_t>* configs) override; |
| 75 | ndk::ScopedAStatus getDisplayConnectionType( |
| 76 | int64_t display, DisplayConnectionType* type) override; |
| 77 | ndk::ScopedAStatus getDisplayIdentificationData( |
| 78 | int64_t display, DisplayIdentification* id) override; |
| 79 | ndk::ScopedAStatus getDisplayName(int64_t display, |
| 80 | std::string* name) override; |
| 81 | ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display, |
| 82 | int32_t* vsync_period) override; |
| 83 | ndk::ScopedAStatus getDisplayedContentSample( |
| 84 | int64_t display, int64_t max_frames, int64_t timestamp, |
| 85 | DisplayContentSample* samples) override; |
| 86 | ndk::ScopedAStatus getDisplayedContentSamplingAttributes( |
| 87 | int64_t display, DisplayContentSamplingAttributes* attrs) override; |
| 88 | ndk::ScopedAStatus getDisplayPhysicalOrientation( |
| 89 | int64_t display, common::Transform* orientation) override; |
| 90 | ndk::ScopedAStatus getHdrCapabilities(int64_t display, |
| 91 | HdrCapabilities* caps) override; |
| 92 | ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override; |
| 93 | ndk::ScopedAStatus getPerFrameMetadataKeys( |
| 94 | int64_t display, std::vector<PerFrameMetadataKey>* keys) override; |
| 95 | ndk::ScopedAStatus getReadbackBufferAttributes( |
| 96 | int64_t display, ReadbackBufferAttributes* attrs) override; |
| 97 | ndk::ScopedAStatus getReadbackBufferFence( |
| 98 | int64_t display, ndk::ScopedFileDescriptor* acquire_fence) override; |
| 99 | ndk::ScopedAStatus getRenderIntents( |
| 100 | int64_t display, ColorMode mode, |
| 101 | std::vector<RenderIntent>* intents) override; |
| 102 | ndk::ScopedAStatus getSupportedContentTypes( |
| 103 | int64_t display, std::vector<ContentType>* types) override; |
| 104 | ndk::ScopedAStatus getDisplayDecorationSupport( |
| 105 | int64_t display, |
| 106 | std::optional<common::DisplayDecorationSupport>* support) override; |
| 107 | ndk::ScopedAStatus registerCallback( |
| 108 | const std::shared_ptr<IComposerCallback>& callback) override; |
| 109 | ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override; |
| 110 | ndk::ScopedAStatus setActiveConfigWithConstraints( |
| 111 | int64_t display, int32_t config, |
| 112 | const VsyncPeriodChangeConstraints& constraints, |
| 113 | VsyncPeriodChangeTimeline* timeline) override; |
| 114 | ndk::ScopedAStatus setBootDisplayConfig(int64_t display, |
| 115 | int32_t config) override; |
| 116 | ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override; |
| 117 | ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display, |
| 118 | int32_t* config) override; |
| 119 | ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override; |
| 120 | ndk::ScopedAStatus setClientTargetSlotCount(int64_t display, |
| 121 | int32_t count) override; |
| 122 | ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode, |
| 123 | RenderIntent intent) override; |
| 124 | ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override; |
| 125 | ndk::ScopedAStatus setDisplayedContentSamplingEnabled( |
| 126 | int64_t display, bool enable, FormatColorComponent component_mask, |
| 127 | int64_t max_frames) override; |
| 128 | ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override; |
| 129 | ndk::ScopedAStatus setReadbackBuffer( |
| 130 | int64_t display, const AidlNativeHandle& buffer, |
| 131 | const ndk::ScopedFileDescriptor& release_fence) override; |
| 132 | ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override; |
| 133 | ndk::ScopedAStatus setIdleTimerEnabled(int64_t display, |
| 134 | int32_t timeout) override; |
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 | |
| 145 | #if __ANDROID_API__ >= 35 |
| 146 | |
Drew Davenport | 7f1761b | 2024-08-20 10:09:43 -0600 | [diff] [blame] | 147 | ndk::ScopedAStatus getDisplayConfigurations( |
| 148 | int64_t display, int32_t max_frame_interval_ns, |
| 149 | std::vector<DisplayConfiguration>* configurations) override; |
| 150 | ndk::ScopedAStatus notifyExpectedPresent( |
| 151 | int64_t display, const ClockMonotonicTimestamp& expected_present_time, |
| 152 | int32_t frame_interval_ns) override; |
Huihong Luo | 012271d | 2024-10-30 13:19:10 -0700 | [diff] [blame] | 153 | ndk::ScopedAStatus startHdcpNegotiation(int64_t display, |
| 154 | const AidlHdcpLevels& levels) override; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 155 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 156 | #endif |
| 157 | |
Brian Lindahl | e1d49f1 | 2024-10-31 08:56:11 -0600 | [diff] [blame] | 158 | ndk::ScopedAStatus getMaxLayerPictureProfiles( |
| 159 | int64_t display, int32_t* maxProfiles) override; |
Sally Qi | e39af97 | 2024-11-21 23:37:58 -0800 | [diff] [blame] | 160 | ndk::ScopedAStatus getLuts(int64_t, const std::vector<Buffer>&, |
| 161 | std::vector<Luts>* out_luts) override; |
Brian Lindahl | e1d49f1 | 2024-10-31 08:56:11 -0600 | [diff] [blame] | 162 | |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 163 | protected: |
| 164 | ::ndk::SpAIBinder createBinder() override; |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 165 | |
| 166 | private: |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 167 | hwc3::Error ImportLayerBuffer(int64_t display_id, int64_t layer_id, |
| 168 | const Buffer& buffer, |
| 169 | buffer_handle_t* out_imported_buffer); |
| 170 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 171 | // Layer commands |
| 172 | void DispatchLayerCommand(int64_t display_id, const LayerCommand& command); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 173 | |
| 174 | // Display commands |
| 175 | void ExecuteDisplayCommand(const DisplayCommand& command); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 176 | void ExecuteSetDisplayColorTransform(uint64_t display_id, |
| 177 | const std::vector<float>& matrix); |
| 178 | void ExecuteSetDisplayClientTarget(uint64_t display_id, |
| 179 | const ClientTarget& command); |
| 180 | void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer); |
| 181 | void ExecuteValidateDisplay( |
| 182 | int64_t display_id, |
| 183 | std::optional<ClockMonotonicTimestamp> expected_present_time); |
| 184 | void ExecuteAcceptDisplayChanges(int64_t display_id); |
| 185 | void ExecutePresentDisplay(int64_t display_id); |
| 186 | void ExecutePresentOrValidateDisplay( |
| 187 | int64_t display_id, |
| 188 | std::optional<ClockMonotonicTimestamp> expected_present_time); |
| 189 | |
| 190 | static hwc3::Error ValidateDisplayInternal( |
| 191 | ::android::HwcDisplay& display, std::vector<int64_t>* out_changed_layers, |
| 192 | std::vector<Composition>* out_composition_types, |
| 193 | int32_t* out_display_request_mask, |
| 194 | std::vector<int64_t>* out_requested_layers, |
| 195 | std::vector<int32_t>* out_request_masks, |
| 196 | ClientTargetProperty* out_client_target_property, |
| 197 | DimmingStage* out_dimming_stage); |
| 198 | |
| 199 | hwc3::Error PresentDisplayInternal( |
| 200 | uint64_t display_id, ::android::base::unique_fd& out_display_fence, |
| 201 | std::unordered_map<int64_t, ::android::base::unique_fd>& |
| 202 | out_release_fences); |
| 203 | |
| 204 | ::android::HwcDisplay* GetDisplay(uint64_t display_id); |
| 205 | |
| 206 | std::unique_ptr<CommandResultWriter> cmd_result_writer_; |
| 207 | |
| 208 | // Manages importing and caching gralloc buffers for displays and layers. |
| 209 | std::unique_ptr<ComposerResources> composer_resources_; |
| 210 | |
| 211 | std::unique_ptr<DrmHwcThree> hwc_; |
Dennis Tsiang | 33f0ece | 2023-11-29 12:45:04 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | } // namespace aidl::android::hardware::graphics::composer3::impl |