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