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 | |
| 26 | #include <android/hardware/graphics/composer/2.1/IComposer.h> |
| 27 | #include <utils/StrongPointer.h> |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 28 | #include <IComposerCommandBuffer.h> |
| 29 | #include <MessageQueue.h> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | namespace Hwc2 { |
| 34 | |
Chia-I Wu | 5901fda | 2016-11-17 10:26:37 +0800 | [diff] [blame] | 35 | using android::hardware::graphics::common::V1_0::ColorMode; |
| 36 | using android::hardware::graphics::common::V1_0::ColorTransform; |
| 37 | using android::hardware::graphics::common::V1_0::Dataspace; |
| 38 | using android::hardware::graphics::common::V1_0::Hdr; |
| 39 | using android::hardware::graphics::common::V1_0::PixelFormat; |
| 40 | using android::hardware::graphics::common::V1_0::Transform; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 41 | |
| 42 | using android::hardware::graphics::composer::V2_1::IComposer; |
| 43 | using android::hardware::graphics::composer::V2_1::IComposerCallback; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 44 | using android::hardware::graphics::composer::V2_1::IComposerClient; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 45 | using android::hardware::graphics::composer::V2_1::Error; |
| 46 | using android::hardware::graphics::composer::V2_1::Display; |
| 47 | using android::hardware::graphics::composer::V2_1::Layer; |
| 48 | using android::hardware::graphics::composer::V2_1::Config; |
| 49 | |
Daniel Nicoara | 3c9cbd4 | 2017-01-17 12:04:06 -0500 | [diff] [blame^] | 50 | using android::hardware::graphics::composer::V2_1::CommandWriterBase; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 51 | using android::hardware::graphics::composer::V2_1::CommandReaderBase; |
| 52 | |
| 53 | using android::hardware::kSynchronizedReadWrite; |
| 54 | using android::hardware::MessageQueue; |
| 55 | using android::hardware::MQDescriptorSync; |
| 56 | using android::hardware::hidl_vec; |
| 57 | using android::hardware::hidl_handle; |
| 58 | |
| 59 | class CommandReader : public CommandReaderBase { |
| 60 | public: |
| 61 | ~CommandReader(); |
| 62 | |
| 63 | // Parse and execute commands from the command queue. The commands are |
| 64 | // actually return values from the server and will be saved in ReturnData. |
| 65 | Error parse(); |
| 66 | |
| 67 | // Get and clear saved errors. |
| 68 | struct CommandError { |
| 69 | uint32_t location; |
| 70 | Error error; |
| 71 | }; |
| 72 | std::vector<CommandError> takeErrors(); |
| 73 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 74 | bool hasChanges(Display display, uint32_t* outNumChangedCompositionTypes, |
| 75 | uint32_t* outNumLayerRequestMasks) const; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 76 | |
| 77 | // Get and clear saved changed composition types. |
| 78 | void takeChangedCompositionTypes(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 79 | std::vector<Layer>* outLayers, |
| 80 | std::vector<IComposerClient::Composition>* outTypes); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 81 | |
| 82 | // Get and clear saved display requests. |
| 83 | void takeDisplayRequests(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 84 | uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers, |
| 85 | std::vector<uint32_t>* outLayerRequestMasks); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 86 | |
| 87 | // Get and clear saved release fences. |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 88 | void takeReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 89 | std::vector<int>* outReleaseFences); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 90 | |
| 91 | // Get and clear saved present fence. |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 92 | void takePresentFence(Display display, int* outPresentFence); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | void resetData(); |
| 96 | |
| 97 | bool parseSelectDisplay(uint16_t length); |
| 98 | bool parseSetError(uint16_t length); |
| 99 | bool parseSetChangedCompositionTypes(uint16_t length); |
| 100 | bool parseSetDisplayRequests(uint16_t length); |
| 101 | bool parseSetPresentFence(uint16_t length); |
| 102 | bool parseSetReleaseFences(uint16_t length); |
| 103 | |
| 104 | struct ReturnData { |
| 105 | uint32_t displayRequests = 0; |
| 106 | |
| 107 | std::vector<Layer> changedLayers; |
| 108 | std::vector<IComposerClient::Composition> compositionTypes; |
| 109 | |
| 110 | std::vector<Layer> requestedLayers; |
| 111 | std::vector<uint32_t> requestMasks; |
| 112 | |
| 113 | int presentFence = -1; |
| 114 | |
| 115 | std::vector<Layer> releasedLayers; |
| 116 | std::vector<int> releaseFences; |
| 117 | }; |
| 118 | |
| 119 | std::vector<CommandError> mErrors; |
| 120 | std::unordered_map<Display, ReturnData> mReturnData; |
| 121 | |
| 122 | // When SELECT_DISPLAY is parsed, this is updated to point to the |
| 123 | // display's return data in mReturnData. We use it to avoid repeated |
| 124 | // map lookups. |
| 125 | ReturnData* mCurrentReturnData; |
| 126 | }; |
| 127 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 128 | // Composer is a wrapper to IComposer, a proxy to server-side composer. |
| 129 | class Composer { |
| 130 | public: |
| 131 | Composer(); |
| 132 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 133 | std::vector<IComposer::Capability> getCapabilities(); |
| 134 | std::string dumpDebugInfo(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 135 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 136 | void registerCallback(const sp<IComposerCallback>& callback); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 137 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 138 | uint32_t getMaxVirtualDisplayCount(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 139 | Error createVirtualDisplay(uint32_t width, uint32_t height, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 140 | PixelFormat* format, Display* outDisplay); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 141 | Error destroyVirtualDisplay(Display display); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 142 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 143 | Error acceptDisplayChanges(Display display); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 144 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 145 | Error createLayer(Display display, Layer* outLayer); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 146 | Error destroyLayer(Display display, Layer layer); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 147 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 148 | Error getActiveConfig(Display display, Config* outConfig); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 149 | Error getChangedCompositionTypes(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 150 | std::vector<Layer>* outLayers, |
| 151 | std::vector<IComposerClient::Composition>* outTypes); |
| 152 | Error getColorModes(Display display, std::vector<ColorMode>* outModes); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 153 | Error getDisplayAttribute(Display display, Config config, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 154 | IComposerClient::Attribute attribute, int32_t* outValue); |
| 155 | Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs); |
| 156 | Error getDisplayName(Display display, std::string* outName); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 157 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 158 | Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask, |
| 159 | std::vector<Layer>* outLayers, |
| 160 | std::vector<uint32_t>* outLayerRequestMasks); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 161 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 162 | Error getDisplayType(Display display, |
| 163 | IComposerClient::DisplayType* outType); |
| 164 | Error getDozeSupport(Display display, bool* outSupport); |
| 165 | Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, |
| 166 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 167 | float* outMinLuminance); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 168 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 169 | Error getReleaseFences(Display display, std::vector<Layer>* outLayers, |
| 170 | std::vector<int>* outReleaseFences); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 171 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 172 | Error presentDisplay(Display display, int* outPresentFence); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 173 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 174 | Error setActiveConfig(Display display, Config config); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 175 | Error setClientTarget(Display display, const native_handle_t* target, |
| 176 | int acquireFence, Dataspace dataspace, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 177 | const std::vector<IComposerClient::Rect>& damage); |
| 178 | Error setColorMode(Display display, ColorMode mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 179 | Error setColorTransform(Display display, const float* matrix, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 180 | ColorTransform hint); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 181 | Error setOutputBuffer(Display display, const native_handle_t* buffer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 182 | int releaseFence); |
| 183 | Error setPowerMode(Display display, IComposerClient::PowerMode mode); |
| 184 | Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled); |
| 185 | |
| 186 | Error setClientTargetSlotCount(Display display); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 187 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 188 | Error validateDisplay(Display display, uint32_t* outNumTypes, |
| 189 | uint32_t* outNumRequests); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 190 | |
| 191 | Error setCursorPosition(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 192 | int32_t x, int32_t y); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 193 | Error setLayerBuffer(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 194 | const native_handle_t* buffer, int acquireFence); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 195 | Error setLayerSurfaceDamage(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 196 | const std::vector<IComposerClient::Rect>& damage); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 197 | Error setLayerBlendMode(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 198 | IComposerClient::BlendMode mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 199 | Error setLayerColor(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 200 | const IComposerClient::Color& color); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 201 | Error setLayerCompositionType(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 202 | IComposerClient::Composition type); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 203 | Error setLayerDataspace(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 204 | Dataspace dataspace); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 205 | Error setLayerDisplayFrame(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 206 | const IComposerClient::Rect& frame); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 207 | Error setLayerPlaneAlpha(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 208 | float alpha); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 209 | Error setLayerSidebandStream(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 210 | const native_handle_t* stream); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 211 | Error setLayerSourceCrop(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 212 | const IComposerClient::FRect& crop); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 213 | Error setLayerTransform(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 214 | Transform transform); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 215 | Error setLayerVisibleRegion(Display display, Layer layer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 216 | const std::vector<IComposerClient::Rect>& visible); |
| 217 | Error setLayerZOrder(Display display, Layer layer, uint32_t z); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 218 | |
| 219 | private: |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 220 | // Many public functions above simply write a command into the command |
| 221 | // queue to batch the calls. validateDisplay and presentDisplay will call |
| 222 | // this function to execute the command queue. |
| 223 | Error execute(); |
| 224 | |
| 225 | sp<IComposer> mComposer; |
| 226 | sp<IComposerClient> mClient; |
| 227 | |
| 228 | // 64KiB minus a small space for metadata such as read/write pointers |
| 229 | static constexpr size_t kWriterInitialSize = |
| 230 | 64 * 1024 / sizeof(uint32_t) - 16; |
Daniel Nicoara | 3c9cbd4 | 2017-01-17 12:04:06 -0500 | [diff] [blame^] | 231 | CommandWriterBase mWriter; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 232 | CommandReader mReader; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | } // namespace Hwc2 |
| 236 | |
| 237 | } // namespace android |
| 238 | |
| 239 | #endif // ANDROID_SF_COMPOSER_HAL_H |