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