Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +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 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 17 | #ifndef ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H |
| 18 | #define ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 19 | |
| 20 | #include <mutex> |
| 21 | #include <unordered_map> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include "Hwc.h" |
| 25 | #include "IComposerCommandBuffer.h" |
| 26 | |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace graphics { |
| 30 | namespace composer { |
| 31 | namespace V2_1 { |
| 32 | namespace implementation { |
| 33 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 34 | class BufferCacheEntry { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 35 | public: |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 36 | BufferCacheEntry(); |
| 37 | BufferCacheEntry(BufferCacheEntry&& other); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 38 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 39 | BufferCacheEntry(const BufferCacheEntry& other) = delete; |
| 40 | BufferCacheEntry& operator=(const BufferCacheEntry& other) = delete; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 41 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 42 | BufferCacheEntry& operator=(buffer_handle_t handle); |
| 43 | ~BufferCacheEntry(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 44 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 45 | buffer_handle_t getHandle() const { return mHandle; } |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | void clear(); |
| 49 | |
| 50 | buffer_handle_t mHandle; |
| 51 | }; |
| 52 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 53 | class ComposerClient : public IComposerClient { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 54 | public: |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 55 | ComposerClient(ComposerBase& hal); |
| 56 | virtual ~ComposerClient(); |
| 57 | |
| 58 | void initialize(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 59 | |
| 60 | void onHotplug(Display display, IComposerCallback::Connection connected); |
| 61 | void onRefresh(Display display); |
| 62 | void onVsync(Display display, int64_t timestamp); |
| 63 | |
| 64 | // IComposerClient interface |
| 65 | Return<void> registerCallback( |
| 66 | const sp<IComposerCallback>& callback) override; |
| 67 | Return<uint32_t> getMaxVirtualDisplayCount() override; |
| 68 | Return<void> createVirtualDisplay(uint32_t width, uint32_t height, |
| 69 | PixelFormat formatHint, uint32_t outputBufferSlotCount, |
| 70 | createVirtualDisplay_cb hidl_cb) override; |
| 71 | Return<Error> destroyVirtualDisplay(Display display) override; |
| 72 | Return<void> createLayer(Display display, uint32_t bufferSlotCount, |
| 73 | createLayer_cb hidl_cb) override; |
| 74 | Return<Error> destroyLayer(Display display, Layer layer) override; |
| 75 | Return<void> getActiveConfig(Display display, |
| 76 | getActiveConfig_cb hidl_cb) override; |
| 77 | Return<Error> getClientTargetSupport(Display display, |
| 78 | uint32_t width, uint32_t height, |
| 79 | PixelFormat format, Dataspace dataspace) override; |
| 80 | Return<void> getColorModes(Display display, |
| 81 | getColorModes_cb hidl_cb) override; |
| 82 | Return<void> getDisplayAttribute(Display display, |
| 83 | Config config, Attribute attribute, |
| 84 | getDisplayAttribute_cb hidl_cb) override; |
| 85 | Return<void> getDisplayConfigs(Display display, |
| 86 | getDisplayConfigs_cb hidl_cb) override; |
| 87 | Return<void> getDisplayName(Display display, |
| 88 | getDisplayName_cb hidl_cb) override; |
| 89 | Return<void> getDisplayType(Display display, |
| 90 | getDisplayType_cb hidl_cb) override; |
| 91 | Return<void> getDozeSupport(Display display, |
| 92 | getDozeSupport_cb hidl_cb) override; |
| 93 | Return<void> getHdrCapabilities(Display display, |
| 94 | getHdrCapabilities_cb hidl_cb) override; |
| 95 | Return<Error> setActiveConfig(Display display, Config config) override; |
| 96 | Return<Error> setColorMode(Display display, ColorMode mode) override; |
| 97 | Return<Error> setPowerMode(Display display, PowerMode mode) override; |
| 98 | Return<Error> setVsyncEnabled(Display display, Vsync enabled) override; |
| 99 | Return<Error> setClientTargetSlotCount(Display display, |
| 100 | uint32_t clientTargetSlotCount) override; |
| 101 | Return<Error> setInputCommandQueue( |
Hridya Valsaraju | 33351da | 2016-12-27 12:40:01 -0800 | [diff] [blame] | 102 | const MQDescriptorSync<uint32_t>& descriptor) override; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 103 | Return<void> getOutputCommandQueue( |
| 104 | getOutputCommandQueue_cb hidl_cb) override; |
| 105 | Return<void> executeCommands(uint32_t inLength, |
| 106 | const hidl_vec<hidl_handle>& inHandles, |
| 107 | executeCommands_cb hidl_cb) override; |
| 108 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 109 | protected: |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 110 | struct LayerBuffers { |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 111 | std::vector<BufferCacheEntry> Buffers; |
| 112 | BufferCacheEntry SidebandStream; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct DisplayData { |
| 116 | bool IsVirtual; |
| 117 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 118 | std::vector<BufferCacheEntry> ClientTargets; |
| 119 | std::vector<BufferCacheEntry> OutputBuffers; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 120 | |
| 121 | std::unordered_map<Layer, LayerBuffers> Layers; |
| 122 | |
| 123 | DisplayData(bool isVirtual) : IsVirtual(isVirtual) {} |
| 124 | }; |
| 125 | |
| 126 | class CommandReader : public CommandReaderBase { |
| 127 | public: |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 128 | CommandReader(ComposerClient& client); |
| 129 | virtual ~CommandReader(); |
| 130 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 131 | Error parse(); |
| 132 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 133 | protected: |
| 134 | virtual bool parseCommand(IComposerClient::Command command, |
| 135 | uint16_t length); |
| 136 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 137 | bool parseSelectDisplay(uint16_t length); |
| 138 | bool parseSelectLayer(uint16_t length); |
| 139 | bool parseSetColorTransform(uint16_t length); |
| 140 | bool parseSetClientTarget(uint16_t length); |
| 141 | bool parseSetOutputBuffer(uint16_t length); |
| 142 | bool parseValidateDisplay(uint16_t length); |
| 143 | bool parseAcceptDisplayChanges(uint16_t length); |
| 144 | bool parsePresentDisplay(uint16_t length); |
| 145 | bool parseSetLayerCursorPosition(uint16_t length); |
| 146 | bool parseSetLayerBuffer(uint16_t length); |
| 147 | bool parseSetLayerSurfaceDamage(uint16_t length); |
| 148 | bool parseSetLayerBlendMode(uint16_t length); |
| 149 | bool parseSetLayerColor(uint16_t length); |
| 150 | bool parseSetLayerCompositionType(uint16_t length); |
| 151 | bool parseSetLayerDataspace(uint16_t length); |
| 152 | bool parseSetLayerDisplayFrame(uint16_t length); |
| 153 | bool parseSetLayerPlaneAlpha(uint16_t length); |
| 154 | bool parseSetLayerSidebandStream(uint16_t length); |
| 155 | bool parseSetLayerSourceCrop(uint16_t length); |
| 156 | bool parseSetLayerTransform(uint16_t length); |
| 157 | bool parseSetLayerVisibleRegion(uint16_t length); |
| 158 | bool parseSetLayerZOrder(uint16_t length); |
| 159 | |
| 160 | hwc_rect_t readRect(); |
| 161 | std::vector<hwc_rect_t> readRegion(size_t count); |
| 162 | hwc_frect_t readFRect(); |
| 163 | |
| 164 | enum class BufferCache { |
| 165 | CLIENT_TARGETS, |
| 166 | OUTPUT_BUFFERS, |
| 167 | LAYER_BUFFERS, |
| 168 | LAYER_SIDEBAND_STREAMS, |
| 169 | }; |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 170 | Error lookupBufferCacheEntryLocked(BufferCache cache, uint32_t slot, |
| 171 | BufferCacheEntry** outEntry); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 172 | Error lookupBuffer(BufferCache cache, uint32_t slot, |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 173 | bool useCache, buffer_handle_t handle, |
| 174 | buffer_handle_t* outHandle); |
| 175 | void updateBuffer(BufferCache cache, uint32_t slot, |
| 176 | bool useCache, buffer_handle_t handle); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 177 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 178 | Error lookupLayerSidebandStream(buffer_handle_t handle, |
| 179 | buffer_handle_t* outHandle) |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 180 | { |
| 181 | return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS, |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 182 | 0, false, handle, outHandle); |
| 183 | } |
| 184 | void updateLayerSidebandStream(buffer_handle_t handle) |
| 185 | { |
| 186 | updateBuffer(BufferCache::LAYER_SIDEBAND_STREAMS, |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 187 | 0, false, handle); |
| 188 | } |
| 189 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 190 | ComposerClient& mClient; |
| 191 | ComposerBase& mHal; |
Daniel Nicoara | bd82b81 | 2017-01-17 11:15:26 -0500 | [diff] [blame] | 192 | CommandWriterBase& mWriter; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 193 | |
| 194 | Display mDisplay; |
| 195 | Layer mLayer; |
| 196 | }; |
| 197 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 198 | virtual std::unique_ptr<CommandReader> createCommandReader(); |
| 199 | |
| 200 | ComposerBase& mHal; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 201 | |
| 202 | // 64KiB minus a small space for metadata such as read/write pointers |
| 203 | static constexpr size_t kWriterInitialSize = |
| 204 | 64 * 1024 / sizeof(uint32_t) - 16; |
| 205 | std::mutex mCommandMutex; |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 206 | std::unique_ptr<CommandReader> mReader; |
Daniel Nicoara | bd82b81 | 2017-01-17 11:15:26 -0500 | [diff] [blame] | 207 | CommandWriterBase mWriter; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 208 | |
| 209 | sp<IComposerCallback> mCallback; |
| 210 | |
| 211 | std::mutex mDisplayDataMutex; |
| 212 | std::unordered_map<Display, DisplayData> mDisplayData; |
| 213 | }; |
| 214 | |
| 215 | } // namespace implementation |
| 216 | } // namespace V2_1 |
| 217 | } // namespace composer |
| 218 | } // namespace graphics |
| 219 | } // namespace hardware |
| 220 | } // namespace android |
| 221 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 222 | #endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H |