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 | |
| 17 | #ifndef ANDROID_SF_COMPOSER_HAL_H |
| 18 | #define ANDROID_SF_COMPOSER_HAL_H |
| 19 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 20 | #include <memory> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 21 | #include <string> |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 22 | #include <unordered_map> |
| 23 | #include <utility> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 24 | #include <vector> |
| 25 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 26 | #include <android/frameworks/vr/composer/1.0/IVrComposerClient.h> |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame^] | 27 | #include <android/hardware/graphics/common/1.1/types.h> |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 28 | #include <android/hardware/graphics/composer/2.2/IComposer.h> |
| 29 | #include <android/hardware/graphics/composer/2.2/IComposerClient.h> |
| 30 | #include <composer-command-buffer/2.2/ComposerCommandBuffer.h> |
| 31 | #include <gui/HdrMetadata.h> |
Lloyd Pique | d0094aa | 2017-12-20 16:43:28 -0800 | [diff] [blame] | 32 | #include <ui/GraphicBuffer.h> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 33 | #include <utils/StrongPointer.h> |
| 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | namespace Hwc2 { |
| 38 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 39 | using android::frameworks::vr::composer::V1_0::IVrComposerClient; |
| 40 | |
Chia-I Wu | 5901fda | 2016-11-17 10:26:37 +0800 | [diff] [blame] | 41 | using android::hardware::graphics::common::V1_0::ColorMode; |
| 42 | using android::hardware::graphics::common::V1_0::ColorTransform; |
Chia-I Wu | 5901fda | 2016-11-17 10:26:37 +0800 | [diff] [blame] | 43 | using android::hardware::graphics::common::V1_0::Hdr; |
Chia-I Wu | 5901fda | 2016-11-17 10:26:37 +0800 | [diff] [blame] | 44 | using android::hardware::graphics::common::V1_0::Transform; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame^] | 45 | using android::hardware::graphics::common::V1_1::Dataspace; |
| 46 | using android::hardware::graphics::common::V1_1::PixelFormat; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 47 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 48 | using android::hardware::graphics::composer::V2_1::Config; |
| 49 | using android::hardware::graphics::composer::V2_1::Display; |
| 50 | using android::hardware::graphics::composer::V2_1::Error; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 51 | using android::hardware::graphics::composer::V2_1::IComposer; |
| 52 | using android::hardware::graphics::composer::V2_1::IComposerCallback; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 53 | using android::hardware::graphics::composer::V2_1::Layer; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 54 | using android::hardware::graphics::composer::V2_2::IComposerClient; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 55 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 56 | using android::hardware::graphics::composer::V2_2::CommandReaderBase; |
| 57 | using android::hardware::graphics::composer::V2_2::CommandWriterBase; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 58 | |
| 59 | using android::hardware::kSynchronizedReadWrite; |
| 60 | using android::hardware::MessageQueue; |
| 61 | using android::hardware::MQDescriptorSync; |
| 62 | using android::hardware::hidl_vec; |
| 63 | using android::hardware::hidl_handle; |
| 64 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 65 | class Composer { |
| 66 | public: |
| 67 | virtual ~Composer() = 0; |
| 68 | |
| 69 | virtual std::vector<IComposer::Capability> getCapabilities() = 0; |
| 70 | virtual std::string dumpDebugInfo() = 0; |
| 71 | |
| 72 | virtual void registerCallback(const sp<IComposerCallback>& callback) = 0; |
| 73 | |
| 74 | // Returns true if the connected composer service is running in a remote |
| 75 | // process, false otherwise. This will return false if the service is |
| 76 | // configured in passthrough mode, for example. |
| 77 | virtual bool isRemote() = 0; |
| 78 | |
| 79 | // Reset all pending commands in the command buffer. Useful if you want to |
| 80 | // skip a frame but have already queued some commands. |
| 81 | virtual void resetCommands() = 0; |
| 82 | |
| 83 | // Explicitly flush all pending commands in the command buffer. |
| 84 | virtual Error executeCommands() = 0; |
| 85 | |
| 86 | virtual uint32_t getMaxVirtualDisplayCount() = 0; |
| 87 | virtual bool isUsingVrComposer() const = 0; |
| 88 | virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, |
| 89 | Display* outDisplay) = 0; |
| 90 | virtual Error destroyVirtualDisplay(Display display) = 0; |
| 91 | |
| 92 | virtual Error acceptDisplayChanges(Display display) = 0; |
| 93 | |
| 94 | virtual Error createLayer(Display display, Layer* outLayer) = 0; |
| 95 | virtual Error destroyLayer(Display display, Layer layer) = 0; |
| 96 | |
| 97 | virtual Error getActiveConfig(Display display, Config* outConfig) = 0; |
| 98 | virtual Error getChangedCompositionTypes( |
| 99 | Display display, std::vector<Layer>* outLayers, |
| 100 | std::vector<IComposerClient::Composition>* outTypes) = 0; |
| 101 | virtual Error getColorModes(Display display, std::vector<ColorMode>* outModes) = 0; |
| 102 | virtual Error getDisplayAttribute(Display display, Config config, |
| 103 | IComposerClient::Attribute attribute, int32_t* outValue) = 0; |
| 104 | virtual Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs) = 0; |
| 105 | virtual Error getDisplayName(Display display, std::string* outName) = 0; |
| 106 | |
| 107 | virtual Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 108 | std::vector<Layer>* outLayers, |
| 109 | std::vector<uint32_t>* outLayerRequestMasks) = 0; |
| 110 | |
| 111 | virtual Error getDisplayType(Display display, IComposerClient::DisplayType* outType) = 0; |
| 112 | virtual Error getDozeSupport(Display display, bool* outSupport) = 0; |
| 113 | virtual Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 114 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 115 | float* outMinLuminance) = 0; |
| 116 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 117 | virtual Error getPerFrameMetadataKeys( |
| 118 | Display display, std::vector<IComposerClient::PerFrameMetadataKey>* outKeys) = 0; |
| 119 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 120 | virtual Error getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 121 | std::vector<int>* outReleaseFences) = 0; |
| 122 | |
| 123 | virtual Error presentDisplay(Display display, int* outPresentFence) = 0; |
| 124 | |
| 125 | virtual Error setActiveConfig(Display display, Config config) = 0; |
| 126 | |
| 127 | /* |
| 128 | * The composer caches client targets internally. When target is nullptr, |
| 129 | * the composer uses slot to look up the client target from its cache. |
| 130 | * When target is not nullptr, the cache is updated with the new target. |
| 131 | */ |
| 132 | virtual Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 133 | int acquireFence, Dataspace dataspace, |
| 134 | const std::vector<IComposerClient::Rect>& damage) = 0; |
| 135 | virtual Error setColorMode(Display display, ColorMode mode) = 0; |
| 136 | virtual Error setColorTransform(Display display, const float* matrix, ColorTransform hint) = 0; |
| 137 | virtual Error setOutputBuffer(Display display, const native_handle_t* buffer, |
| 138 | int releaseFence) = 0; |
| 139 | virtual Error setPowerMode(Display display, IComposerClient::PowerMode mode) = 0; |
| 140 | virtual Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) = 0; |
| 141 | |
| 142 | virtual Error setClientTargetSlotCount(Display display) = 0; |
| 143 | |
| 144 | virtual Error validateDisplay(Display display, uint32_t* outNumTypes, |
| 145 | uint32_t* outNumRequests) = 0; |
| 146 | |
| 147 | virtual Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes, |
| 148 | uint32_t* outNumRequests, int* outPresentFence, |
| 149 | uint32_t* state) = 0; |
| 150 | |
| 151 | virtual Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) = 0; |
| 152 | /* see setClientTarget for the purpose of slot */ |
| 153 | virtual Error setLayerBuffer(Display display, Layer layer, uint32_t slot, |
| 154 | const sp<GraphicBuffer>& buffer, int acquireFence) = 0; |
| 155 | virtual Error setLayerSurfaceDamage(Display display, Layer layer, |
| 156 | const std::vector<IComposerClient::Rect>& damage) = 0; |
| 157 | virtual Error setLayerBlendMode(Display display, Layer layer, |
| 158 | IComposerClient::BlendMode mode) = 0; |
| 159 | virtual Error setLayerColor(Display display, Layer layer, |
| 160 | const IComposerClient::Color& color) = 0; |
| 161 | virtual Error setLayerCompositionType(Display display, Layer layer, |
| 162 | IComposerClient::Composition type) = 0; |
| 163 | virtual Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) = 0; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 164 | virtual Error setLayerHdrMetadata(Display display, Layer layer, |
| 165 | const HdrMetadata& metadata) = 0; |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 166 | virtual Error setLayerDisplayFrame(Display display, Layer layer, |
| 167 | const IComposerClient::Rect& frame) = 0; |
| 168 | virtual Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) = 0; |
| 169 | virtual Error setLayerSidebandStream(Display display, Layer layer, |
| 170 | const native_handle_t* stream) = 0; |
| 171 | virtual Error setLayerSourceCrop(Display display, Layer layer, |
| 172 | const IComposerClient::FRect& crop) = 0; |
| 173 | virtual Error setLayerTransform(Display display, Layer layer, Transform transform) = 0; |
| 174 | virtual Error setLayerVisibleRegion(Display display, Layer layer, |
| 175 | const std::vector<IComposerClient::Rect>& visible) = 0; |
| 176 | virtual Error setLayerZOrder(Display display, Layer layer, uint32_t z) = 0; |
| 177 | virtual Error setLayerInfo(Display display, Layer layer, uint32_t type, uint32_t appId) = 0; |
| 178 | }; |
| 179 | |
| 180 | namespace impl { |
| 181 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 182 | class CommandReader : public CommandReaderBase { |
| 183 | public: |
| 184 | ~CommandReader(); |
| 185 | |
| 186 | // Parse and execute commands from the command queue. The commands are |
| 187 | // actually return values from the server and will be saved in ReturnData. |
| 188 | Error parse(); |
| 189 | |
| 190 | // Get and clear saved errors. |
| 191 | struct CommandError { |
| 192 | uint32_t location; |
| 193 | Error error; |
| 194 | }; |
| 195 | std::vector<CommandError> takeErrors(); |
| 196 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 197 | bool hasChanges(Display display, uint32_t* outNumChangedCompositionTypes, |
| 198 | uint32_t* outNumLayerRequestMasks) const; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 199 | |
| 200 | // Get and clear saved changed composition types. |
| 201 | void takeChangedCompositionTypes(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 202 | std::vector<Layer>* outLayers, |
| 203 | std::vector<IComposerClient::Composition>* outTypes); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 204 | |
| 205 | // Get and clear saved display requests. |
| 206 | void takeDisplayRequests(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 207 | uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers, |
| 208 | std::vector<uint32_t>* outLayerRequestMasks); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 209 | |
| 210 | // Get and clear saved release fences. |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 211 | void takeReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 212 | std::vector<int>* outReleaseFences); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 213 | |
| 214 | // Get and clear saved present fence. |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 215 | void takePresentFence(Display display, int* outPresentFence); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 216 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 217 | // Get what stage succeeded during PresentOrValidate: Present or Validate |
| 218 | void takePresentOrValidateStage(Display display, uint32_t * state); |
| 219 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 220 | private: |
| 221 | void resetData(); |
| 222 | |
| 223 | bool parseSelectDisplay(uint16_t length); |
| 224 | bool parseSetError(uint16_t length); |
| 225 | bool parseSetChangedCompositionTypes(uint16_t length); |
| 226 | bool parseSetDisplayRequests(uint16_t length); |
| 227 | bool parseSetPresentFence(uint16_t length); |
| 228 | bool parseSetReleaseFences(uint16_t length); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 229 | bool parseSetPresentOrValidateDisplayResult(uint16_t length); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 230 | |
| 231 | struct ReturnData { |
| 232 | uint32_t displayRequests = 0; |
| 233 | |
| 234 | std::vector<Layer> changedLayers; |
| 235 | std::vector<IComposerClient::Composition> compositionTypes; |
| 236 | |
| 237 | std::vector<Layer> requestedLayers; |
| 238 | std::vector<uint32_t> requestMasks; |
| 239 | |
| 240 | int presentFence = -1; |
| 241 | |
| 242 | std::vector<Layer> releasedLayers; |
| 243 | std::vector<int> releaseFences; |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 244 | |
| 245 | uint32_t presentOrValidateState; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | std::vector<CommandError> mErrors; |
| 249 | std::unordered_map<Display, ReturnData> mReturnData; |
| 250 | |
| 251 | // When SELECT_DISPLAY is parsed, this is updated to point to the |
| 252 | // display's return data in mReturnData. We use it to avoid repeated |
| 253 | // map lookups. |
| 254 | ReturnData* mCurrentReturnData; |
| 255 | }; |
| 256 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 257 | // Composer is a wrapper to IComposer, a proxy to server-side composer. |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 258 | class Composer final : public Hwc2::Composer { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 259 | public: |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 260 | Composer(const std::string& serviceName); |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 261 | ~Composer() override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 262 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 263 | std::vector<IComposer::Capability> getCapabilities() override; |
| 264 | std::string dumpDebugInfo() override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 265 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 266 | void registerCallback(const sp<IComposerCallback>& callback) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 267 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 268 | // Returns true if the connected composer service is running in a remote |
| 269 | // process, false otherwise. This will return false if the service is |
| 270 | // configured in passthrough mode, for example. |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 271 | bool isRemote() override; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 272 | |
Steven Thomas | 0af4b9f | 2017-04-26 14:34:01 -0700 | [diff] [blame] | 273 | // Reset all pending commands in the command buffer. Useful if you want to |
| 274 | // skip a frame but have already queued some commands. |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 275 | void resetCommands() override; |
Steven Thomas | 0af4b9f | 2017-04-26 14:34:01 -0700 | [diff] [blame] | 276 | |
Chia-I Wu | ae5a6b8 | 2017-10-10 09:09:22 -0700 | [diff] [blame] | 277 | // Explicitly flush all pending commands in the command buffer. |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 278 | Error executeCommands() override; |
Chia-I Wu | ae5a6b8 | 2017-10-10 09:09:22 -0700 | [diff] [blame] | 279 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 280 | uint32_t getMaxVirtualDisplayCount() override; |
| 281 | bool isUsingVrComposer() const override { return mIsUsingVrComposer; } |
| 282 | Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, |
| 283 | Display* outDisplay) override; |
| 284 | Error destroyVirtualDisplay(Display display) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 285 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 286 | Error acceptDisplayChanges(Display display) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 287 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 288 | Error createLayer(Display display, Layer* outLayer) override; |
| 289 | Error destroyLayer(Display display, Layer layer) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 290 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 291 | Error getActiveConfig(Display display, Config* outConfig) override; |
| 292 | Error getChangedCompositionTypes(Display display, std::vector<Layer>* outLayers, |
| 293 | std::vector<IComposerClient::Composition>* outTypes) override; |
| 294 | Error getColorModes(Display display, std::vector<ColorMode>* outModes) override; |
| 295 | Error getDisplayAttribute(Display display, Config config, IComposerClient::Attribute attribute, |
| 296 | int32_t* outValue) override; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 297 | Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs); |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 298 | Error getDisplayName(Display display, std::string* outName) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 299 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 300 | Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 301 | std::vector<Layer>* outLayers, |
| 302 | std::vector<uint32_t>* outLayerRequestMasks) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 303 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 304 | Error getDisplayType(Display display, IComposerClient::DisplayType* outType) override; |
| 305 | Error getDozeSupport(Display display, bool* outSupport) override; |
| 306 | Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, float* outMaxLuminance, |
| 307 | float* outMaxAverageLuminance, float* outMinLuminance) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 308 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 309 | Error getPerFrameMetadataKeys( |
| 310 | Display display, std::vector<IComposerClient::PerFrameMetadataKey>* outKeys) override; |
| 311 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 312 | Error getReleaseFences(Display display, std::vector<Layer>* outLayers, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 313 | std::vector<int>* outReleaseFences) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 314 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 315 | Error presentDisplay(Display display, int* outPresentFence) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 316 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 317 | Error setActiveConfig(Display display, Config config) override; |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 318 | |
| 319 | /* |
| 320 | * The composer caches client targets internally. When target is nullptr, |
| 321 | * the composer uses slot to look up the client target from its cache. |
| 322 | * When target is not nullptr, the cache is updated with the new target. |
| 323 | */ |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 324 | Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target, |
| 325 | int acquireFence, Dataspace dataspace, |
| 326 | const std::vector<IComposerClient::Rect>& damage) override; |
| 327 | Error setColorMode(Display display, ColorMode mode) override; |
| 328 | Error setColorTransform(Display display, const float* matrix, ColorTransform hint) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 329 | Error setOutputBuffer(Display display, const native_handle_t* buffer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 330 | int releaseFence) override; |
| 331 | Error setPowerMode(Display display, IComposerClient::PowerMode mode) override; |
| 332 | Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) override; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 333 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 334 | Error setClientTargetSlotCount(Display display) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 335 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 336 | Error validateDisplay(Display display, uint32_t* outNumTypes, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 337 | uint32_t* outNumRequests) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 338 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 339 | Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 340 | int* outPresentFence, uint32_t* state) override; |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 341 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 342 | Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override; |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 343 | /* see setClientTarget for the purpose of slot */ |
| 344 | Error setLayerBuffer(Display display, Layer layer, uint32_t slot, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 345 | const sp<GraphicBuffer>& buffer, int acquireFence) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 346 | Error setLayerSurfaceDamage(Display display, Layer layer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 347 | const std::vector<IComposerClient::Rect>& damage) override; |
| 348 | Error setLayerBlendMode(Display display, Layer layer, IComposerClient::BlendMode mode) override; |
| 349 | Error setLayerColor(Display display, Layer layer, const IComposerClient::Color& color) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 350 | Error setLayerCompositionType(Display display, Layer layer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 351 | IComposerClient::Composition type) override; |
| 352 | Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) override; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 353 | Error setLayerHdrMetadata(Display display, Layer layer, const HdrMetadata& metadata) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 354 | Error setLayerDisplayFrame(Display display, Layer layer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 355 | const IComposerClient::Rect& frame) override; |
| 356 | Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 357 | Error setLayerSidebandStream(Display display, Layer layer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 358 | const native_handle_t* stream) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 359 | Error setLayerSourceCrop(Display display, Layer layer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 360 | const IComposerClient::FRect& crop) override; |
| 361 | Error setLayerTransform(Display display, Layer layer, Transform transform) override; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 362 | Error setLayerVisibleRegion(Display display, Layer layer, |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 363 | const std::vector<IComposerClient::Rect>& visible) override; |
| 364 | Error setLayerZOrder(Display display, Layer layer, uint32_t z) override; |
| 365 | Error setLayerInfo(Display display, Layer layer, uint32_t type, uint32_t appId) override; |
| 366 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 367 | private: |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 368 | class CommandWriter : public CommandWriterBase { |
| 369 | public: |
| 370 | CommandWriter(uint32_t initialMaxSize); |
| 371 | ~CommandWriter() override; |
| 372 | |
| 373 | void setLayerInfo(uint32_t type, uint32_t appId); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 374 | void setClientTargetMetadata( |
| 375 | const IVrComposerClient::BufferMetadata& metadata); |
| 376 | void setLayerBufferMetadata( |
| 377 | const IVrComposerClient::BufferMetadata& metadata); |
| 378 | |
| 379 | private: |
| 380 | void writeBufferMetadata( |
| 381 | const IVrComposerClient::BufferMetadata& metadata); |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 382 | }; |
| 383 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 384 | // Many public functions above simply write a command into the command |
| 385 | // queue to batch the calls. validateDisplay and presentDisplay will call |
| 386 | // this function to execute the command queue. |
| 387 | Error execute(); |
| 388 | |
| 389 | sp<IComposer> mComposer; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 390 | sp<hardware::graphics::composer::V2_1::IComposerClient> mClient; |
| 391 | sp<IComposerClient> mClient_2_2; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 392 | |
| 393 | // 64KiB minus a small space for metadata such as read/write pointers |
| 394 | static constexpr size_t kWriterInitialSize = |
| 395 | 64 * 1024 / sizeof(uint32_t) - 16; |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 396 | CommandWriter mWriter; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 397 | CommandReader mReader; |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 398 | |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 399 | // When true, the we attach to the vr_hwcomposer service instead of the |
| 400 | // hwcomposer. This allows us to redirect surfaces to 3d surfaces in vr. |
| 401 | const bool mIsUsingVrComposer; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 402 | }; |
| 403 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 404 | } // namespace impl |
| 405 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 406 | } // namespace Hwc2 |
| 407 | |
| 408 | } // namespace android |
| 409 | |
| 410 | #endif // ANDROID_SF_COMPOSER_HAL_H |