Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 17 | #pragma once |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 18 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 19 | #include <memory> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 20 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 21 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 22 | #pragma clang diagnostic push |
| 23 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 24 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 25 | |
Peiyong Lin | afa0f57 | 2020-01-13 16:35:02 -0800 | [diff] [blame] | 26 | #include <composer-command-buffer/2.4/ComposerCommandBuffer.h> |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 27 | #include <gui/BufferQueue.h> |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 28 | #include <gui/HdrMetadata.h> |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 29 | #include <math/mat4.h> |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 30 | #include <ui/DisplayedFrameStats.h> |
Lloyd Pique | d0094aa | 2017-12-20 16:43:28 -0800 | [diff] [blame] | 31 | #include <ui/GraphicBuffer.h> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 32 | #include <utils/StrongPointer.h> |
| 33 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 34 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
| 35 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 36 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 37 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 38 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 39 | namespace android::Hwc2 { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 40 | |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 41 | namespace types = hardware::graphics::common; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 42 | |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 43 | namespace V2_1 = hardware::graphics::composer::V2_1; |
| 44 | namespace V2_2 = hardware::graphics::composer::V2_2; |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 45 | namespace V2_3 = hardware::graphics::composer::V2_3; |
Dominik Laskowski | 25a4e7d | 2019-09-20 14:50:10 -0700 | [diff] [blame] | 46 | namespace V2_4 = hardware::graphics::composer::V2_4; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 47 | |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 48 | using types::V1_0::ColorTransform; |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 49 | using types::V1_0::Transform; |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 50 | using types::V1_1::RenderIntent; |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 51 | using types::V1_2::ColorMode; |
| 52 | using types::V1_2::Dataspace; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 53 | using types::V1_2::Hdr; |
Kevin DuBois | 73d0f48 | 2019-01-25 11:18:03 -0800 | [diff] [blame] | 54 | using types::V1_2::PixelFormat; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 55 | |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 56 | using V2_1::Config; |
| 57 | using V2_1::Display; |
| 58 | using V2_1::Error; |
Dominik Laskowski | 6231aaf | 2018-04-02 17:10:23 -0700 | [diff] [blame] | 59 | using V2_1::Layer; |
Peiyong Lin | afa0f57 | 2020-01-13 16:35:02 -0800 | [diff] [blame] | 60 | using V2_4::CommandReaderBase; |
| 61 | using V2_4::CommandWriterBase; |
Dominik Laskowski | 25a4e7d | 2019-09-20 14:50:10 -0700 | [diff] [blame] | 62 | using V2_4::IComposer; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 63 | using V2_4::IComposerCallback; |
Dominik Laskowski | 25a4e7d | 2019-09-20 14:50:10 -0700 | [diff] [blame] | 64 | using V2_4::IComposerClient; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 65 | using V2_4::VsyncPeriodChangeTimeline; |
| 66 | using V2_4::VsyncPeriodNanos; |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 67 | using DisplayCapability = IComposerClient::DisplayCapability; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 68 | using PerFrameMetadata = IComposerClient::PerFrameMetadata; |
| 69 | using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 70 | using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 71 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 72 | class Composer { |
| 73 | public: |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 74 | static std::unique_ptr<Composer> create(const std::string& serviceName); |
| 75 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 76 | virtual ~Composer() = 0; |
| 77 | |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 78 | enum class OptionalFeature { |
| 79 | RefreshRateSwitching, |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame^] | 80 | ExpectedPresentTime, |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | virtual bool isSupported(OptionalFeature) const = 0; |
| 84 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 85 | virtual std::vector<IComposer::Capability> getCapabilities() = 0; |
| 86 | virtual std::string dumpDebugInfo() = 0; |
| 87 | |
| 88 | virtual void registerCallback(const sp<IComposerCallback>& callback) = 0; |
| 89 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 90 | // Reset all pending commands in the command buffer. Useful if you want to |
| 91 | // skip a frame but have already queued some commands. |
| 92 | virtual void resetCommands() = 0; |
| 93 | |
| 94 | // Explicitly flush all pending commands in the command buffer. |
| 95 | virtual Error executeCommands() = 0; |
| 96 | |
| 97 | virtual uint32_t getMaxVirtualDisplayCount() = 0; |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 98 | virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat*, |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 99 | Display* outDisplay) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 100 | virtual Error destroyVirtualDisplay(Display display) = 0; |
| 101 | |
| 102 | virtual Error acceptDisplayChanges(Display display) = 0; |
| 103 | |
| 104 | virtual Error createLayer(Display display, Layer* outLayer) = 0; |
| 105 | virtual Error destroyLayer(Display display, Layer layer) = 0; |
| 106 | |
| 107 | virtual Error getActiveConfig(Display display, Config* outConfig) = 0; |
| 108 | virtual Error getChangedCompositionTypes( |
| 109 | Display display, std::vector<Layer>* outLayers, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 110 | std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 111 | virtual Error getColorModes(Display display, std::vector<ColorMode>* outModes) = 0; |
| 112 | virtual Error getDisplayAttribute(Display display, Config config, |
| 113 | IComposerClient::Attribute attribute, int32_t* outValue) = 0; |
| 114 | virtual Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs) = 0; |
| 115 | virtual Error getDisplayName(Display display, std::string* outName) = 0; |
| 116 | |
| 117 | virtual Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 118 | std::vector<Layer>* outLayers, |
| 119 | std::vector<uint32_t>* outLayerRequestMasks) = 0; |
| 120 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 121 | virtual Error getDozeSupport(Display display, bool* outSupport) = 0; |
| 122 | virtual Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 123 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 124 | float* outMinLuminance) = 0; |
| 125 | |
| 126 | virtual Error getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 127 | std::vector<int>* outReleaseFences) = 0; |
| 128 | |
| 129 | virtual Error presentDisplay(Display display, int* outPresentFence) = 0; |
| 130 | |
| 131 | virtual Error setActiveConfig(Display display, Config config) = 0; |
| 132 | |
| 133 | /* |
| 134 | * The composer caches client targets internally. When target is nullptr, |
| 135 | * the composer uses slot to look up the client target from its cache. |
| 136 | * When target is not nullptr, the cache is updated with the new target. |
| 137 | */ |
| 138 | virtual Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 139 | int acquireFence, Dataspace dataspace, |
| 140 | const std::vector<IComposerClient::Rect>& damage) = 0; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 141 | virtual Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 142 | virtual Error setColorTransform(Display display, const float* matrix, ColorTransform hint) = 0; |
| 143 | virtual Error setOutputBuffer(Display display, const native_handle_t* buffer, |
| 144 | int releaseFence) = 0; |
| 145 | virtual Error setPowerMode(Display display, IComposerClient::PowerMode mode) = 0; |
| 146 | virtual Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) = 0; |
| 147 | |
| 148 | virtual Error setClientTargetSlotCount(Display display) = 0; |
| 149 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame^] | 150 | virtual Error validateDisplay(Display display, nsecs_t expectedPresentTime, |
| 151 | uint32_t* outNumTypes, uint32_t* outNumRequests) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 152 | |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame^] | 153 | virtual Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime, |
| 154 | uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 155 | int* outPresentFence, uint32_t* state) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 156 | |
| 157 | virtual Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) = 0; |
| 158 | /* see setClientTarget for the purpose of slot */ |
| 159 | virtual Error setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 160 | const sp<GraphicBuffer>& buffer, int acquireFence) = 0; |
| 161 | virtual Error setLayerSurfaceDamage(Display display, Layer layer, |
| 162 | const std::vector<IComposerClient::Rect>& damage) = 0; |
| 163 | virtual Error setLayerBlendMode(Display display, Layer layer, |
| 164 | IComposerClient::BlendMode mode) = 0; |
| 165 | virtual Error setLayerColor(Display display, Layer layer, |
| 166 | const IComposerClient::Color& color) = 0; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 167 | virtual Error setLayerCompositionType( |
| 168 | Display display, Layer layer, |
| 169 | aidl::android::hardware::graphics::composer3::Composition type) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 170 | virtual Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) = 0; |
| 171 | virtual Error setLayerDisplayFrame(Display display, Layer layer, |
| 172 | const IComposerClient::Rect& frame) = 0; |
| 173 | virtual Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) = 0; |
| 174 | virtual Error setLayerSidebandStream(Display display, Layer layer, |
| 175 | const native_handle_t* stream) = 0; |
| 176 | virtual Error setLayerSourceCrop(Display display, Layer layer, |
| 177 | const IComposerClient::FRect& crop) = 0; |
| 178 | virtual Error setLayerTransform(Display display, Layer layer, Transform transform) = 0; |
| 179 | virtual Error setLayerVisibleRegion(Display display, Layer layer, |
| 180 | const std::vector<IComposerClient::Rect>& visible) = 0; |
| 181 | virtual Error setLayerZOrder(Display display, Layer layer, uint32_t z) = 0; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 182 | |
| 183 | // Composer HAL 2.2 |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 184 | virtual Error setLayerPerFrameMetadata( |
| 185 | Display display, Layer layer, |
| 186 | const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) = 0; |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 187 | virtual std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys( |
| 188 | Display display) = 0; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 189 | virtual Error getRenderIntents(Display display, ColorMode colorMode, |
| 190 | std::vector<RenderIntent>* outRenderIntents) = 0; |
| 191 | virtual Error getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) = 0; |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 192 | |
| 193 | // Composer HAL 2.3 |
| 194 | virtual Error getDisplayIdentificationData(Display display, uint8_t* outPort, |
| 195 | std::vector<uint8_t>* outData) = 0; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 196 | virtual Error setLayerColorTransform(Display display, Layer layer, |
| 197 | const float* matrix) = 0; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 198 | virtual Error getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat, |
| 199 | Dataspace* outDataspace, |
| 200 | uint8_t* outComponentMask) = 0; |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 201 | virtual Error setDisplayContentSamplingEnabled(Display display, bool enabled, |
| 202 | uint8_t componentMask, uint64_t maxFrames) = 0; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 203 | virtual Error getDisplayedContentSample(Display display, uint64_t maxFrames, uint64_t timestamp, |
| 204 | DisplayedFrameStats* outStats) = 0; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 205 | virtual Error setLayerPerFrameMetadataBlobs( |
| 206 | Display display, Layer layer, const std::vector<PerFrameMetadataBlob>& metadata) = 0; |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 207 | virtual Error setDisplayBrightness(Display display, float brightness) = 0; |
Dominik Laskowski | 25a4e7d | 2019-09-20 14:50:10 -0700 | [diff] [blame] | 208 | |
| 209 | // Composer HAL 2.4 |
| 210 | virtual Error getDisplayCapabilities(Display display, |
| 211 | std::vector<DisplayCapability>* outCapabilities) = 0; |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 212 | virtual V2_4::Error getDisplayConnectionType( |
| 213 | Display display, IComposerClient::DisplayConnectionType* outType) = 0; |
| 214 | virtual V2_4::Error getDisplayVsyncPeriod(Display display, |
| 215 | VsyncPeriodNanos* outVsyncPeriod) = 0; |
| 216 | virtual V2_4::Error setActiveConfigWithConstraints( |
| 217 | Display display, Config config, |
| 218 | const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints, |
| 219 | VsyncPeriodChangeTimeline* outTimeline) = 0; |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 220 | |
| 221 | virtual V2_4::Error setAutoLowLatencyMode(Display displayId, bool on) = 0; |
| 222 | virtual V2_4::Error getSupportedContentTypes( |
| 223 | Display displayId, |
| 224 | std::vector<IComposerClient::ContentType>* outSupportedContentTypes) = 0; |
| 225 | virtual V2_4::Error setContentType(Display displayId, |
| 226 | IComposerClient::ContentType contentType) = 0; |
Dan Stoza | 18d48cb | 2019-10-21 15:39:24 -0700 | [diff] [blame] | 227 | virtual V2_4::Error setLayerGenericMetadata(Display display, Layer layer, |
| 228 | const std::string& key, bool mandatory, |
| 229 | const std::vector<uint8_t>& value) = 0; |
| 230 | virtual V2_4::Error getLayerGenericMetadataKeys( |
| 231 | std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) = 0; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 232 | virtual Error getClientTargetProperty( |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 233 | Display display, IComposerClient::ClientTargetProperty* outClientTargetProperty, |
| 234 | float* outWhitePointNits) = 0; |
| 235 | |
| 236 | // AIDL Composer |
| 237 | virtual Error setLayerWhitePointNits(Display display, Layer layer, float whitePointNits) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
Ady Abraham | 9fc2805 | 2021-10-14 17:21:38 -0700 | [diff] [blame] | 240 | } // namespace android::Hwc2 |