1 /* 2 * Copyright 2021, 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 <map> 20 #include <memory> 21 #include <unordered_set> 22 23 #include <hardware/hwcomposer2.h> 24 25 #include "include/IComposerHal.h" 26 27 class ExynosDevice; 28 class ExynosDisplay; 29 class ExynosLayer; 30 31 struct exynos_hwc2_device_t; 32 typedef struct exynos_hwc2_device_t ExynosHWCCtx; 33 34 namespace aidl::android::hardware::graphics::composer3::impl { 35 36 // Forward aidl call to Exynos HWC 37 class HalImpl : public IComposerHal { 38 public: 39 HalImpl(std::unique_ptr<ExynosDevice> device, bool batchingSupported); 40 virtual ~HalImpl() = default; 41 42 void getCapabilities(std::vector<Capability>* caps) override; 43 void dumpDebugInfo(std::string* output) override; 44 bool hasCapability(Capability cap) override; 45 46 void registerEventCallback(EventCallback* callback) override; 47 void unregisterEventCallback() override; 48 49 int32_t acceptDisplayChanges(int64_t display) override; 50 int32_t createLayer(int64_t display, int64_t* outLayer) override; 51 int32_t batchedCreateDestroyLayer(int64_t display, int64_t layer, 52 LayerLifecycleBatchCommandType cmd) override; 53 int32_t createVirtualDisplay(uint32_t width, uint32_t height, AidlPixelFormat format, 54 VirtualDisplay* outDisplay) override; 55 int32_t destroyLayer(int64_t display, int64_t layer) override; 56 int32_t destroyVirtualDisplay(int64_t display) override; 57 int32_t flushDisplayBrightnessChange(int64_t display) override; 58 int32_t getActiveConfig(int64_t display, int32_t* outConfig) override; 59 int32_t getColorModes(int64_t display, std::vector<ColorMode>* outModes) override; 60 61 int32_t getDataspaceSaturationMatrix(common::Dataspace dataspace, 62 std::vector<float>* matrix) override; 63 int32_t getDisplayAttribute(int64_t display, int32_t config, DisplayAttribute attribute, 64 int32_t* outValue) override; 65 int32_t getDisplayBrightnessSupport(int64_t display, bool& outSupport) override; 66 int32_t getDisplayCapabilities(int64_t display, 67 std::vector<DisplayCapability>* caps) override; 68 int32_t getDisplayConfigs(int64_t display, std::vector<int32_t>* configs) override; 69 int32_t getDisplayConfigurations(int64_t display, int32_t maxFrameIntervalNs, 70 std::vector<DisplayConfiguration>* outConfigs) override; 71 int32_t notifyExpectedPresent(int64_t display, 72 const ClockMonotonicTimestamp& expectedPresentTime, 73 int32_t frameIntervalNs) override; 74 int32_t getDisplayConnectionType(int64_t display, DisplayConnectionType* outType) override; 75 int32_t getDisplayIdentificationData(int64_t display, DisplayIdentification* id) override; 76 int32_t getDisplayName(int64_t display, std::string* outName) override; 77 int32_t getDisplayVsyncPeriod(int64_t display, int32_t* outVsyncPeriod) override; 78 int32_t getDisplayedContentSample(int64_t display, int64_t maxFrames, int64_t timestamp, 79 DisplayContentSample* samples) override; 80 int32_t getDisplayedContentSamplingAttributes( 81 int64_t display, DisplayContentSamplingAttributes* attrs) override; 82 int32_t getDisplayPhysicalOrientation(int64_t display, 83 common::Transform* orientation) override; 84 int32_t getDozeSupport(int64_t display, bool& outSupport) override; 85 int32_t getHdrCapabilities(int64_t display, HdrCapabilities* caps) override; 86 int32_t getOverlaySupport(OverlayProperties* caps) override; 87 int32_t getMaxVirtualDisplayCount(int32_t* count) override; 88 int32_t getPerFrameMetadataKeys(int64_t display, 89 std::vector<PerFrameMetadataKey>* keys) override; 90 91 int32_t getReadbackBufferAttributes(int64_t display, 92 ReadbackBufferAttributes* attrs) override; 93 int32_t getReadbackBufferFence(int64_t display, 94 ndk::ScopedFileDescriptor* acquireFence) override; 95 int32_t getRenderIntents(int64_t display, ColorMode mode, 96 std::vector<RenderIntent>* intents) override; 97 int32_t getSupportedContentTypes(int64_t display, std::vector<ContentType>* types) override; 98 int32_t presentDisplay(int64_t display, ndk::ScopedFileDescriptor& fence, 99 std::vector<int64_t>* outLayers, 100 std::vector<ndk::ScopedFileDescriptor>* outReleaseFences) override; 101 int32_t setActiveConfig(int64_t display, int32_t config) override; 102 int32_t setActiveConfigWithConstraints( 103 int64_t display, int32_t config, 104 const VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, 105 VsyncPeriodChangeTimeline* timeline) override; 106 int32_t setBootDisplayConfig(int64_t display, int32_t config) override; 107 int32_t clearBootDisplayConfig(int64_t display) override; 108 int32_t getPreferredBootDisplayConfig(int64_t display, int32_t* config) override; 109 int32_t getHdrConversionCapabilities(std::vector<common::HdrConversionCapability>*) override; 110 int32_t setHdrConversionStrategy(const common::HdrConversionStrategy&, common::Hdr*) override; 111 int32_t setAutoLowLatencyMode(int64_t display, bool on) override; 112 int32_t setClientTarget(int64_t display, buffer_handle_t target, 113 const ndk::ScopedFileDescriptor& fence, common::Dataspace dataspace, 114 const std::vector<common::Rect>& damage) override; 115 int32_t getHasClientComposition(int64_t display, bool& outHasClientComp) override; 116 int32_t setColorMode(int64_t display, ColorMode mode, RenderIntent intent) override; 117 int32_t setColorTransform(int64_t display, const std::vector<float>& matrix) override; 118 int32_t setContentType(int64_t display, ContentType contentType) override; 119 int32_t setDisplayBrightness(int64_t display, float brightness) override; 120 int32_t setDisplayedContentSamplingEnabled(int64_t display, bool enable, 121 FormatColorComponent componentMask, 122 int64_t maxFrames) override; 123 int32_t setLayerBlendMode(int64_t display, int64_t layer, common::BlendMode mode) override; 124 int32_t setLayerBuffer(int64_t display, int64_t layer, buffer_handle_t buffer, 125 const ndk::ScopedFileDescriptor& acquireFence) override; 126 int32_t uncacheLayerBuffers(int64_t display, int64_t layer, 127 const std::vector<buffer_handle_t>& buffers, 128 std::vector<buffer_handle_t>& outClearableBuffers) override; 129 int32_t setLayerColor(int64_t display, int64_t layer, Color color) override; 130 int32_t setLayerColorTransform(int64_t display, int64_t layer, 131 const std::vector<float>& matrix) override; 132 int32_t setLayerCompositionType(int64_t display, int64_t layer, Composition type) override; 133 int32_t setLayerCursorPosition(int64_t display, int64_t layer, int32_t x, int32_t y) override; 134 int32_t setLayerDataspace(int64_t display, int64_t layer, 135 common::Dataspace dataspace) override; 136 int32_t setLayerDisplayFrame(int64_t display, int64_t layer, 137 const common::Rect& frame) override; 138 int32_t setLayerPerFrameMetadata( 139 int64_t display, int64_t layer, 140 const std::vector<std::optional<PerFrameMetadata>>& metadata) override; 141 int32_t setLayerPerFrameMetadataBlobs( 142 int64_t display, int64_t layer, 143 const std::vector<std::optional<PerFrameMetadataBlob>>& blobs) override; 144 int32_t setLayerPlaneAlpha(int64_t display, int64_t layer, float alpha) override; 145 int32_t setLayerSidebandStream(int64_t display, int64_t layer, 146 buffer_handle_t stream) override; 147 int32_t setLayerSourceCrop(int64_t display, int64_t layer, 148 const common::FRect& crop) override; 149 int32_t setLayerSurfaceDamage( 150 int64_t display, int64_t layer, 151 const std::vector<std::optional<common::Rect>>& damage) override; 152 int32_t setLayerTransform(int64_t display, int64_t layer, 153 common::Transform transform) override; 154 int32_t setLayerVisibleRegion( 155 int64_t display, int64_t layer, 156 const std::vector<std::optional<common::Rect>>& visible) override; 157 int32_t setLayerBrightness(int64_t display, int64_t layer, float brightness) override; 158 int32_t setLayerZOrder(int64_t display, int64_t layer, uint32_t z) override; 159 int32_t setOutputBuffer(int64_t display, buffer_handle_t buffer, 160 const ndk::ScopedFileDescriptor& releaseFence) override; 161 int32_t setPowerMode(int64_t display, PowerMode mode) override; 162 int32_t getPowerMode(int64_t display, std::optional<PowerMode>& outMode) override; 163 int32_t setReadbackBuffer(int64_t display, buffer_handle_t buffer, 164 const ndk::ScopedFileDescriptor& releaseFence) override; 165 int32_t setVsyncEnabled(int64_t display, bool enabled) override; 166 int32_t getDisplayIdleTimerSupport(int64_t display, bool& outSupport) override; 167 int32_t getDisplayMultiThreadedPresentSupport(const int64_t& display, 168 bool& outSupport) override; 169 int32_t setIdleTimerEnabled(int64_t display, int32_t timeout) override; 170 int32_t getRCDLayerSupport(int64_t display, bool& outSupport) override; 171 int32_t setLayerBlockingRegion( 172 int64_t display, int64_t layer, 173 const std::vector<std::optional<common::Rect>>& blockingRegion) override; 174 int32_t validateDisplay(int64_t display, std::vector<int64_t>* outChangedLayers, 175 std::vector<Composition>* outCompositionTypes, 176 uint32_t* outDisplayRequestMask, 177 std::vector<int64_t>* outRequestedLayers, 178 std::vector<int32_t>* outRequestMasks, 179 ClientTargetProperty* outClientTargetProperty, 180 DimmingStage* outDimmingStage) override; 181 int32_t setExpectedPresentTime( 182 int64_t display, const std::optional<ClockMonotonicTimestamp> expectedPresentTime, 183 int frameIntervalNs) override; 184 getEventCallback()185 EventCallback* getEventCallback() { return mEventCallback; } 186 int32_t setRefreshRateChangedCallbackDebugEnabled(int64_t display, bool enabled) override; 187 int32_t layerSf2Hwc(int64_t display, int64_t layer, hwc2_layer_t& outMappedLayer) override; 188 void setHwcBatchingSupport(bool supported); 189 190 private: 191 void initCaps(bool batchingSupported); 192 int32_t getHalDisplay(int64_t display, ExynosDisplay*& halDisplay); 193 int32_t getHalLayer(int64_t display, int64_t layer, ExynosLayer*& halLayer); 194 195 std::unique_ptr<ExynosDevice> mDevice; 196 EventCallback* mEventCallback; 197 #ifdef USES_HWC_SERVICES 198 std::unique_ptr<ExynosHWCCtx> mHwcCtx; 199 #endif 200 std::unordered_set<Capability> mCaps; 201 std::map<int64_t, hwc2_layer_t> mSfLayerToHalLayerMap; 202 std::map<hwc2_layer_t, int64_t> mHalLayerToSfLayerMap; 203 }; 204 205 } // namespace aidl::android::hardware::graphics::composer3::impl 206