Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [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 | 95a99a1 | 2017-03-21 15:30:45 -0400 | [diff] [blame] | 17 | #include <android/frameworks/vr/composer/1.0/IVrComposerClient.h> |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 18 | #include <hardware/gralloc.h> |
| 19 | #include <hardware/gralloc1.h> |
| 20 | #include <log/log.h> |
| 21 | |
Daniel Nicoara | 4251e92 | 2017-04-13 15:19:15 -0400 | [diff] [blame] | 22 | #include "impl/vr_hwc.h" |
| 23 | #include "impl/vr_composer_client.h" |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace dvr { |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 27 | namespace { |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 28 | |
| 29 | using android::hardware::graphics::common::V1_0::PixelFormat; |
Daniel Nicoara | 95a99a1 | 2017-03-21 15:30:45 -0400 | [diff] [blame] | 30 | using android::frameworks::vr::composer::V1_0::IVrComposerClient; |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 31 | |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 32 | class ComposerClientImpl : public ComposerClient { |
| 33 | public: |
| 34 | ComposerClientImpl(android::dvr::VrHwc& hal); |
| 35 | virtual ~ComposerClientImpl(); |
| 36 | |
| 37 | private: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 38 | class VrCommandEngine : public ComposerCommandEngine { |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 39 | public: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 40 | VrCommandEngine(ComposerClientImpl& client); |
| 41 | ~VrCommandEngine() override; |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 42 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 43 | bool executeCommand(IComposerClient::Command command, |
| 44 | uint16_t length) override; |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 45 | |
| 46 | private: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 47 | bool executeSetLayerInfo(uint16_t length); |
| 48 | bool executeSetClientTargetMetadata(uint16_t length); |
| 49 | bool executeSetLayerBufferMetadata(uint16_t length); |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 50 | |
| 51 | IVrComposerClient::BufferMetadata readBufferMetadata(); |
| 52 | |
| 53 | ComposerClientImpl& mVrClient; |
| 54 | android::dvr::VrHwc& mVrHal; |
| 55 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 56 | VrCommandEngine(const VrCommandEngine&) = delete; |
| 57 | void operator=(const VrCommandEngine&) = delete; |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 58 | }; |
| 59 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 60 | std::unique_ptr<ComposerCommandEngine> createCommandEngine() override; |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 61 | |
| 62 | dvr::VrHwc& mVrHal; |
| 63 | |
| 64 | ComposerClientImpl(const ComposerClientImpl&) = delete; |
| 65 | void operator=(const ComposerClientImpl&) = delete; |
| 66 | }; |
| 67 | |
| 68 | ComposerClientImpl::ComposerClientImpl(android::dvr::VrHwc& hal) |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 69 | : ComposerClient(hal), mVrHal(hal) {} |
| 70 | |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 71 | ComposerClientImpl::~ComposerClientImpl() {} |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 72 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 73 | std::unique_ptr<ComposerCommandEngine> |
| 74 | ComposerClientImpl::createCommandEngine() { |
| 75 | return std::unique_ptr<VrCommandEngine>(new VrCommandEngine(*this)); |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 78 | ComposerClientImpl::VrCommandEngine::VrCommandEngine(ComposerClientImpl& client) |
| 79 | : ComposerCommandEngine(&client.mHal, client.mResources.get()), mVrClient(client), |
| 80 | mVrHal(client.mVrHal) {} |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 81 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 82 | ComposerClientImpl::VrCommandEngine::~VrCommandEngine() {} |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 83 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 84 | bool ComposerClientImpl::VrCommandEngine::executeCommand( |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 85 | IComposerClient::Command command, uint16_t length) { |
| 86 | IVrComposerClient::VrCommand vrCommand = |
| 87 | static_cast<IVrComposerClient::VrCommand>(command); |
| 88 | switch (vrCommand) { |
| 89 | case IVrComposerClient::VrCommand::SET_LAYER_INFO: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 90 | return executeSetLayerInfo(length); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 91 | case IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 92 | return executeSetClientTargetMetadata(length); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 93 | case IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 94 | return executeSetLayerBufferMetadata(length); |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 95 | default: |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 96 | return ComposerCommandEngine::executeCommand(command, length); |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 100 | bool ComposerClientImpl::VrCommandEngine::executeSetLayerInfo(uint16_t length) { |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 101 | if (length != 2) { |
| 102 | return false; |
| 103 | } |
| 104 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 105 | auto err = mVrHal.setLayerInfo(mCurrentDisplay, mCurrentLayer, read(), read()); |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 106 | if (err != Error::NONE) { |
| 107 | mWriter.setError(getCommandLoc(), err); |
| 108 | } |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 113 | bool ComposerClientImpl::VrCommandEngine::executeSetClientTargetMetadata( |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 114 | uint16_t length) { |
| 115 | if (length != 7) |
| 116 | return false; |
| 117 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 118 | auto err = mVrHal.setClientTargetMetadata(mCurrentDisplay, readBufferMetadata()); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 119 | if (err != Error::NONE) |
| 120 | mWriter.setError(getCommandLoc(), err); |
| 121 | |
| 122 | return true; |
| 123 | } |
| 124 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 125 | bool ComposerClientImpl::VrCommandEngine::executeSetLayerBufferMetadata( |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 126 | uint16_t length) { |
| 127 | if (length != 7) |
| 128 | return false; |
| 129 | |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 130 | auto err = mVrHal.setLayerBufferMetadata(mCurrentDisplay, mCurrentLayer, |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 131 | readBufferMetadata()); |
| 132 | if (err != Error::NONE) |
| 133 | mWriter.setError(getCommandLoc(), err); |
| 134 | |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | IVrComposerClient::BufferMetadata |
Chia-I Wu | 69f8fb7 | 2018-01-30 12:39:00 -0800 | [diff] [blame^] | 139 | ComposerClientImpl::VrCommandEngine::readBufferMetadata() { |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 140 | IVrComposerClient::BufferMetadata metadata = { |
| 141 | .width = read(), |
| 142 | .height = read(), |
| 143 | .stride = read(), |
| 144 | .layerCount = read(), |
| 145 | .format = static_cast<PixelFormat>(readSigned()), |
| 146 | .usage = read64(), |
| 147 | }; |
| 148 | return metadata; |
| 149 | } |
| 150 | |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 151 | } // namespace |
| 152 | |
| 153 | VrComposerClient::VrComposerClient(dvr::VrHwc& hal) |
| 154 | : client_(new ComposerClientImpl(hal)) { |
| 155 | client_->initialize(); |
| 156 | } |
| 157 | |
| 158 | VrComposerClient::~VrComposerClient() {} |
| 159 | |
| 160 | void VrComposerClient::onHotplug(Display display, |
| 161 | IComposerCallback::Connection connected) { |
| 162 | client_->onHotplug(display, connected); |
| 163 | } |
| 164 | |
Daniel Nicoara | 8fc9822 | 2017-08-09 18:10:44 -0400 | [diff] [blame] | 165 | void VrComposerClient::onRefresh(Display display) { |
| 166 | client_->onRefresh(display); |
| 167 | } |
| 168 | |
Daniel Nicoara | a50abc2 | 2017-05-15 10:34:08 -0400 | [diff] [blame] | 169 | Return<void> VrComposerClient::registerCallback( |
| 170 | const sp<IComposerCallback>& callback) { |
| 171 | return client_->registerCallback(callback); |
| 172 | } |
| 173 | |
| 174 | Return<uint32_t> VrComposerClient::getMaxVirtualDisplayCount() { |
| 175 | return client_->getMaxVirtualDisplayCount(); |
| 176 | } |
| 177 | |
| 178 | Return<void> VrComposerClient::createVirtualDisplay(uint32_t width, |
| 179 | uint32_t height, PixelFormat formatHint, uint32_t outputBufferSlotCount, |
| 180 | createVirtualDisplay_cb hidl_cb) { |
| 181 | return client_->createVirtualDisplay( |
| 182 | width, height, formatHint, outputBufferSlotCount, hidl_cb); |
| 183 | } |
| 184 | |
| 185 | Return<Error> VrComposerClient::destroyVirtualDisplay(Display display) { |
| 186 | return client_->destroyVirtualDisplay(display); |
| 187 | } |
| 188 | |
| 189 | Return<void> VrComposerClient::createLayer(Display display, |
| 190 | uint32_t bufferSlotCount, createLayer_cb hidl_cb) { |
| 191 | return client_->createLayer(display, bufferSlotCount, hidl_cb); |
| 192 | } |
| 193 | |
| 194 | Return<Error> VrComposerClient::destroyLayer(Display display, Layer layer) { |
| 195 | return client_->destroyLayer(display, layer); |
| 196 | } |
| 197 | |
| 198 | Return<void> VrComposerClient::getActiveConfig(Display display, |
| 199 | getActiveConfig_cb hidl_cb) { |
| 200 | return client_->getActiveConfig(display, hidl_cb); |
| 201 | } |
| 202 | |
| 203 | Return<Error> VrComposerClient::getClientTargetSupport(Display display, |
| 204 | uint32_t width, uint32_t height, PixelFormat format, Dataspace dataspace) { |
| 205 | return client_->getClientTargetSupport(display, width, height, format, |
| 206 | dataspace); |
| 207 | } |
| 208 | |
| 209 | Return<void> VrComposerClient::getColorModes(Display display, |
| 210 | getColorModes_cb hidl_cb) { |
| 211 | return client_->getColorModes(display, hidl_cb); |
| 212 | } |
| 213 | |
| 214 | Return<void> VrComposerClient::getDisplayAttribute(Display display, |
| 215 | Config config, Attribute attribute, getDisplayAttribute_cb hidl_cb) { |
| 216 | return client_->getDisplayAttribute(display, config, attribute, hidl_cb); |
| 217 | } |
| 218 | |
| 219 | Return<void> VrComposerClient::getDisplayConfigs(Display display, |
| 220 | getDisplayConfigs_cb hidl_cb) { |
| 221 | return client_->getDisplayConfigs(display, hidl_cb); |
| 222 | } |
| 223 | |
| 224 | Return<void> VrComposerClient::getDisplayName(Display display, |
| 225 | getDisplayName_cb hidl_cb) { |
| 226 | return client_->getDisplayName(display, hidl_cb); |
| 227 | } |
| 228 | |
| 229 | Return<void> VrComposerClient::getDisplayType(Display display, |
| 230 | getDisplayType_cb hidl_cb) { |
| 231 | return client_->getDisplayType(display, hidl_cb); |
| 232 | } |
| 233 | |
| 234 | Return<void> VrComposerClient::getDozeSupport( |
| 235 | Display display, getDozeSupport_cb hidl_cb) { |
| 236 | return client_->getDozeSupport(display, hidl_cb); |
| 237 | } |
| 238 | |
| 239 | Return<void> VrComposerClient::getHdrCapabilities( |
| 240 | Display display, getHdrCapabilities_cb hidl_cb) { |
| 241 | return client_->getHdrCapabilities(display, hidl_cb); |
| 242 | } |
| 243 | |
| 244 | Return<Error> VrComposerClient::setActiveConfig(Display display, |
| 245 | Config config) { |
| 246 | return client_->setActiveConfig(display, config); |
| 247 | } |
| 248 | |
| 249 | Return<Error> VrComposerClient::setColorMode(Display display, ColorMode mode) { |
| 250 | return client_->setColorMode(display, mode); |
| 251 | } |
| 252 | |
| 253 | Return<Error> VrComposerClient::setPowerMode(Display display, PowerMode mode) { |
| 254 | return client_->setPowerMode(display, mode); |
| 255 | } |
| 256 | |
| 257 | Return<Error> VrComposerClient::setVsyncEnabled(Display display, |
| 258 | Vsync enabled) { |
| 259 | return client_->setVsyncEnabled(display, enabled); |
| 260 | } |
| 261 | |
| 262 | Return<Error> VrComposerClient::setClientTargetSlotCount( |
| 263 | Display display, uint32_t clientTargetSlotCount) { |
| 264 | return client_->setClientTargetSlotCount(display, clientTargetSlotCount); |
| 265 | } |
| 266 | |
| 267 | Return<Error> VrComposerClient::setInputCommandQueue( |
| 268 | const hardware::MQDescriptorSync<uint32_t>& descriptor) { |
| 269 | return client_->setInputCommandQueue(descriptor); |
| 270 | } |
| 271 | |
| 272 | Return<void> VrComposerClient::getOutputCommandQueue( |
| 273 | getOutputCommandQueue_cb hidl_cb) { |
| 274 | return client_->getOutputCommandQueue(hidl_cb); |
| 275 | } |
| 276 | |
| 277 | Return<void> VrComposerClient::executeCommands(uint32_t inLength, |
| 278 | const hidl_vec<hidl_handle>& inHandles, executeCommands_cb hidl_cb) { |
| 279 | return client_->executeCommands(inLength, inHandles, hidl_cb); |
| 280 | } |
| 281 | |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 282 | } // namespace dvr |
| 283 | } // namespace android |