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