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 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 30 | using details::canCastInterface; |
| 31 | using details::getDescriptor; |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 32 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 33 | std::unique_ptr<ComposerClient> Composer::createClient() { |
| 34 | std::unique_ptr<ComposerClient> client; |
| 35 | getRaw()->createClient([&](const auto& tmpError, const auto& tmpClient) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 36 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; |
| 37 | ALOGV("tmpClient is a %s", getDescriptor(&(*tmpClient)).c_str()); |
| 38 | ASSERT_TRUE(canCastInterface( |
| 39 | &(*tmpClient), "android.hardware.graphics.composer@2.2::IComposerClient", false)) |
| 40 | << "Cannot create 2.2 IComposerClient"; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 41 | client = std::make_unique<ComposerClient>(IComposerClient::castFrom(tmpClient, true)); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 42 | }); |
| 43 | |
| 44 | return client; |
| 45 | } |
| 46 | |
Chia-I Wu | 76630c6 | 2018-05-22 12:52:36 -0700 | [diff] [blame] | 47 | sp<IComposerClient> ComposerClient::getRaw() const { |
| 48 | return mClient; |
| 49 | } |
| 50 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 51 | std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient::getPerFrameMetadataKeys( |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 52 | Display display) { |
| 53 | std::vector<IComposerClient::PerFrameMetadataKey> keys; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 54 | mClient->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 55 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys"; |
| 56 | keys = tmpKeys; |
| 57 | }); |
| 58 | |
| 59 | return keys; |
| 60 | } |
| 61 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 62 | void ComposerClient::execute(V2_1::vts::TestCommandReader* reader, CommandWriterBase* writer) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 63 | bool queueChanged = false; |
| 64 | uint32_t commandLength = 0; |
| 65 | hidl_vec<hidl_handle> commandHandles; |
| 66 | ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles)); |
| 67 | |
| 68 | if (queueChanged) { |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 69 | auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor()); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 70 | ASSERT_EQ(Error::NONE, static_cast<Error>(ret)); |
| 71 | return; |
| 72 | } |
| 73 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 74 | mClient->executeCommands(commandLength, commandHandles, |
| 75 | [&](const auto& tmpError, const auto& tmpOutQueueChanged, |
| 76 | const auto& tmpOutLength, const auto& tmpOutHandles) { |
| 77 | ASSERT_EQ(Error::NONE, tmpError); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 78 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 79 | if (tmpOutQueueChanged) { |
| 80 | mClient->getOutputCommandQueue( |
| 81 | [&](const auto& tmpError, const auto& tmpDescriptor) { |
| 82 | ASSERT_EQ(Error::NONE, tmpError); |
| 83 | reader->setMQDescriptor(tmpDescriptor); |
| 84 | }); |
| 85 | } |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 86 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 87 | ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles)); |
| 88 | reader->parse(); |
| 89 | }); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 92 | Display ComposerClient::createVirtualDisplay_2_2(uint32_t width, uint32_t height, |
| 93 | PixelFormat formatHint, |
| 94 | uint32_t outputBufferSlotCount, |
| 95 | PixelFormat* outFormat) { |
Peiyong Lin | a2acfa2 | 2018-03-28 12:09:42 -0700 | [diff] [blame] | 96 | Display display = 0; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 97 | mClient->createVirtualDisplay_2_2( |
Peiyong Lin | a2acfa2 | 2018-03-28 12:09:42 -0700 | [diff] [blame] | 98 | width, height, formatHint, outputBufferSlotCount, |
| 99 | [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) { |
| 100 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display"; |
| 101 | display = tmpDisplay; |
| 102 | *outFormat = tmpFormat; |
| 103 | |
| 104 | ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second) |
| 105 | << "duplicated virtual display id " << display; |
| 106 | }); |
| 107 | |
| 108 | return display; |
| 109 | } |
| 110 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 111 | bool ComposerClient::getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height, |
| 112 | PixelFormat format, Dataspace dataspace) { |
| 113 | Error error = mClient->getClientTargetSupport_2_2(display, width, height, format, dataspace); |
Peiyong Lin | a2acfa2 | 2018-03-28 12:09:42 -0700 | [diff] [blame] | 114 | return error == Error::NONE; |
| 115 | } |
| 116 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 117 | void ComposerClient::setPowerMode_2_2(Display display, IComposerClient::PowerMode mode) { |
| 118 | Error error = mClient->setPowerMode_2_2(display, mode); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 119 | ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode"; |
| 120 | } |
| 121 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 122 | void ComposerClient::setReadbackBuffer(Display display, const native_handle_t* buffer, |
| 123 | int32_t /* releaseFence */) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 124 | // Ignoring fence, HIDL doesn't care |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 125 | Error error = mClient->setReadbackBuffer(display, buffer, nullptr); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 126 | ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer"; |
| 127 | } |
| 128 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 129 | void ComposerClient::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat, |
| 130 | Dataspace* outDataspace) { |
| 131 | mClient->getReadbackBufferAttributes( |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 132 | display, |
| 133 | [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) { |
| 134 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes"; |
| 135 | *outPixelFormat = tmpOutPixelFormat; |
| 136 | *outDataspace = tmpOutDataspace; |
| 137 | }); |
| 138 | } |
| 139 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 140 | void ComposerClient::getReadbackBufferFence(Display display, int32_t* outFence) { |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 141 | mClient->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 142 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence"; |
Valerie Hau | 667f11a | 2018-08-01 12:58:44 -0700 | [diff] [blame^] | 143 | const native_handle_t* nativeFenceHandle = tmpHandle.getNativeHandle(); |
| 144 | *outFence = dup(nativeFenceHandle->data[0]); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 145 | }); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 148 | std::vector<ColorMode> ComposerClient::getColorModes(Display display) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 149 | std::vector<ColorMode> modes; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 150 | mClient->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 151 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes"; |
| 152 | modes = tmpModes; |
| 153 | }); |
| 154 | return modes; |
| 155 | } |
| 156 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 157 | std::vector<RenderIntent> ComposerClient::getRenderIntents(Display display, ColorMode mode) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 158 | std::vector<RenderIntent> intents; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 159 | mClient->getRenderIntents(display, mode, [&](const auto& tmpError, const auto& tmpIntents) { |
| 160 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents"; |
| 161 | intents = tmpIntents; |
| 162 | }); |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 163 | return intents; |
| 164 | } |
| 165 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 166 | void ComposerClient::setColorMode(Display display, ColorMode mode, RenderIntent intent) { |
| 167 | Error error = mClient->setColorMode_2_2(display, mode, intent); |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 168 | ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode"; |
| 169 | } |
| 170 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 171 | std::array<float, 16> ComposerClient::getDataspaceSaturationMatrix(Dataspace dataspace) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 172 | std::array<float, 16> matrix; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 173 | mClient->getDataspaceSaturationMatrix( |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 174 | dataspace, [&](const auto& tmpError, const auto& tmpMatrix) { |
| 175 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix"; |
| 176 | std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin()); |
| 177 | }); |
| 178 | |
| 179 | return matrix; |
| 180 | } |
| 181 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 182 | } // namespace vts |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 183 | } // namespace V2_2 |
| 184 | } // namespace composer |
| 185 | } // namespace graphics |
| 186 | } // namespace hardware |
| 187 | } // namespace android |