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; |
Chia-I Wu | ae00f5c | 2017-07-17 10:32:15 -0700 | [diff] [blame] | 113 | // the handle is a sideband stream handle, not a buffer handle |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 114 | BufferCacheEntry SidebandStream; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | struct DisplayData { |
| 118 | bool IsVirtual; |
| 119 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 120 | std::vector<BufferCacheEntry> ClientTargets; |
| 121 | std::vector<BufferCacheEntry> OutputBuffers; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 122 | |
| 123 | std::unordered_map<Layer, LayerBuffers> Layers; |
| 124 | |
| 125 | DisplayData(bool isVirtual) : IsVirtual(isVirtual) {} |
| 126 | }; |
| 127 | |
| 128 | class CommandReader : public CommandReaderBase { |
| 129 | public: |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 130 | CommandReader(ComposerClient& client); |
| 131 | virtual ~CommandReader(); |
| 132 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 133 | Error parse(); |
| 134 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 135 | protected: |
| 136 | virtual bool parseCommand(IComposerClient::Command command, |
| 137 | uint16_t length); |
| 138 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 139 | bool parseSelectDisplay(uint16_t length); |
| 140 | bool parseSelectLayer(uint16_t length); |
| 141 | bool parseSetColorTransform(uint16_t length); |
| 142 | bool parseSetClientTarget(uint16_t length); |
| 143 | bool parseSetOutputBuffer(uint16_t length); |
| 144 | bool parseValidateDisplay(uint16_t length); |
Fabien Sanglard | 11ec393 | 2017-06-19 19:25:31 -0700 | [diff] [blame] | 145 | bool parsePresentOrValidateDisplay(uint16_t length); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 146 | bool parseAcceptDisplayChanges(uint16_t length); |
| 147 | bool parsePresentDisplay(uint16_t length); |
| 148 | bool parseSetLayerCursorPosition(uint16_t length); |
| 149 | bool parseSetLayerBuffer(uint16_t length); |
| 150 | bool parseSetLayerSurfaceDamage(uint16_t length); |
| 151 | bool parseSetLayerBlendMode(uint16_t length); |
| 152 | bool parseSetLayerColor(uint16_t length); |
| 153 | bool parseSetLayerCompositionType(uint16_t length); |
| 154 | bool parseSetLayerDataspace(uint16_t length); |
| 155 | bool parseSetLayerDisplayFrame(uint16_t length); |
| 156 | bool parseSetLayerPlaneAlpha(uint16_t length); |
| 157 | bool parseSetLayerSidebandStream(uint16_t length); |
| 158 | bool parseSetLayerSourceCrop(uint16_t length); |
| 159 | bool parseSetLayerTransform(uint16_t length); |
| 160 | bool parseSetLayerVisibleRegion(uint16_t length); |
| 161 | bool parseSetLayerZOrder(uint16_t length); |
| 162 | |
| 163 | hwc_rect_t readRect(); |
| 164 | std::vector<hwc_rect_t> readRegion(size_t count); |
| 165 | hwc_frect_t readFRect(); |
| 166 | |
| 167 | enum class BufferCache { |
| 168 | CLIENT_TARGETS, |
| 169 | OUTPUT_BUFFERS, |
| 170 | LAYER_BUFFERS, |
| 171 | LAYER_SIDEBAND_STREAMS, |
| 172 | }; |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 173 | Error lookupBufferCacheEntryLocked(BufferCache cache, uint32_t slot, |
| 174 | BufferCacheEntry** outEntry); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 175 | Error lookupBuffer(BufferCache cache, uint32_t slot, |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 176 | bool useCache, buffer_handle_t handle, |
| 177 | buffer_handle_t* outHandle); |
Steven Thomas | 58da77e | 2017-04-26 15:24:28 -0700 | [diff] [blame] | 178 | Error updateBuffer(BufferCache cache, uint32_t slot, |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 179 | bool useCache, buffer_handle_t handle); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 180 | |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 181 | Error lookupLayerSidebandStream(buffer_handle_t handle, |
| 182 | buffer_handle_t* outHandle) |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 183 | { |
| 184 | return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS, |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 185 | 0, false, handle, outHandle); |
| 186 | } |
Steven Thomas | 58da77e | 2017-04-26 15:24:28 -0700 | [diff] [blame] | 187 | Error updateLayerSidebandStream(buffer_handle_t handle) |
Chia-I Wu | 41a1c15 | 2017-03-09 15:41:59 -0800 | [diff] [blame] | 188 | { |
Steven Thomas | 58da77e | 2017-04-26 15:24:28 -0700 | [diff] [blame] | 189 | return updateBuffer(BufferCache::LAYER_SIDEBAND_STREAMS, |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 190 | 0, false, handle); |
| 191 | } |
| 192 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 193 | ComposerClient& mClient; |
| 194 | ComposerBase& mHal; |
Daniel Nicoara | bd82b81 | 2017-01-17 11:15:26 -0500 | [diff] [blame] | 195 | CommandWriterBase& mWriter; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 196 | |
| 197 | Display mDisplay; |
| 198 | Layer mLayer; |
| 199 | }; |
| 200 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 201 | virtual std::unique_ptr<CommandReader> createCommandReader(); |
| 202 | |
| 203 | ComposerBase& mHal; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 204 | |
| 205 | // 64KiB minus a small space for metadata such as read/write pointers |
| 206 | static constexpr size_t kWriterInitialSize = |
| 207 | 64 * 1024 / sizeof(uint32_t) - 16; |
| 208 | std::mutex mCommandMutex; |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 209 | std::unique_ptr<CommandReader> mReader; |
Daniel Nicoara | bd82b81 | 2017-01-17 11:15:26 -0500 | [diff] [blame] | 210 | CommandWriterBase mWriter; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 211 | |
| 212 | sp<IComposerCallback> mCallback; |
| 213 | |
| 214 | std::mutex mDisplayDataMutex; |
| 215 | std::unordered_map<Display, DisplayData> mDisplayData; |
| 216 | }; |
| 217 | |
| 218 | } // namespace implementation |
| 219 | } // namespace V2_1 |
| 220 | } // namespace composer |
| 221 | } // namespace graphics |
| 222 | } // namespace hardware |
| 223 | } // namespace android |
| 224 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 225 | #endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H |