Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +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 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "HwcComposer" |
| 19 | |
| 20 | #include <inttypes.h> |
| 21 | #include <log/log.h> |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 22 | #include <gui/BufferQueue.h> |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 23 | |
| 24 | #include "ComposerHal.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | using hardware::Return; |
| 29 | using hardware::hidl_vec; |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 30 | using hardware::hidl_handle; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 31 | |
| 32 | namespace Hwc2 { |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | class BufferHandle { |
| 37 | public: |
| 38 | BufferHandle(const native_handle_t* buffer) |
| 39 | { |
| 40 | // nullptr is not a valid handle to HIDL |
| 41 | mHandle = (buffer) ? buffer : native_handle_init(mStorage, 0, 0); |
| 42 | } |
| 43 | |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 44 | operator const hidl_handle&() const |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 45 | { |
| 46 | return mHandle; |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 0, 0); |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 51 | hidl_handle mHandle; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | class FenceHandle |
| 55 | { |
| 56 | public: |
| 57 | FenceHandle(int fd, bool owned) |
| 58 | : mOwned(owned) |
| 59 | { |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 60 | native_handle_t* handle; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 61 | if (fd >= 0) { |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 62 | handle = native_handle_init(mStorage, 1, 0); |
| 63 | handle->data[0] = fd; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 64 | } else { |
| 65 | // nullptr is not a valid handle to HIDL |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 66 | handle = native_handle_init(mStorage, 0, 0); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 67 | } |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 68 | mHandle = handle; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | ~FenceHandle() |
| 72 | { |
| 73 | if (mOwned) { |
| 74 | native_handle_close(mHandle); |
| 75 | } |
| 76 | } |
| 77 | |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 78 | operator const hidl_handle&() const |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 79 | { |
| 80 | return mHandle; |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | bool mOwned; |
| 85 | NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 1, 0); |
Martijn Coenen | 7c5a92f | 2016-11-21 10:01:07 +0100 | [diff] [blame] | 86 | hidl_handle mHandle; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | // assume NO_RESOURCES when Status::isOk returns false |
| 90 | constexpr Error kDefaultError = Error::NO_RESOURCES; |
| 91 | |
| 92 | template<typename T, typename U> |
| 93 | T unwrapRet(Return<T>& ret, const U& default_val) |
| 94 | { |
Steven Moreland | 9d02100 | 2017-01-03 17:10:54 -0800 | [diff] [blame] | 95 | return (ret.isOk()) ? static_cast<T>(ret) : |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 96 | static_cast<T>(default_val); |
| 97 | } |
| 98 | |
| 99 | Error unwrapRet(Return<Error>& ret) |
| 100 | { |
| 101 | return unwrapRet(ret, kDefaultError); |
| 102 | } |
| 103 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 104 | } // anonymous namespace |
| 105 | |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 106 | Composer::CommandWriter::CommandWriter(uint32_t initialMaxSize) |
| 107 | : CommandWriterBase(initialMaxSize) {} |
| 108 | |
| 109 | Composer::CommandWriter::~CommandWriter() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 110 | { |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void Composer::CommandWriter::setLayerInfo(uint32_t type, uint32_t appId) |
| 114 | { |
| 115 | constexpr uint16_t kSetLayerInfoLength = 2; |
| 116 | beginCommand( |
| 117 | static_cast<IComposerClient::Command>( |
| 118 | IVrComposerClient::VrCommand::SET_LAYER_INFO), |
| 119 | kSetLayerInfoLength); |
| 120 | write(type); |
| 121 | write(appId); |
| 122 | endCommand(); |
| 123 | } |
| 124 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 125 | void Composer::CommandWriter::setClientTargetMetadata( |
| 126 | const IVrComposerClient::BufferMetadata& metadata) |
| 127 | { |
| 128 | constexpr uint16_t kSetClientTargetMetadataLength = 7; |
| 129 | beginCommand( |
| 130 | static_cast<IComposerClient::Command>( |
| 131 | IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA), |
| 132 | kSetClientTargetMetadataLength); |
| 133 | writeBufferMetadata(metadata); |
| 134 | endCommand(); |
| 135 | } |
| 136 | |
| 137 | void Composer::CommandWriter::setLayerBufferMetadata( |
| 138 | const IVrComposerClient::BufferMetadata& metadata) |
| 139 | { |
| 140 | constexpr uint16_t kSetLayerBufferMetadataLength = 7; |
| 141 | beginCommand( |
| 142 | static_cast<IComposerClient::Command>( |
| 143 | IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA), |
| 144 | kSetLayerBufferMetadataLength); |
| 145 | writeBufferMetadata(metadata); |
| 146 | endCommand(); |
| 147 | } |
| 148 | |
| 149 | void Composer::CommandWriter::writeBufferMetadata( |
| 150 | const IVrComposerClient::BufferMetadata& metadata) |
| 151 | { |
| 152 | write(metadata.width); |
| 153 | write(metadata.height); |
| 154 | write(metadata.stride); |
| 155 | write(metadata.layerCount); |
| 156 | writeSigned(static_cast<int32_t>(metadata.format)); |
| 157 | write64(metadata.usage); |
| 158 | } |
| 159 | |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 160 | Composer::Composer(bool useVrComposer) |
| 161 | : mWriter(kWriterInitialSize), |
| 162 | mIsUsingVrComposer(useVrComposer) |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 163 | { |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 164 | if (mIsUsingVrComposer) { |
Daniel Nicoara | e96afe6 | 2017-03-24 15:15:50 -0400 | [diff] [blame] | 165 | mComposer = IComposer::getService("vr"); |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 166 | } else { |
Chris Phoenix | f5eb5e6 | 2017-01-24 14:08:33 -0800 | [diff] [blame] | 167 | mComposer = IComposer::getService(); // use default name |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 170 | if (mComposer == nullptr) { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 171 | LOG_ALWAYS_FATAL("failed to get hwcomposer service"); |
| 172 | } |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 173 | |
| 174 | mComposer->createClient( |
| 175 | [&](const auto& tmpError, const auto& tmpClient) |
| 176 | { |
| 177 | if (tmpError == Error::NONE) { |
| 178 | mClient = tmpClient; |
| 179 | } |
| 180 | }); |
| 181 | if (mClient == nullptr) { |
| 182 | LOG_ALWAYS_FATAL("failed to create composer client"); |
| 183 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 186 | std::vector<IComposer::Capability> Composer::getCapabilities() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 187 | { |
| 188 | std::vector<IComposer::Capability> capabilities; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 189 | mComposer->getCapabilities( |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 190 | [&](const auto& tmpCapabilities) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 191 | capabilities = tmpCapabilities; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 192 | }); |
| 193 | |
| 194 | return capabilities; |
| 195 | } |
| 196 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 197 | std::string Composer::dumpDebugInfo() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 198 | { |
| 199 | std::string info; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 200 | mComposer->dumpDebugInfo([&](const auto& tmpInfo) { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 201 | info = tmpInfo.c_str(); |
| 202 | }); |
| 203 | |
| 204 | return info; |
| 205 | } |
| 206 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 207 | void Composer::registerCallback(const sp<IComposerCallback>& callback) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 208 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 209 | auto ret = mClient->registerCallback(callback); |
Steven Moreland | 9d02100 | 2017-01-03 17:10:54 -0800 | [diff] [blame] | 210 | if (!ret.isOk()) { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 211 | ALOGE("failed to register IComposerCallback"); |
| 212 | } |
| 213 | } |
| 214 | |
Steven Thomas | 0af4b9f | 2017-04-26 14:34:01 -0700 | [diff] [blame] | 215 | void Composer::resetCommands() { |
| 216 | mWriter.reset(); |
| 217 | } |
| 218 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 219 | uint32_t Composer::getMaxVirtualDisplayCount() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 220 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 221 | auto ret = mClient->getMaxVirtualDisplayCount(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 222 | return unwrapRet(ret, 0); |
| 223 | } |
| 224 | |
| 225 | Error Composer::createVirtualDisplay(uint32_t width, uint32_t height, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 226 | PixelFormat* format, Display* outDisplay) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 227 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 228 | const uint32_t bufferSlotCount = 1; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 229 | Error error = kDefaultError; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 230 | mClient->createVirtualDisplay(width, height, *format, bufferSlotCount, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 231 | [&](const auto& tmpError, const auto& tmpDisplay, |
| 232 | const auto& tmpFormat) { |
| 233 | error = tmpError; |
| 234 | if (error != Error::NONE) { |
| 235 | return; |
| 236 | } |
| 237 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 238 | *outDisplay = tmpDisplay; |
| 239 | *format = tmpFormat; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 240 | }); |
| 241 | |
| 242 | return error; |
| 243 | } |
| 244 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 245 | Error Composer::destroyVirtualDisplay(Display display) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 246 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 247 | auto ret = mClient->destroyVirtualDisplay(display); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 248 | return unwrapRet(ret); |
| 249 | } |
| 250 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 251 | Error Composer::acceptDisplayChanges(Display display) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 252 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 253 | mWriter.selectDisplay(display); |
| 254 | mWriter.acceptDisplayChanges(); |
| 255 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 256 | } |
| 257 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 258 | Error Composer::createLayer(Display display, Layer* outLayer) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 259 | { |
| 260 | Error error = kDefaultError; |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 261 | mClient->createLayer(display, BufferQueue::NUM_BUFFER_SLOTS, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 262 | [&](const auto& tmpError, const auto& tmpLayer) { |
| 263 | error = tmpError; |
| 264 | if (error != Error::NONE) { |
| 265 | return; |
| 266 | } |
| 267 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 268 | *outLayer = tmpLayer; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 269 | }); |
| 270 | |
| 271 | return error; |
| 272 | } |
| 273 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 274 | Error Composer::destroyLayer(Display display, Layer layer) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 275 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 276 | auto ret = mClient->destroyLayer(display, layer); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 277 | return unwrapRet(ret); |
| 278 | } |
| 279 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 280 | Error Composer::getActiveConfig(Display display, Config* outConfig) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 281 | { |
| 282 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 283 | mClient->getActiveConfig(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 284 | [&](const auto& tmpError, const auto& tmpConfig) { |
| 285 | error = tmpError; |
| 286 | if (error != Error::NONE) { |
| 287 | return; |
| 288 | } |
| 289 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 290 | *outConfig = tmpConfig; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 291 | }); |
| 292 | |
| 293 | return error; |
| 294 | } |
| 295 | |
| 296 | Error Composer::getChangedCompositionTypes(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 297 | std::vector<Layer>* outLayers, |
| 298 | std::vector<IComposerClient::Composition>* outTypes) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 299 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 300 | mReader.takeChangedCompositionTypes(display, outLayers, outTypes); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 301 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | Error Composer::getColorModes(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 305 | std::vector<ColorMode>* outModes) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 306 | { |
| 307 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 308 | mClient->getColorModes(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 309 | [&](const auto& tmpError, const auto& tmpModes) { |
| 310 | error = tmpError; |
| 311 | if (error != Error::NONE) { |
| 312 | return; |
| 313 | } |
| 314 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 315 | *outModes = tmpModes; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 316 | }); |
| 317 | |
| 318 | return error; |
| 319 | } |
| 320 | |
| 321 | Error Composer::getDisplayAttribute(Display display, Config config, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 322 | IComposerClient::Attribute attribute, int32_t* outValue) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 323 | { |
| 324 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 325 | mClient->getDisplayAttribute(display, config, attribute, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 326 | [&](const auto& tmpError, const auto& tmpValue) { |
| 327 | error = tmpError; |
| 328 | if (error != Error::NONE) { |
| 329 | return; |
| 330 | } |
| 331 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 332 | *outValue = tmpValue; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 333 | }); |
| 334 | |
| 335 | return error; |
| 336 | } |
| 337 | |
| 338 | Error Composer::getDisplayConfigs(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 339 | std::vector<Config>* outConfigs) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 340 | { |
| 341 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 342 | mClient->getDisplayConfigs(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 343 | [&](const auto& tmpError, const auto& tmpConfigs) { |
| 344 | error = tmpError; |
| 345 | if (error != Error::NONE) { |
| 346 | return; |
| 347 | } |
| 348 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 349 | *outConfigs = tmpConfigs; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 350 | }); |
| 351 | |
| 352 | return error; |
| 353 | } |
| 354 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 355 | Error Composer::getDisplayName(Display display, std::string* outName) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 356 | { |
| 357 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 358 | mClient->getDisplayName(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 359 | [&](const auto& tmpError, const auto& tmpName) { |
| 360 | error = tmpError; |
| 361 | if (error != Error::NONE) { |
| 362 | return; |
| 363 | } |
| 364 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 365 | *outName = tmpName.c_str(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 366 | }); |
| 367 | |
| 368 | return error; |
| 369 | } |
| 370 | |
| 371 | Error Composer::getDisplayRequests(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 372 | uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers, |
| 373 | std::vector<uint32_t>* outLayerRequestMasks) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 374 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 375 | mReader.takeDisplayRequests(display, outDisplayRequestMask, |
| 376 | outLayers, outLayerRequestMasks); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 377 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 378 | } |
| 379 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 380 | Error Composer::getDisplayType(Display display, |
| 381 | IComposerClient::DisplayType* outType) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 382 | { |
| 383 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 384 | mClient->getDisplayType(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 385 | [&](const auto& tmpError, const auto& tmpType) { |
| 386 | error = tmpError; |
| 387 | if (error != Error::NONE) { |
| 388 | return; |
| 389 | } |
| 390 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 391 | *outType = tmpType; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 392 | }); |
| 393 | |
| 394 | return error; |
| 395 | } |
| 396 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 397 | Error Composer::getDozeSupport(Display display, bool* outSupport) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 398 | { |
| 399 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 400 | mClient->getDozeSupport(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 401 | [&](const auto& tmpError, const auto& tmpSupport) { |
| 402 | error = tmpError; |
| 403 | if (error != Error::NONE) { |
| 404 | return; |
| 405 | } |
| 406 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 407 | *outSupport = tmpSupport; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 408 | }); |
| 409 | |
| 410 | return error; |
| 411 | } |
| 412 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 413 | Error Composer::getHdrCapabilities(Display display, |
| 414 | std::vector<Hdr>* outTypes, float* outMaxLuminance, |
| 415 | float* outMaxAverageLuminance, float* outMinLuminance) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 416 | { |
| 417 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 418 | mClient->getHdrCapabilities(display, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 419 | [&](const auto& tmpError, const auto& tmpTypes, |
| 420 | const auto& tmpMaxLuminance, |
| 421 | const auto& tmpMaxAverageLuminance, |
| 422 | const auto& tmpMinLuminance) { |
| 423 | error = tmpError; |
| 424 | if (error != Error::NONE) { |
| 425 | return; |
| 426 | } |
| 427 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 428 | *outTypes = tmpTypes; |
| 429 | *outMaxLuminance = tmpMaxLuminance; |
| 430 | *outMaxAverageLuminance = tmpMaxAverageLuminance; |
| 431 | *outMinLuminance = tmpMinLuminance; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 432 | }); |
| 433 | |
| 434 | return error; |
| 435 | } |
| 436 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 437 | Error Composer::getReleaseFences(Display display, |
| 438 | std::vector<Layer>* outLayers, std::vector<int>* outReleaseFences) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 439 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 440 | mReader.takeReleaseFences(display, outLayers, outReleaseFences); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 441 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 442 | } |
| 443 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 444 | Error Composer::presentDisplay(Display display, int* outPresentFence) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 445 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 446 | mWriter.selectDisplay(display); |
| 447 | mWriter.presentDisplay(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 448 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 449 | Error error = execute(); |
| 450 | if (error != Error::NONE) { |
| 451 | return error; |
| 452 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 453 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 454 | mReader.takePresentFence(display, outPresentFence); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 455 | |
| 456 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 457 | } |
| 458 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 459 | Error Composer::setActiveConfig(Display display, Config config) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 460 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 461 | auto ret = mClient->setActiveConfig(display, config); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 462 | return unwrapRet(ret); |
| 463 | } |
| 464 | |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 465 | Error Composer::setClientTarget(Display display, uint32_t slot, |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 466 | const sp<GraphicBuffer>& target, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 467 | int acquireFence, Dataspace dataspace, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 468 | const std::vector<IComposerClient::Rect>& damage) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 469 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 470 | mWriter.selectDisplay(display); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 471 | if (mIsUsingVrComposer && target.get()) { |
| 472 | IVrComposerClient::BufferMetadata metadata = { |
| 473 | .width = target->getWidth(), |
| 474 | .height = target->getHeight(), |
| 475 | .stride = target->getStride(), |
| 476 | .layerCount = target->getLayerCount(), |
| 477 | .format = static_cast<PixelFormat>(target->getPixelFormat()), |
| 478 | .usage = target->getUsage(), |
| 479 | }; |
| 480 | mWriter.setClientTargetMetadata(metadata); |
| 481 | } |
| 482 | |
| 483 | const native_handle_t* handle = nullptr; |
| 484 | if (target.get()) { |
| 485 | handle = target->getNativeBuffer()->handle; |
| 486 | } |
| 487 | |
| 488 | mWriter.setClientTarget(slot, handle, acquireFence, dataspace, damage); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 489 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 490 | } |
| 491 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 492 | Error Composer::setColorMode(Display display, ColorMode mode) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 493 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 494 | auto ret = mClient->setColorMode(display, mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 495 | return unwrapRet(ret); |
| 496 | } |
| 497 | |
| 498 | Error Composer::setColorTransform(Display display, const float* matrix, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 499 | ColorTransform hint) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 500 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 501 | mWriter.selectDisplay(display); |
| 502 | mWriter.setColorTransform(matrix, hint); |
| 503 | return Error::NONE; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | Error Composer::setOutputBuffer(Display display, const native_handle_t* buffer, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 507 | int releaseFence) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 508 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 509 | mWriter.selectDisplay(display); |
| 510 | mWriter.setOutputBuffer(0, buffer, dup(releaseFence)); |
| 511 | return Error::NONE; |
| 512 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 513 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 514 | Error Composer::setPowerMode(Display display, IComposerClient::PowerMode mode) |
| 515 | { |
| 516 | auto ret = mClient->setPowerMode(display, mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 517 | return unwrapRet(ret); |
| 518 | } |
| 519 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 520 | Error Composer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 521 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 522 | auto ret = mClient->setVsyncEnabled(display, enabled); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 523 | return unwrapRet(ret); |
| 524 | } |
| 525 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 526 | Error Composer::setClientTargetSlotCount(Display display) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 527 | { |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 528 | const uint32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 529 | auto ret = mClient->setClientTargetSlotCount(display, bufferSlotCount); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 530 | return unwrapRet(ret); |
| 531 | } |
| 532 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 533 | Error Composer::validateDisplay(Display display, uint32_t* outNumTypes, |
| 534 | uint32_t* outNumRequests) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 535 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 536 | mWriter.selectDisplay(display); |
| 537 | mWriter.validateDisplay(); |
| 538 | |
| 539 | Error error = execute(); |
| 540 | if (error != Error::NONE) { |
| 541 | return error; |
| 542 | } |
| 543 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 544 | mReader.hasChanges(display, outNumTypes, outNumRequests); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 545 | |
| 546 | return Error::NONE; |
| 547 | } |
| 548 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame^] | 549 | Error Composer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes, |
| 550 | uint32_t* outNumRequests, int* outPresentFence, uint32_t* state) { |
| 551 | mWriter.selectDisplay(display); |
| 552 | mWriter.presentOrvalidateDisplay(); |
| 553 | |
| 554 | Error error = execute(); |
| 555 | if (error != Error::NONE) { |
| 556 | return error; |
| 557 | } |
| 558 | |
| 559 | mReader.takePresentOrValidateStage(display, state); |
| 560 | |
| 561 | if (*state == 1) { // Present succeeded |
| 562 | mReader.takePresentFence(display, outPresentFence); |
| 563 | } |
| 564 | |
| 565 | if (*state == 0) { // Validate succeeded. |
| 566 | mReader.hasChanges(display, outNumTypes, outNumRequests); |
| 567 | } |
| 568 | |
| 569 | return Error::NONE; |
| 570 | } |
| 571 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 572 | Error Composer::setCursorPosition(Display display, Layer layer, |
| 573 | int32_t x, int32_t y) |
| 574 | { |
| 575 | mWriter.selectDisplay(display); |
| 576 | mWriter.selectLayer(layer); |
| 577 | mWriter.setLayerCursorPosition(x, y); |
| 578 | return Error::NONE; |
| 579 | } |
| 580 | |
| 581 | Error Composer::setLayerBuffer(Display display, Layer layer, |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 582 | uint32_t slot, const sp<GraphicBuffer>& buffer, int acquireFence) |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 583 | { |
| 584 | mWriter.selectDisplay(display); |
| 585 | mWriter.selectLayer(layer); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 586 | if (mIsUsingVrComposer && buffer.get()) { |
| 587 | IVrComposerClient::BufferMetadata metadata = { |
| 588 | .width = buffer->getWidth(), |
| 589 | .height = buffer->getHeight(), |
| 590 | .stride = buffer->getStride(), |
| 591 | .layerCount = buffer->getLayerCount(), |
| 592 | .format = static_cast<PixelFormat>(buffer->getPixelFormat()), |
| 593 | .usage = buffer->getUsage(), |
| 594 | }; |
| 595 | mWriter.setLayerBufferMetadata(metadata); |
| 596 | } |
| 597 | |
| 598 | const native_handle_t* handle = nullptr; |
| 599 | if (buffer.get()) { |
| 600 | handle = buffer->getNativeBuffer()->handle; |
| 601 | } |
| 602 | |
| 603 | mWriter.setLayerBuffer(slot, handle, acquireFence); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 604 | return Error::NONE; |
| 605 | } |
| 606 | |
| 607 | Error Composer::setLayerSurfaceDamage(Display display, Layer layer, |
| 608 | const std::vector<IComposerClient::Rect>& damage) |
| 609 | { |
| 610 | mWriter.selectDisplay(display); |
| 611 | mWriter.selectLayer(layer); |
| 612 | mWriter.setLayerSurfaceDamage(damage); |
| 613 | return Error::NONE; |
| 614 | } |
| 615 | |
| 616 | Error Composer::setLayerBlendMode(Display display, Layer layer, |
| 617 | IComposerClient::BlendMode mode) |
| 618 | { |
| 619 | mWriter.selectDisplay(display); |
| 620 | mWriter.selectLayer(layer); |
| 621 | mWriter.setLayerBlendMode(mode); |
| 622 | return Error::NONE; |
| 623 | } |
| 624 | |
| 625 | Error Composer::setLayerColor(Display display, Layer layer, |
| 626 | const IComposerClient::Color& color) |
| 627 | { |
| 628 | mWriter.selectDisplay(display); |
| 629 | mWriter.selectLayer(layer); |
| 630 | mWriter.setLayerColor(color); |
| 631 | return Error::NONE; |
| 632 | } |
| 633 | |
| 634 | Error Composer::setLayerCompositionType(Display display, Layer layer, |
| 635 | IComposerClient::Composition type) |
| 636 | { |
| 637 | mWriter.selectDisplay(display); |
| 638 | mWriter.selectLayer(layer); |
| 639 | mWriter.setLayerCompositionType(type); |
| 640 | return Error::NONE; |
| 641 | } |
| 642 | |
| 643 | Error Composer::setLayerDataspace(Display display, Layer layer, |
| 644 | Dataspace dataspace) |
| 645 | { |
| 646 | mWriter.selectDisplay(display); |
| 647 | mWriter.selectLayer(layer); |
| 648 | mWriter.setLayerDataspace(dataspace); |
| 649 | return Error::NONE; |
| 650 | } |
| 651 | |
| 652 | Error Composer::setLayerDisplayFrame(Display display, Layer layer, |
| 653 | const IComposerClient::Rect& frame) |
| 654 | { |
| 655 | mWriter.selectDisplay(display); |
| 656 | mWriter.selectLayer(layer); |
| 657 | mWriter.setLayerDisplayFrame(frame); |
| 658 | return Error::NONE; |
| 659 | } |
| 660 | |
| 661 | Error Composer::setLayerPlaneAlpha(Display display, Layer layer, |
| 662 | float alpha) |
| 663 | { |
| 664 | mWriter.selectDisplay(display); |
| 665 | mWriter.selectLayer(layer); |
| 666 | mWriter.setLayerPlaneAlpha(alpha); |
| 667 | return Error::NONE; |
| 668 | } |
| 669 | |
| 670 | Error Composer::setLayerSidebandStream(Display display, Layer layer, |
| 671 | const native_handle_t* stream) |
| 672 | { |
| 673 | mWriter.selectDisplay(display); |
| 674 | mWriter.selectLayer(layer); |
| 675 | mWriter.setLayerSidebandStream(stream); |
| 676 | return Error::NONE; |
| 677 | } |
| 678 | |
| 679 | Error Composer::setLayerSourceCrop(Display display, Layer layer, |
| 680 | const IComposerClient::FRect& crop) |
| 681 | { |
| 682 | mWriter.selectDisplay(display); |
| 683 | mWriter.selectLayer(layer); |
| 684 | mWriter.setLayerSourceCrop(crop); |
| 685 | return Error::NONE; |
| 686 | } |
| 687 | |
| 688 | Error Composer::setLayerTransform(Display display, Layer layer, |
| 689 | Transform transform) |
| 690 | { |
| 691 | mWriter.selectDisplay(display); |
| 692 | mWriter.selectLayer(layer); |
| 693 | mWriter.setLayerTransform(transform); |
| 694 | return Error::NONE; |
| 695 | } |
| 696 | |
| 697 | Error Composer::setLayerVisibleRegion(Display display, Layer layer, |
| 698 | const std::vector<IComposerClient::Rect>& visible) |
| 699 | { |
| 700 | mWriter.selectDisplay(display); |
| 701 | mWriter.selectLayer(layer); |
| 702 | mWriter.setLayerVisibleRegion(visible); |
| 703 | return Error::NONE; |
| 704 | } |
| 705 | |
| 706 | Error Composer::setLayerZOrder(Display display, Layer layer, uint32_t z) |
| 707 | { |
| 708 | mWriter.selectDisplay(display); |
| 709 | mWriter.selectLayer(layer); |
| 710 | mWriter.setLayerZOrder(z); |
| 711 | return Error::NONE; |
| 712 | } |
| 713 | |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 714 | Error Composer::setLayerInfo(Display display, Layer layer, uint32_t type, |
| 715 | uint32_t appId) |
| 716 | { |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 717 | if (mIsUsingVrComposer) { |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 718 | mWriter.selectDisplay(display); |
| 719 | mWriter.selectLayer(layer); |
| 720 | mWriter.setLayerInfo(type, appId); |
| 721 | } |
| 722 | return Error::NONE; |
| 723 | } |
| 724 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 725 | Error Composer::execute() |
| 726 | { |
| 727 | // prepare input command queue |
| 728 | bool queueChanged = false; |
| 729 | uint32_t commandLength = 0; |
| 730 | hidl_vec<hidl_handle> commandHandles; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 731 | if (!mWriter.writeQueue(&queueChanged, &commandLength, &commandHandles)) { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 732 | mWriter.reset(); |
| 733 | return Error::NO_RESOURCES; |
| 734 | } |
| 735 | |
| 736 | // set up new input command queue if necessary |
| 737 | if (queueChanged) { |
| 738 | auto ret = mClient->setInputCommandQueue(*mWriter.getMQDescriptor()); |
| 739 | auto error = unwrapRet(ret); |
| 740 | if (error != Error::NONE) { |
| 741 | mWriter.reset(); |
| 742 | return error; |
| 743 | } |
| 744 | } |
| 745 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 746 | Error error = kDefaultError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 747 | mClient->executeCommands(commandLength, commandHandles, |
| 748 | [&](const auto& tmpError, const auto& tmpOutChanged, |
| 749 | const auto& tmpOutLength, const auto& tmpOutHandles) |
| 750 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 751 | error = tmpError; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 752 | |
| 753 | // set up new output command queue if necessary |
| 754 | if (error == Error::NONE && tmpOutChanged) { |
| 755 | error = kDefaultError; |
| 756 | mClient->getOutputCommandQueue( |
| 757 | [&](const auto& tmpError, |
| 758 | const auto& tmpDescriptor) |
| 759 | { |
| 760 | error = tmpError; |
| 761 | if (error != Error::NONE) { |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | mReader.setMQDescriptor(tmpDescriptor); |
| 766 | }); |
| 767 | } |
| 768 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 769 | if (error != Error::NONE) { |
| 770 | return; |
| 771 | } |
| 772 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 773 | if (mReader.readQueue(tmpOutLength, tmpOutHandles)) { |
| 774 | error = mReader.parse(); |
| 775 | mReader.reset(); |
| 776 | } else { |
| 777 | error = Error::NO_RESOURCES; |
| 778 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 779 | }); |
| 780 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 781 | if (error == Error::NONE) { |
| 782 | std::vector<CommandReader::CommandError> commandErrors = |
| 783 | mReader.takeErrors(); |
| 784 | |
| 785 | for (const auto& cmdErr : commandErrors) { |
| 786 | auto command = mWriter.getCommand(cmdErr.location); |
| 787 | |
| 788 | if (command == IComposerClient::Command::VALIDATE_DISPLAY || |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame^] | 789 | command == IComposerClient::Command::PRESENT_DISPLAY || |
| 790 | command == IComposerClient::Command::PRESENT_OR_VALIDATE_DISPLAY) { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 791 | error = cmdErr.error; |
| 792 | } else { |
| 793 | ALOGW("command 0x%x generated error %d", |
| 794 | command, cmdErr.error); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | mWriter.reset(); |
| 800 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 801 | return error; |
| 802 | } |
| 803 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 804 | CommandReader::~CommandReader() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 805 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 806 | resetData(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 807 | } |
| 808 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 809 | Error CommandReader::parse() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 810 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 811 | resetData(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 812 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 813 | IComposerClient::Command command; |
| 814 | uint16_t length = 0; |
| 815 | |
| 816 | while (!isEmpty()) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 817 | if (!beginCommand(&command, &length)) { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 818 | break; |
| 819 | } |
| 820 | |
| 821 | bool parsed = false; |
| 822 | switch (command) { |
| 823 | case IComposerClient::Command::SELECT_DISPLAY: |
| 824 | parsed = parseSelectDisplay(length); |
| 825 | break; |
| 826 | case IComposerClient::Command::SET_ERROR: |
| 827 | parsed = parseSetError(length); |
| 828 | break; |
| 829 | case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES: |
| 830 | parsed = parseSetChangedCompositionTypes(length); |
| 831 | break; |
| 832 | case IComposerClient::Command::SET_DISPLAY_REQUESTS: |
| 833 | parsed = parseSetDisplayRequests(length); |
| 834 | break; |
| 835 | case IComposerClient::Command::SET_PRESENT_FENCE: |
| 836 | parsed = parseSetPresentFence(length); |
| 837 | break; |
| 838 | case IComposerClient::Command::SET_RELEASE_FENCES: |
| 839 | parsed = parseSetReleaseFences(length); |
| 840 | break; |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame^] | 841 | case IComposerClient::Command ::SET_PRESENT_OR_VALIDATE_DISPLAY_RESULT: |
| 842 | parsed = parseSetPresentOrValidateDisplayResult(length); |
| 843 | break; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 844 | default: |
| 845 | parsed = false; |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | endCommand(); |
| 850 | |
| 851 | if (!parsed) { |
| 852 | ALOGE("failed to parse command 0x%x length %" PRIu16, |
| 853 | command, length); |
| 854 | break; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | return isEmpty() ? Error::NONE : Error::NO_RESOURCES; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 859 | } |
| 860 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 861 | bool CommandReader::parseSelectDisplay(uint16_t length) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 862 | { |
Daniel Nicoara | 3c9cbd4 | 2017-01-17 12:04:06 -0500 | [diff] [blame] | 863 | if (length != CommandWriterBase::kSelectDisplayLength) { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 864 | return false; |
| 865 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 866 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 867 | mCurrentReturnData = &mReturnData[read64()]; |
| 868 | |
| 869 | return true; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 870 | } |
| 871 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 872 | bool CommandReader::parseSetError(uint16_t length) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 873 | { |
Daniel Nicoara | 3c9cbd4 | 2017-01-17 12:04:06 -0500 | [diff] [blame] | 874 | if (length != CommandWriterBase::kSetErrorLength) { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 875 | return false; |
| 876 | } |
| 877 | |
| 878 | auto location = read(); |
| 879 | auto error = static_cast<Error>(readSigned()); |
| 880 | |
| 881 | mErrors.emplace_back(CommandError{location, error}); |
| 882 | |
| 883 | return true; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 884 | } |
| 885 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 886 | bool CommandReader::parseSetChangedCompositionTypes(uint16_t length) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 887 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 888 | // (layer id, composition type) pairs |
| 889 | if (length % 3 != 0 || !mCurrentReturnData) { |
| 890 | return false; |
| 891 | } |
| 892 | |
| 893 | uint32_t count = length / 3; |
| 894 | mCurrentReturnData->changedLayers.reserve(count); |
| 895 | mCurrentReturnData->compositionTypes.reserve(count); |
| 896 | while (count > 0) { |
| 897 | auto layer = read64(); |
| 898 | auto type = static_cast<IComposerClient::Composition>(readSigned()); |
| 899 | |
| 900 | mCurrentReturnData->changedLayers.push_back(layer); |
| 901 | mCurrentReturnData->compositionTypes.push_back(type); |
| 902 | |
| 903 | count--; |
| 904 | } |
| 905 | |
| 906 | return true; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 907 | } |
| 908 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 909 | bool CommandReader::parseSetDisplayRequests(uint16_t length) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 910 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 911 | // display requests followed by (layer id, layer requests) pairs |
| 912 | if (length % 3 != 1 || !mCurrentReturnData) { |
| 913 | return false; |
| 914 | } |
| 915 | |
| 916 | mCurrentReturnData->displayRequests = read(); |
| 917 | |
| 918 | uint32_t count = (length - 1) / 3; |
| 919 | mCurrentReturnData->requestedLayers.reserve(count); |
| 920 | mCurrentReturnData->requestMasks.reserve(count); |
| 921 | while (count > 0) { |
| 922 | auto layer = read64(); |
| 923 | auto layerRequestMask = read(); |
| 924 | |
| 925 | mCurrentReturnData->requestedLayers.push_back(layer); |
| 926 | mCurrentReturnData->requestMasks.push_back(layerRequestMask); |
| 927 | |
| 928 | count--; |
| 929 | } |
| 930 | |
| 931 | return true; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 932 | } |
| 933 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 934 | bool CommandReader::parseSetPresentFence(uint16_t length) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 935 | { |
Daniel Nicoara | 3c9cbd4 | 2017-01-17 12:04:06 -0500 | [diff] [blame] | 936 | if (length != CommandWriterBase::kSetPresentFenceLength || |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 937 | !mCurrentReturnData) { |
| 938 | return false; |
| 939 | } |
| 940 | |
| 941 | if (mCurrentReturnData->presentFence >= 0) { |
| 942 | close(mCurrentReturnData->presentFence); |
| 943 | } |
| 944 | mCurrentReturnData->presentFence = readFence(); |
| 945 | |
| 946 | return true; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 947 | } |
| 948 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 949 | bool CommandReader::parseSetReleaseFences(uint16_t length) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 950 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 951 | // (layer id, release fence index) pairs |
| 952 | if (length % 3 != 0 || !mCurrentReturnData) { |
| 953 | return false; |
| 954 | } |
| 955 | |
| 956 | uint32_t count = length / 3; |
| 957 | mCurrentReturnData->releasedLayers.reserve(count); |
| 958 | mCurrentReturnData->releaseFences.reserve(count); |
| 959 | while (count > 0) { |
| 960 | auto layer = read64(); |
| 961 | auto fence = readFence(); |
| 962 | |
| 963 | mCurrentReturnData->releasedLayers.push_back(layer); |
| 964 | mCurrentReturnData->releaseFences.push_back(fence); |
| 965 | |
| 966 | count--; |
| 967 | } |
| 968 | |
| 969 | return true; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 970 | } |
| 971 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame^] | 972 | bool CommandReader::parseSetPresentOrValidateDisplayResult(uint16_t length) |
| 973 | { |
| 974 | if (length != CommandWriterBase::kPresentOrValidateDisplayResultLength || !mCurrentReturnData) { |
| 975 | return false; |
| 976 | } |
| 977 | mCurrentReturnData->presentOrValidateState = read(); |
| 978 | return true; |
| 979 | } |
| 980 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 981 | void CommandReader::resetData() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 982 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 983 | mErrors.clear(); |
| 984 | |
| 985 | for (auto& data : mReturnData) { |
| 986 | if (data.second.presentFence >= 0) { |
| 987 | close(data.second.presentFence); |
| 988 | } |
| 989 | for (auto fence : data.second.releaseFences) { |
| 990 | if (fence >= 0) { |
| 991 | close(fence); |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | mReturnData.clear(); |
| 997 | mCurrentReturnData = nullptr; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 998 | } |
| 999 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1000 | std::vector<CommandReader::CommandError> CommandReader::takeErrors() |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1001 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1002 | return std::move(mErrors); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1003 | } |
| 1004 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1005 | bool CommandReader::hasChanges(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1006 | uint32_t* outNumChangedCompositionTypes, |
| 1007 | uint32_t* outNumLayerRequestMasks) const |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1008 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1009 | auto found = mReturnData.find(display); |
| 1010 | if (found == mReturnData.end()) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1011 | *outNumChangedCompositionTypes = 0; |
| 1012 | *outNumLayerRequestMasks = 0; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1013 | return false; |
| 1014 | } |
| 1015 | |
| 1016 | const ReturnData& data = found->second; |
| 1017 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1018 | *outNumChangedCompositionTypes = data.compositionTypes.size(); |
| 1019 | *outNumLayerRequestMasks = data.requestMasks.size(); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1020 | |
| 1021 | return !(data.compositionTypes.empty() && data.requestMasks.empty()); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1024 | void CommandReader::takeChangedCompositionTypes(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1025 | std::vector<Layer>* outLayers, |
| 1026 | std::vector<IComposerClient::Composition>* outTypes) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1027 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1028 | auto found = mReturnData.find(display); |
| 1029 | if (found == mReturnData.end()) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1030 | outLayers->clear(); |
| 1031 | outTypes->clear(); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1032 | return; |
| 1033 | } |
| 1034 | |
| 1035 | ReturnData& data = found->second; |
| 1036 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1037 | *outLayers = std::move(data.changedLayers); |
| 1038 | *outTypes = std::move(data.compositionTypes); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1041 | void CommandReader::takeDisplayRequests(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1042 | uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers, |
| 1043 | std::vector<uint32_t>* outLayerRequestMasks) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1044 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1045 | auto found = mReturnData.find(display); |
| 1046 | if (found == mReturnData.end()) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1047 | *outDisplayRequestMask = 0; |
| 1048 | outLayers->clear(); |
| 1049 | outLayerRequestMasks->clear(); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1050 | return; |
| 1051 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1052 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1053 | ReturnData& data = found->second; |
| 1054 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1055 | *outDisplayRequestMask = data.displayRequests; |
| 1056 | *outLayers = std::move(data.requestedLayers); |
| 1057 | *outLayerRequestMasks = std::move(data.requestMasks); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1058 | } |
| 1059 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1060 | void CommandReader::takeReleaseFences(Display display, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1061 | std::vector<Layer>* outLayers, std::vector<int>* outReleaseFences) |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1062 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1063 | auto found = mReturnData.find(display); |
| 1064 | if (found == mReturnData.end()) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1065 | outLayers->clear(); |
| 1066 | outReleaseFences->clear(); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | ReturnData& data = found->second; |
| 1071 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1072 | *outLayers = std::move(data.releasedLayers); |
| 1073 | *outReleaseFences = std::move(data.releaseFences); |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1076 | void CommandReader::takePresentFence(Display display, int* outPresentFence) |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1077 | { |
| 1078 | auto found = mReturnData.find(display); |
| 1079 | if (found == mReturnData.end()) { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1080 | *outPresentFence = -1; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | ReturnData& data = found->second; |
| 1085 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1086 | *outPresentFence = data.presentFence; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1087 | data.presentFence = -1; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1088 | } |
| 1089 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame^] | 1090 | void CommandReader::takePresentOrValidateStage(Display display, uint32_t* state) { |
| 1091 | auto found = mReturnData.find(display); |
| 1092 | if (found == mReturnData.end()) { |
| 1093 | *state= -1; |
| 1094 | return; |
| 1095 | } |
| 1096 | ReturnData& data = found->second; |
| 1097 | *state = data.presentOrValidateState; |
| 1098 | } |
| 1099 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1100 | } // namespace Hwc2 |
| 1101 | |
| 1102 | } // namespace android |