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