1 /* 2 * Copyright (C) 2024 The Android Open Source Project 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 19 #include <memory> 20 21 #include "aidl/android/hardware/graphics/composer3/BnComposerClient.h" 22 #include "aidl/android/hardware/graphics/composer3/LayerCommand.h" 23 #include "hwc2_device/HwcLayer.h" 24 #include "hwc3/CommandResultWriter.h" 25 #include "hwc3/Utils.h" 26 #include "utils/Mutex.h" 27 28 using AidlHdcpLevels = aidl::android::hardware::drm::HdcpLevels; 29 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat; 30 using AidlNativeHandle = aidl::android::hardware::common::NativeHandle; 31 32 namespace android { 33 class HwcDisplay; 34 } // namespace android 35 36 namespace aidl::android::hardware::graphics::composer3::impl { 37 38 class DrmHwcThree; 39 40 class ComposerClient : public BnComposerClient { 41 public: 42 ComposerClient(); 43 ~ComposerClient() override; 44 45 void Init(); 46 std::string Dump(); 47 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; 132 133 #if __ANDROID_API__ >= 34 134 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; 144 145 #endif 146 147 #if __ANDROID_API__ >= 35 148 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; 155 ndk::ScopedAStatus startHdcpNegotiation(int64_t display, 156 const AidlHdcpLevels& levels) override; 157 158 #endif 159 160 ndk::ScopedAStatus getMaxLayerPictureProfiles( 161 int64_t display, int32_t* maxProfiles) override; 162 ndk::ScopedAStatus getLuts(int64_t, const std::vector<Buffer>&, 163 std::vector<Luts>* out_luts) override; 164 165 protected: 166 ::ndk::SpAIBinder createBinder() override; 167 168 private: 169 hwc3::Error ImportLayerBuffer(int64_t display_id, int64_t layer_id, 170 const Buffer& buffer, 171 ::android::HwcLayer::Buffer* out_buffer); 172 173 // Layer commands 174 void DispatchLayerCommand(int64_t display_id, const LayerCommand& command); 175 176 // Display commands 177 void ExecuteDisplayCommand(const DisplayCommand& command); 178 void ExecuteSetDisplayClientTarget(uint64_t display_id, 179 const ClientTarget& command); 180 void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer); 181 182 ::android::HwcDisplay* GetDisplay(uint64_t display_id); 183 184 std::unique_ptr<CommandResultWriter> cmd_result_writer_; 185 186 std::unique_ptr<DrmHwcThree> hwc_; 187 }; 188 189 } // namespace aidl::android::hardware::graphics::composer3::impl 190