Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 17 | #include <composer-vts/2.2/ComposerVts.h> |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 18 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 19 | #include <VtsHalHidlTargetTestBase.h> |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 20 | #include <composer-command-buffer/2.2/ComposerCommandBuffer.h> |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 21 | #include <hidl/HidlTransportUtils.h> |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace graphics { |
| 26 | namespace composer { |
| 27 | namespace V2_2 { |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 28 | namespace vts { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 29 | |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 30 | using android::hardware::details::canCastInterface; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 31 | using android::hardware::details::getDescriptor; |
| 32 | using android::hardware::graphics::composer::V2_2::IComposerClient; |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 33 | |
| 34 | std::unique_ptr<ComposerClient_v2_2> Composer_v2_2::createClient_v2_2() { |
| 35 | std::unique_ptr<ComposerClient_v2_2> client; |
| 36 | mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) { |
| 37 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; |
| 38 | ALOGV("tmpClient is a %s", getDescriptor(&(*tmpClient)).c_str()); |
| 39 | ASSERT_TRUE(canCastInterface( |
| 40 | &(*tmpClient), "android.hardware.graphics.composer@2.2::IComposerClient", false)) |
| 41 | << "Cannot create 2.2 IComposerClient"; |
| 42 | client = std::make_unique<ComposerClient_v2_2>(IComposerClient::castFrom(tmpClient, true)); |
| 43 | }); |
| 44 | |
| 45 | return client; |
| 46 | } |
| 47 | |
| 48 | std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient_v2_2::getPerFrameMetadataKeys( |
| 49 | Display display) { |
| 50 | std::vector<IComposerClient::PerFrameMetadataKey> keys; |
| 51 | mClient_v2_2->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) { |
| 52 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys"; |
| 53 | keys = tmpKeys; |
| 54 | }); |
| 55 | |
| 56 | return keys; |
| 57 | } |
| 58 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 59 | void ComposerClient_v2_2::execute_v2_2(V2_1::vts::TestCommandReader* reader, |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 60 | V2_2::CommandWriterBase* writer) { |
| 61 | bool queueChanged = false; |
| 62 | uint32_t commandLength = 0; |
| 63 | hidl_vec<hidl_handle> commandHandles; |
| 64 | ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles)); |
| 65 | |
| 66 | if (queueChanged) { |
| 67 | auto ret = mClient_v2_2->setInputCommandQueue(*writer->getMQDescriptor()); |
| 68 | ASSERT_EQ(Error::NONE, static_cast<Error>(ret)); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | mClient_v2_2->executeCommands(commandLength, commandHandles, |
| 73 | [&](const auto& tmpError, const auto& tmpOutQueueChanged, |
| 74 | const auto& tmpOutLength, const auto& tmpOutHandles) { |
| 75 | ASSERT_EQ(Error::NONE, tmpError); |
| 76 | |
| 77 | if (tmpOutQueueChanged) { |
| 78 | mClient_v2_2->getOutputCommandQueue( |
| 79 | [&](const auto& tmpError, const auto& tmpDescriptor) { |
| 80 | ASSERT_EQ(Error::NONE, tmpError); |
| 81 | reader->setMQDescriptor(tmpDescriptor); |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles)); |
| 86 | reader->parse(); |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | void ComposerClient_v2_2::setPowerMode_2_2(Display display, V2_2::IComposerClient::PowerMode mode) { |
| 91 | Error error = mClient_v2_2->setPowerMode_2_2(display, mode); |
| 92 | ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode"; |
| 93 | } |
| 94 | |
| 95 | void ComposerClient_v2_2::setReadbackBuffer(Display display, const native_handle_t* buffer, |
| 96 | int32_t /* releaseFence */) { |
| 97 | // Ignoring fence, HIDL doesn't care |
| 98 | Error error = mClient_v2_2->setReadbackBuffer(display, buffer, nullptr); |
| 99 | ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer"; |
| 100 | } |
| 101 | |
| 102 | void ComposerClient_v2_2::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat, |
| 103 | Dataspace* outDataspace) { |
| 104 | mClient_v2_2->getReadbackBufferAttributes( |
| 105 | display, |
| 106 | [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) { |
| 107 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes"; |
| 108 | *outPixelFormat = tmpOutPixelFormat; |
| 109 | *outDataspace = tmpOutDataspace; |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | void ComposerClient_v2_2::getReadbackBufferFence(Display display, int32_t* outFence) { |
| 114 | hidl_handle handle; |
| 115 | mClient_v2_2->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) { |
| 116 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence"; |
| 117 | handle = tmpHandle; |
| 118 | }); |
| 119 | *outFence = 0; |
| 120 | } |
| 121 | |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 122 | std::vector<ColorMode> ComposerClient_v2_2::getColorModes(Display display) { |
| 123 | std::vector<ColorMode> modes; |
| 124 | mClient_v2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) { |
| 125 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes"; |
| 126 | modes = tmpModes; |
| 127 | }); |
| 128 | return modes; |
| 129 | } |
| 130 | |
| 131 | std::vector<RenderIntent> ComposerClient_v2_2::getRenderIntents(Display display, ColorMode mode) { |
| 132 | std::vector<RenderIntent> intents; |
| 133 | mClient_v2_2->getRenderIntents( |
| 134 | display, mode, [&](const auto& tmpError, const auto& tmpIntents) { |
| 135 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents"; |
| 136 | intents = tmpIntents; |
| 137 | }); |
| 138 | return intents; |
| 139 | } |
| 140 | |
| 141 | void ComposerClient_v2_2::setColorMode(Display display, ColorMode mode, RenderIntent intent) { |
| 142 | Error error = mClient_v2_2->setColorMode_2_2(display, mode, intent); |
| 143 | ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode"; |
| 144 | } |
| 145 | |
| 146 | std::array<float, 16> ComposerClient_v2_2::getDataspaceSaturationMatrix(Dataspace dataspace) { |
| 147 | std::array<float, 16> matrix; |
| 148 | mClient_v2_2->getDataspaceSaturationMatrix( |
| 149 | dataspace, [&](const auto& tmpError, const auto& tmpMatrix) { |
| 150 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix"; |
| 151 | std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin()); |
| 152 | }); |
| 153 | |
| 154 | return matrix; |
| 155 | } |
| 156 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 157 | } // namespace vts |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 158 | } // namespace V2_2 |
| 159 | } // namespace composer |
| 160 | } // namespace graphics |
| 161 | } // namespace hardware |
| 162 | } // namespace android |