ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2022, 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 | |
ramindani | 458e53e | 2022-02-23 17:30:16 +0000 | [diff] [blame] | 17 | #include "VtsComposerClient.h" |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 18 | #include <aidlcommonsupport/NativeHandle.h> |
| 19 | #include <android-base/logging.h> |
| 20 | #include <log/log_main.h> |
| 21 | |
| 22 | #undef LOG_TAG |
| 23 | #define LOG_TAG "VtsComposerClient" |
| 24 | |
| 25 | using namespace std::chrono_literals; |
| 26 | |
| 27 | namespace aidl::android::hardware::graphics::composer3::vts { |
| 28 | |
| 29 | VtsComposerClient::VtsComposerClient(const std::string& name) { |
| 30 | SpAIBinder binder(AServiceManager_waitForService(name.c_str())); |
| 31 | ALOGE_IF(binder == nullptr, "Could not initialize the service binder"); |
| 32 | if (binder != nullptr) { |
| 33 | mComposer = IComposer::fromBinder(binder); |
| 34 | ALOGE_IF(mComposer == nullptr, "Failed to acquire the composer from the binder"); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | ScopedAStatus VtsComposerClient::createClient() { |
| 39 | if (mComposer == nullptr) { |
| 40 | ALOGE("IComposer not initialized"); |
| 41 | return ScopedAStatus::fromServiceSpecificError(IComposerClient::INVALID_CONFIGURATION); |
| 42 | } |
| 43 | auto status = mComposer->createClient(&mComposerClient); |
| 44 | if (!status.isOk() || mComposerClient == nullptr) { |
| 45 | ALOGE("Failed to create client for IComposerClient with %s", |
| 46 | status.getDescription().c_str()); |
| 47 | return status; |
| 48 | } |
| 49 | mComposerCallback = SharedRefBase::make<GraphicsComposerCallback>(); |
| 50 | if (mComposerCallback == nullptr) { |
| 51 | ALOGE("Unable to create ComposerCallback"); |
| 52 | return ScopedAStatus::fromServiceSpecificError(IComposerClient::INVALID_CONFIGURATION); |
| 53 | } |
| 54 | return mComposerClient->registerCallback(mComposerCallback); |
| 55 | } |
| 56 | |
| 57 | bool VtsComposerClient::tearDown() { |
| 58 | return verifyComposerCallbackParams() && destroyAllLayers(); |
| 59 | } |
| 60 | |
Brian Lindahl | 78ff2d6 | 2022-12-18 11:21:41 -0700 | [diff] [blame] | 61 | std::pair<ScopedAStatus, int32_t> VtsComposerClient::getInterfaceVersion() { |
| 62 | int32_t version = 1; |
| 63 | auto status = mComposerClient->getInterfaceVersion(&version); |
| 64 | return {std::move(status), version}; |
| 65 | } |
| 66 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 67 | std::pair<ScopedAStatus, VirtualDisplay> VtsComposerClient::createVirtualDisplay( |
| 68 | int32_t width, int32_t height, PixelFormat pixelFormat, int32_t bufferSlotCount) { |
| 69 | VirtualDisplay outVirtualDisplay; |
| 70 | auto status = mComposerClient->createVirtualDisplay(width, height, pixelFormat, bufferSlotCount, |
| 71 | &outVirtualDisplay); |
| 72 | if (!status.isOk()) { |
| 73 | return {std::move(status), outVirtualDisplay}; |
| 74 | } |
| 75 | return {addDisplayToDisplayResources(outVirtualDisplay.display, /*isVirtual*/ true), |
| 76 | outVirtualDisplay}; |
| 77 | } |
| 78 | |
| 79 | ScopedAStatus VtsComposerClient::destroyVirtualDisplay(int64_t display) { |
| 80 | auto status = mComposerClient->destroyVirtualDisplay(display); |
| 81 | if (!status.isOk()) { |
| 82 | return status; |
| 83 | } |
| 84 | mDisplayResources.erase(display); |
| 85 | return status; |
| 86 | } |
| 87 | |
| 88 | std::pair<ScopedAStatus, int64_t> VtsComposerClient::createLayer(int64_t display, |
| 89 | int32_t bufferSlotCount) { |
| 90 | int64_t outLayer; |
| 91 | auto status = mComposerClient->createLayer(display, bufferSlotCount, &outLayer); |
| 92 | |
| 93 | if (!status.isOk()) { |
| 94 | return {std::move(status), outLayer}; |
| 95 | } |
| 96 | return {addLayerToDisplayResources(display, outLayer), outLayer}; |
| 97 | } |
| 98 | |
| 99 | ScopedAStatus VtsComposerClient::destroyLayer(int64_t display, int64_t layer) { |
| 100 | auto status = mComposerClient->destroyLayer(display, layer); |
| 101 | |
| 102 | if (!status.isOk()) { |
| 103 | return status; |
| 104 | } |
| 105 | removeLayerFromDisplayResources(display, layer); |
| 106 | return status; |
| 107 | } |
| 108 | |
| 109 | std::pair<ScopedAStatus, int32_t> VtsComposerClient::getActiveConfig(int64_t display) { |
| 110 | int32_t outConfig; |
| 111 | return {mComposerClient->getActiveConfig(display, &outConfig), outConfig}; |
| 112 | } |
| 113 | |
| 114 | ScopedAStatus VtsComposerClient::setActiveConfig(VtsDisplay* vtsDisplay, int32_t config) { |
| 115 | auto status = mComposerClient->setActiveConfig(vtsDisplay->getDisplayId(), config); |
| 116 | if (!status.isOk()) { |
| 117 | return status; |
| 118 | } |
| 119 | return updateDisplayProperties(vtsDisplay, config); |
| 120 | } |
| 121 | |
| 122 | std::pair<ScopedAStatus, int32_t> VtsComposerClient::getDisplayAttribute( |
| 123 | int64_t display, int32_t config, DisplayAttribute displayAttribute) { |
| 124 | int32_t outDisplayAttribute; |
| 125 | return {mComposerClient->getDisplayAttribute(display, config, displayAttribute, |
| 126 | &outDisplayAttribute), |
| 127 | outDisplayAttribute}; |
| 128 | } |
| 129 | |
| 130 | ScopedAStatus VtsComposerClient::setPowerMode(int64_t display, PowerMode powerMode) { |
| 131 | return mComposerClient->setPowerMode(display, powerMode); |
| 132 | } |
| 133 | |
| 134 | ScopedAStatus VtsComposerClient::setVsync(int64_t display, bool enable) { |
| 135 | return mComposerClient->setVsyncEnabled(display, enable); |
| 136 | } |
| 137 | |
| 138 | void VtsComposerClient::setVsyncAllowed(bool isAllowed) { |
| 139 | mComposerCallback->setVsyncAllowed(isAllowed); |
| 140 | } |
| 141 | |
| 142 | std::pair<ScopedAStatus, std::vector<float>> VtsComposerClient::getDataspaceSaturationMatrix( |
| 143 | Dataspace dataspace) { |
| 144 | std::vector<float> outMatrix; |
| 145 | return {mComposerClient->getDataspaceSaturationMatrix(dataspace, &outMatrix), outMatrix}; |
| 146 | } |
| 147 | |
| 148 | std::pair<ScopedAStatus, std::vector<CommandResultPayload>> VtsComposerClient::executeCommands( |
| 149 | const std::vector<DisplayCommand>& commands) { |
| 150 | std::vector<CommandResultPayload> outResultPayload; |
| 151 | return {mComposerClient->executeCommands(commands, &outResultPayload), |
| 152 | std::move(outResultPayload)}; |
| 153 | } |
| 154 | |
| 155 | std::optional<VsyncPeriodChangeTimeline> VtsComposerClient::takeLastVsyncPeriodChangeTimeline() { |
| 156 | return mComposerCallback->takeLastVsyncPeriodChangeTimeline(); |
| 157 | } |
| 158 | |
| 159 | ScopedAStatus VtsComposerClient::setContentType(int64_t display, ContentType contentType) { |
| 160 | return mComposerClient->setContentType(display, contentType); |
| 161 | } |
| 162 | |
| 163 | std::pair<ScopedAStatus, VsyncPeriodChangeTimeline> |
| 164 | VtsComposerClient::setActiveConfigWithConstraints(VtsDisplay* vtsDisplay, int32_t config, |
| 165 | const VsyncPeriodChangeConstraints& constraints) { |
| 166 | VsyncPeriodChangeTimeline outTimeline; |
| 167 | auto status = mComposerClient->setActiveConfigWithConstraints( |
| 168 | vtsDisplay->getDisplayId(), config, constraints, &outTimeline); |
| 169 | if (!status.isOk()) { |
| 170 | return {std::move(status), outTimeline}; |
| 171 | } |
| 172 | return {updateDisplayProperties(vtsDisplay, config), outTimeline}; |
| 173 | } |
| 174 | |
| 175 | std::pair<ScopedAStatus, std::vector<DisplayCapability>> VtsComposerClient::getDisplayCapabilities( |
| 176 | int64_t display) { |
| 177 | std::vector<DisplayCapability> outCapabilities; |
| 178 | return {mComposerClient->getDisplayCapabilities(display, &outCapabilities), outCapabilities}; |
| 179 | } |
| 180 | |
| 181 | ScopedAStatus VtsComposerClient::dumpDebugInfo() { |
Ady Abraham | 89d7270 | 2022-02-18 17:04:55 -0800 | [diff] [blame] | 182 | int pipefds[2]; |
| 183 | if (pipe(pipefds) < 0) { |
| 184 | return ScopedAStatus::fromServiceSpecificError(IComposer::EX_NO_RESOURCES); |
| 185 | } |
| 186 | |
| 187 | const auto status = mComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0); |
| 188 | close(pipefds[0]); |
| 189 | close(pipefds[1]); |
| 190 | return ScopedAStatus::fromStatus(status); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | std::pair<ScopedAStatus, DisplayIdentification> VtsComposerClient::getDisplayIdentificationData( |
| 194 | int64_t display) { |
| 195 | DisplayIdentification outDisplayIdentification; |
| 196 | return {mComposerClient->getDisplayIdentificationData(display, &outDisplayIdentification), |
| 197 | outDisplayIdentification}; |
| 198 | } |
| 199 | |
| 200 | std::pair<ScopedAStatus, HdrCapabilities> VtsComposerClient::getHdrCapabilities(int64_t display) { |
| 201 | HdrCapabilities outHdrCapabilities; |
| 202 | return {mComposerClient->getHdrCapabilities(display, &outHdrCapabilities), outHdrCapabilities}; |
| 203 | } |
| 204 | |
| 205 | std::pair<ScopedAStatus, std::vector<PerFrameMetadataKey>> |
| 206 | VtsComposerClient::getPerFrameMetadataKeys(int64_t display) { |
| 207 | std::vector<PerFrameMetadataKey> outPerFrameMetadataKeys; |
| 208 | return {mComposerClient->getPerFrameMetadataKeys(display, &outPerFrameMetadataKeys), |
| 209 | outPerFrameMetadataKeys}; |
| 210 | } |
| 211 | |
| 212 | std::pair<ScopedAStatus, ReadbackBufferAttributes> VtsComposerClient::getReadbackBufferAttributes( |
| 213 | int64_t display) { |
| 214 | ReadbackBufferAttributes outReadbackBufferAttributes; |
| 215 | return {mComposerClient->getReadbackBufferAttributes(display, &outReadbackBufferAttributes), |
| 216 | outReadbackBufferAttributes}; |
| 217 | } |
| 218 | |
| 219 | ScopedAStatus VtsComposerClient::setReadbackBuffer(int64_t display, const native_handle_t* buffer, |
| 220 | const ScopedFileDescriptor& releaseFence) { |
| 221 | return mComposerClient->setReadbackBuffer(display, ::android::dupToAidl(buffer), releaseFence); |
| 222 | } |
| 223 | |
| 224 | std::pair<ScopedAStatus, ScopedFileDescriptor> VtsComposerClient::getReadbackBufferFence( |
| 225 | int64_t display) { |
| 226 | ScopedFileDescriptor outReleaseFence; |
| 227 | return {mComposerClient->getReadbackBufferFence(display, &outReleaseFence), |
| 228 | std::move(outReleaseFence)}; |
| 229 | } |
| 230 | |
| 231 | std::pair<ScopedAStatus, std::vector<ColorMode>> VtsComposerClient::getColorModes(int64_t display) { |
| 232 | std::vector<ColorMode> outColorModes; |
| 233 | return {mComposerClient->getColorModes(display, &outColorModes), outColorModes}; |
| 234 | } |
| 235 | |
| 236 | std::pair<ScopedAStatus, std::vector<RenderIntent>> VtsComposerClient::getRenderIntents( |
| 237 | int64_t display, ColorMode colorMode) { |
| 238 | std::vector<RenderIntent> outRenderIntents; |
| 239 | return {mComposerClient->getRenderIntents(display, colorMode, &outRenderIntents), |
| 240 | outRenderIntents}; |
| 241 | } |
| 242 | |
| 243 | ScopedAStatus VtsComposerClient::setColorMode(int64_t display, ColorMode colorMode, |
| 244 | RenderIntent renderIntent) { |
| 245 | return mComposerClient->setColorMode(display, colorMode, renderIntent); |
| 246 | } |
| 247 | |
| 248 | std::pair<ScopedAStatus, DisplayContentSamplingAttributes> |
| 249 | VtsComposerClient::getDisplayedContentSamplingAttributes(int64_t display) { |
| 250 | DisplayContentSamplingAttributes outAttributes; |
| 251 | return {mComposerClient->getDisplayedContentSamplingAttributes(display, &outAttributes), |
| 252 | outAttributes}; |
| 253 | } |
| 254 | |
| 255 | ScopedAStatus VtsComposerClient::setDisplayedContentSamplingEnabled( |
| 256 | int64_t display, bool isEnabled, FormatColorComponent formatColorComponent, |
| 257 | int64_t maxFrames) { |
| 258 | return mComposerClient->setDisplayedContentSamplingEnabled(display, isEnabled, |
| 259 | formatColorComponent, maxFrames); |
| 260 | } |
| 261 | |
| 262 | std::pair<ScopedAStatus, DisplayContentSample> VtsComposerClient::getDisplayedContentSample( |
| 263 | int64_t display, int64_t maxFrames, int64_t timestamp) { |
| 264 | DisplayContentSample outDisplayContentSample; |
| 265 | return {mComposerClient->getDisplayedContentSample(display, maxFrames, timestamp, |
| 266 | &outDisplayContentSample), |
| 267 | outDisplayContentSample}; |
| 268 | } |
| 269 | |
| 270 | std::pair<ScopedAStatus, DisplayConnectionType> VtsComposerClient::getDisplayConnectionType( |
| 271 | int64_t display) { |
| 272 | DisplayConnectionType outDisplayConnectionType; |
| 273 | return {mComposerClient->getDisplayConnectionType(display, &outDisplayConnectionType), |
| 274 | outDisplayConnectionType}; |
| 275 | } |
| 276 | |
| 277 | std::pair<ScopedAStatus, std::vector<int32_t>> VtsComposerClient::getDisplayConfigs( |
| 278 | int64_t display) { |
| 279 | std::vector<int32_t> outConfigs; |
| 280 | return {mComposerClient->getDisplayConfigs(display, &outConfigs), outConfigs}; |
| 281 | } |
| 282 | |
| 283 | std::pair<ScopedAStatus, int32_t> VtsComposerClient::getDisplayVsyncPeriod(int64_t display) { |
| 284 | int32_t outVsyncPeriodNanos; |
| 285 | return {mComposerClient->getDisplayVsyncPeriod(display, &outVsyncPeriodNanos), |
| 286 | outVsyncPeriodNanos}; |
| 287 | } |
| 288 | |
| 289 | ScopedAStatus VtsComposerClient::setAutoLowLatencyMode(int64_t display, bool isEnabled) { |
| 290 | return mComposerClient->setAutoLowLatencyMode(display, isEnabled); |
| 291 | } |
| 292 | |
| 293 | std::pair<ScopedAStatus, std::vector<ContentType>> VtsComposerClient::getSupportedContentTypes( |
| 294 | int64_t display) { |
| 295 | std::vector<ContentType> outContentTypes; |
| 296 | return {mComposerClient->getSupportedContentTypes(display, &outContentTypes), outContentTypes}; |
| 297 | } |
| 298 | |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 299 | std::pair<ScopedAStatus, std::optional<DisplayDecorationSupport>> |
| 300 | VtsComposerClient::getDisplayDecorationSupport(int64_t display) { |
| 301 | std::optional<DisplayDecorationSupport> outSupport; |
| 302 | return {mComposerClient->getDisplayDecorationSupport(display, &outSupport), outSupport}; |
| 303 | } |
| 304 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 305 | std::pair<ScopedAStatus, int32_t> VtsComposerClient::getMaxVirtualDisplayCount() { |
| 306 | int32_t outMaxVirtualDisplayCount; |
| 307 | return {mComposerClient->getMaxVirtualDisplayCount(&outMaxVirtualDisplayCount), |
| 308 | outMaxVirtualDisplayCount}; |
| 309 | } |
| 310 | |
| 311 | std::pair<ScopedAStatus, std::string> VtsComposerClient::getDisplayName(int64_t display) { |
| 312 | std::string outDisplayName; |
| 313 | return {mComposerClient->getDisplayName(display, &outDisplayName), outDisplayName}; |
| 314 | } |
| 315 | |
| 316 | ScopedAStatus VtsComposerClient::setClientTargetSlotCount(int64_t display, |
| 317 | int32_t bufferSlotCount) { |
| 318 | return mComposerClient->setClientTargetSlotCount(display, bufferSlotCount); |
| 319 | } |
| 320 | |
| 321 | std::pair<ScopedAStatus, std::vector<Capability>> VtsComposerClient::getCapabilities() { |
| 322 | std::vector<Capability> outCapabilities; |
| 323 | return {mComposer->getCapabilities(&outCapabilities), outCapabilities}; |
| 324 | } |
| 325 | |
| 326 | ScopedAStatus VtsComposerClient::setBootDisplayConfig(int64_t display, int32_t config) { |
| 327 | return mComposerClient->setBootDisplayConfig(display, config); |
| 328 | } |
| 329 | |
| 330 | ScopedAStatus VtsComposerClient::clearBootDisplayConfig(int64_t display) { |
| 331 | return mComposerClient->clearBootDisplayConfig(display); |
| 332 | } |
| 333 | |
| 334 | std::pair<ScopedAStatus, int32_t> VtsComposerClient::getPreferredBootDisplayConfig( |
| 335 | int64_t display) { |
| 336 | int32_t outConfig; |
| 337 | return {mComposerClient->getPreferredBootDisplayConfig(display, &outConfig), outConfig}; |
| 338 | } |
| 339 | |
Kriti Dang | 3793ebd | 2022-12-05 13:03:49 +0100 | [diff] [blame] | 340 | std::pair<ScopedAStatus, std::vector<common::HdrConversionCapability>> |
| 341 | VtsComposerClient::getHdrConversionCapabilities() { |
| 342 | std::vector<common::HdrConversionCapability> hdrConversionCapability; |
| 343 | return {mComposerClient->getHdrConversionCapabilities(&hdrConversionCapability), |
| 344 | hdrConversionCapability}; |
| 345 | } |
| 346 | |
| 347 | ScopedAStatus VtsComposerClient::setHdrConversionStrategy( |
| 348 | const common::HdrConversionStrategy& conversionStrategy) { |
| 349 | return mComposerClient->setHdrConversionStrategy(conversionStrategy); |
| 350 | } |
| 351 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 352 | std::pair<ScopedAStatus, common::Transform> VtsComposerClient::getDisplayPhysicalOrientation( |
| 353 | int64_t display) { |
| 354 | common::Transform outDisplayOrientation; |
| 355 | return {mComposerClient->getDisplayPhysicalOrientation(display, &outDisplayOrientation), |
| 356 | outDisplayOrientation}; |
| 357 | } |
| 358 | |
Sally Qi | 2600d34 | 2022-08-16 12:46:17 -0700 | [diff] [blame] | 359 | std::pair<ScopedAStatus, composer3::OverlayProperties> VtsComposerClient::getOverlaySupport() { |
| 360 | OverlayProperties properties; |
| 361 | return {mComposerClient->getOverlaySupport(&properties), properties}; |
| 362 | } |
| 363 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 364 | ScopedAStatus VtsComposerClient::setIdleTimerEnabled(int64_t display, int32_t timeoutMs) { |
| 365 | return mComposerClient->setIdleTimerEnabled(display, timeoutMs); |
| 366 | } |
| 367 | |
| 368 | int32_t VtsComposerClient::getVsyncIdleCount() { |
| 369 | return mComposerCallback->getVsyncIdleCount(); |
| 370 | } |
| 371 | |
| 372 | int64_t VtsComposerClient::getVsyncIdleTime() { |
| 373 | return mComposerCallback->getVsyncIdleTime(); |
| 374 | } |
| 375 | |
ramindani | 8345034 | 2023-02-03 12:52:08 -0800 | [diff] [blame^] | 376 | ndk::ScopedAStatus VtsComposerClient::setRefreshRateChangedCallbackDebugEnabled( |
| 377 | int64_t /* display */, bool /* enabled */) { |
| 378 | // TODO(b/202734676) Add implementation for VTS tests |
| 379 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 380 | } |
| 381 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 382 | int64_t VtsComposerClient::getInvalidDisplayId() { |
| 383 | // returns an invalid display id (one that has not been registered to a |
| 384 | // display. Currently assuming that a device will never have close to |
| 385 | // std::numeric_limit<uint64_t>::max() displays registered while running tests |
| 386 | int64_t id = std::numeric_limits<int64_t>::max(); |
| 387 | std::vector<int64_t> displays = mComposerCallback->getDisplays(); |
| 388 | while (id > 0) { |
| 389 | if (std::none_of(displays.begin(), displays.end(), |
| 390 | [id](const auto& display) { return id == display; })) { |
| 391 | return id; |
| 392 | } |
| 393 | id--; |
| 394 | } |
| 395 | |
| 396 | // Although 0 could be an invalid display, a return value of 0 |
| 397 | // from getInvalidDisplayId means all other ids are in use, a condition which |
| 398 | // we are assuming a device will never have |
| 399 | EXPECT_NE(0, id); |
| 400 | return id; |
| 401 | } |
| 402 | |
| 403 | std::pair<ScopedAStatus, std::vector<VtsDisplay>> VtsComposerClient::getDisplays() { |
| 404 | while (true) { |
| 405 | // Sleep for a small period of time to allow all built-in displays |
| 406 | // to post hotplug events |
| 407 | std::this_thread::sleep_for(5ms); |
| 408 | std::vector<int64_t> displays = mComposerCallback->getDisplays(); |
| 409 | if (displays.empty()) { |
| 410 | continue; |
| 411 | } |
| 412 | |
| 413 | std::vector<VtsDisplay> vtsDisplays; |
| 414 | vtsDisplays.reserve(displays.size()); |
| 415 | for (int64_t display : displays) { |
| 416 | auto vtsDisplay = VtsDisplay{display}; |
| 417 | auto configs = getDisplayConfigs(display); |
| 418 | if (!configs.first.isOk()) { |
| 419 | ALOGE("Unable to get the displays for test, failed to get the configs " |
| 420 | "for display %" PRId64, |
| 421 | display); |
| 422 | return {std::move(configs.first), vtsDisplays}; |
| 423 | } |
| 424 | for (int config : configs.second) { |
HyunKyoung | 4775bdc | 2022-11-09 20:43:34 +0900 | [diff] [blame] | 425 | auto status = addDisplayConfig(&vtsDisplay, config); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 426 | if (!status.isOk()) { |
HyunKyoung | 4775bdc | 2022-11-09 20:43:34 +0900 | [diff] [blame] | 427 | ALOGE("Unable to get the displays for test, failed to add config " |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 428 | "for display %" PRId64, |
| 429 | display); |
| 430 | return {std::move(status), vtsDisplays}; |
| 431 | } |
| 432 | } |
HyunKyoung | 4775bdc | 2022-11-09 20:43:34 +0900 | [diff] [blame] | 433 | |
| 434 | auto config = getActiveConfig(display); |
| 435 | if (!config.first.isOk()) { |
| 436 | ALOGE("Unable to get the displays for test, failed to get active config " |
| 437 | "for display %" PRId64, display); |
| 438 | return {std::move(config.first), vtsDisplays}; |
| 439 | } |
| 440 | |
| 441 | auto status = updateDisplayProperties(&vtsDisplay, config.second); |
| 442 | if (!status.isOk()) { |
| 443 | ALOGE("Unable to get the displays for test, " |
| 444 | "failed to update the properties " |
| 445 | "for display %" PRId64, |
| 446 | display); |
| 447 | return {std::move(status), vtsDisplays}; |
| 448 | } |
| 449 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 450 | vtsDisplays.emplace_back(vtsDisplay); |
| 451 | addDisplayToDisplayResources(display, /*isVirtual*/ false); |
| 452 | } |
| 453 | |
| 454 | return {ScopedAStatus::ok(), vtsDisplays}; |
| 455 | } |
| 456 | } |
| 457 | |
HyunKyoung | 4775bdc | 2022-11-09 20:43:34 +0900 | [diff] [blame] | 458 | ScopedAStatus VtsComposerClient::addDisplayConfig(VtsDisplay* vtsDisplay, int32_t config) { |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 459 | const auto width = |
| 460 | getDisplayAttribute(vtsDisplay->getDisplayId(), config, DisplayAttribute::WIDTH); |
| 461 | const auto height = |
| 462 | getDisplayAttribute(vtsDisplay->getDisplayId(), config, DisplayAttribute::HEIGHT); |
| 463 | const auto vsyncPeriod = |
| 464 | getDisplayAttribute(vtsDisplay->getDisplayId(), config, DisplayAttribute::VSYNC_PERIOD); |
| 465 | const auto configGroup = |
| 466 | getDisplayAttribute(vtsDisplay->getDisplayId(), config, DisplayAttribute::CONFIG_GROUP); |
| 467 | if (width.first.isOk() && height.first.isOk() && vsyncPeriod.first.isOk() && |
| 468 | configGroup.first.isOk()) { |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 469 | vtsDisplay->addDisplayConfig(config, {vsyncPeriod.second, configGroup.second}); |
| 470 | return ScopedAStatus::ok(); |
| 471 | } |
| 472 | |
| 473 | LOG(ERROR) << "Failed to update display property for width: " << width.first.isOk() |
| 474 | << ", height: " << height.first.isOk() << ", vsync: " << vsyncPeriod.first.isOk() |
| 475 | << ", config: " << configGroup.first.isOk(); |
| 476 | return ScopedAStatus::fromServiceSpecificError(IComposerClient::EX_BAD_CONFIG); |
| 477 | } |
| 478 | |
HyunKyoung | 4775bdc | 2022-11-09 20:43:34 +0900 | [diff] [blame] | 479 | ScopedAStatus VtsComposerClient::updateDisplayProperties(VtsDisplay* vtsDisplay, int32_t config) { |
| 480 | const auto width = |
| 481 | getDisplayAttribute(vtsDisplay->getDisplayId(), config, DisplayAttribute::WIDTH); |
| 482 | const auto height = |
| 483 | getDisplayAttribute(vtsDisplay->getDisplayId(), config, DisplayAttribute::HEIGHT); |
| 484 | if (width.first.isOk() && height.first.isOk()) { |
| 485 | vtsDisplay->setDimensions(width.second, height.second); |
| 486 | return ScopedAStatus::ok(); |
| 487 | } |
| 488 | |
| 489 | LOG(ERROR) << "Failed to update display property for width: " << width.first.isOk() |
| 490 | << ", height: " << height.first.isOk(); |
| 491 | return ScopedAStatus::fromServiceSpecificError(IComposerClient::EX_BAD_CONFIG); |
| 492 | } |
| 493 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 494 | ScopedAStatus VtsComposerClient::addDisplayToDisplayResources(int64_t display, bool isVirtual) { |
| 495 | if (mDisplayResources.insert({display, DisplayResource(isVirtual)}).second) { |
| 496 | return ScopedAStatus::ok(); |
| 497 | } |
| 498 | |
| 499 | ALOGE("Duplicate display id %" PRId64, display); |
| 500 | return ScopedAStatus::fromServiceSpecificError(IComposerClient::EX_BAD_DISPLAY); |
| 501 | } |
| 502 | |
| 503 | ScopedAStatus VtsComposerClient::addLayerToDisplayResources(int64_t display, int64_t layer) { |
| 504 | auto resource = mDisplayResources.find(display); |
| 505 | if (resource == mDisplayResources.end()) { |
| 506 | resource = mDisplayResources.insert({display, DisplayResource(false)}).first; |
| 507 | } |
| 508 | |
| 509 | if (!resource->second.layers.insert(layer).second) { |
| 510 | ALOGE("Duplicate layer id %" PRId64, layer); |
| 511 | return ScopedAStatus::fromServiceSpecificError(IComposerClient::EX_BAD_LAYER); |
| 512 | } |
| 513 | return ScopedAStatus::ok(); |
| 514 | } |
| 515 | |
| 516 | void VtsComposerClient::removeLayerFromDisplayResources(int64_t display, int64_t layer) { |
| 517 | auto resource = mDisplayResources.find(display); |
| 518 | if (resource != mDisplayResources.end()) { |
| 519 | resource->second.layers.erase(layer); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | bool VtsComposerClient::verifyComposerCallbackParams() { |
| 524 | bool isValid = true; |
| 525 | if (mComposerCallback != nullptr) { |
| 526 | if (mComposerCallback->getInvalidHotplugCount() != 0) { |
| 527 | ALOGE("Invalid hotplug count"); |
| 528 | isValid = false; |
| 529 | } |
| 530 | if (mComposerCallback->getInvalidRefreshCount() != 0) { |
| 531 | ALOGE("Invalid refresh count"); |
| 532 | isValid = false; |
| 533 | } |
| 534 | if (mComposerCallback->getInvalidVsyncCount() != 0) { |
| 535 | ALOGE("Invalid vsync count"); |
| 536 | isValid = false; |
| 537 | } |
| 538 | if (mComposerCallback->getInvalidVsyncPeriodChangeCount() != 0) { |
| 539 | ALOGE("Invalid vsync period change count"); |
| 540 | isValid = false; |
| 541 | } |
| 542 | if (mComposerCallback->getInvalidSeamlessPossibleCount() != 0) { |
| 543 | ALOGE("Invalid seamless possible count"); |
| 544 | isValid = false; |
| 545 | } |
| 546 | } |
| 547 | return isValid; |
| 548 | } |
| 549 | |
| 550 | bool VtsComposerClient::destroyAllLayers() { |
JihCheng Chiu | d0dbe4e | 2022-06-11 01:53:11 +0800 | [diff] [blame] | 551 | std::unordered_map<int64_t, DisplayResource> physicalDisplays; |
| 552 | while (!mDisplayResources.empty()) { |
| 553 | const auto& it = mDisplayResources.begin(); |
| 554 | const auto& [display, resource] = *it; |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 555 | |
JihCheng Chiu | d0dbe4e | 2022-06-11 01:53:11 +0800 | [diff] [blame] | 556 | while (!resource.layers.empty()) { |
| 557 | auto layer = *resource.layers.begin(); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 558 | const auto status = destroyLayer(display, layer); |
| 559 | if (!status.isOk()) { |
| 560 | ALOGE("Unable to destroy all the layers, failed at layer %" PRId64 " with error %s", |
| 561 | layer, status.getDescription().c_str()); |
| 562 | return false; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | if (resource.isVirtual) { |
| 567 | const auto status = destroyVirtualDisplay(display); |
| 568 | if (!status.isOk()) { |
| 569 | ALOGE("Unable to destroy the display %" PRId64 " failed with error %s", display, |
| 570 | status.getDescription().c_str()); |
| 571 | return false; |
| 572 | } |
JihCheng Chiu | d0dbe4e | 2022-06-11 01:53:11 +0800 | [diff] [blame] | 573 | } else { |
| 574 | auto extractIter = mDisplayResources.extract(it); |
| 575 | physicalDisplays.insert(std::move(extractIter)); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 576 | } |
| 577 | } |
JihCheng Chiu | d0dbe4e | 2022-06-11 01:53:11 +0800 | [diff] [blame] | 578 | mDisplayResources.swap(physicalDisplays); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 579 | mDisplayResources.clear(); |
| 580 | return true; |
| 581 | } |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 582 | } // namespace aidl::android::hardware::graphics::composer3::vts |