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)); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 73 | mClient->executeCommands(commandLength, commandHandles, |
| 74 | [&](const auto& tmpError, const auto& tmpOutQueueChanged, |
| 75 | const auto& tmpOutLength, const auto& tmpOutHandles) { |
| 76 | ASSERT_EQ(Error::NONE, tmpError); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 77 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 78 | if (tmpOutQueueChanged) { |
| 79 | mClient->getOutputCommandQueue( |
| 80 | [&](const auto& tmpError, const auto& tmpDescriptor) { |
| 81 | ASSERT_EQ(Error::NONE, tmpError); |
| 82 | reader->setMQDescriptor(tmpDescriptor); |
| 83 | }); |
| 84 | } |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 85 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 86 | ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles)); |
| 87 | reader->parse(); |
| 88 | }); |
Valerie Hau | cbe8e9a | 2018-09-17 10:58:03 -0700 | [diff] [blame] | 89 | reader->reset(); |
| 90 | writer->reset(); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 93 | Display ComposerClient::createVirtualDisplay_2_2(uint32_t width, uint32_t height, |
| 94 | PixelFormat formatHint, |
| 95 | uint32_t outputBufferSlotCount, |
| 96 | PixelFormat* outFormat) { |
Peiyong Lin | a2acfa2 | 2018-03-28 12:09:42 -0700 | [diff] [blame] | 97 | Display display = 0; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 98 | mClient->createVirtualDisplay_2_2( |
Peiyong Lin | a2acfa2 | 2018-03-28 12:09:42 -0700 | [diff] [blame] | 99 | width, height, formatHint, outputBufferSlotCount, |
| 100 | [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) { |
| 101 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display"; |
| 102 | display = tmpDisplay; |
| 103 | *outFormat = tmpFormat; |
| 104 | |
| 105 | ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second) |
| 106 | << "duplicated virtual display id " << display; |
| 107 | }); |
| 108 | |
| 109 | return display; |
| 110 | } |
| 111 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 112 | bool ComposerClient::getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height, |
| 113 | PixelFormat format, Dataspace dataspace) { |
| 114 | Error error = mClient->getClientTargetSupport_2_2(display, width, height, format, dataspace); |
Peiyong Lin | a2acfa2 | 2018-03-28 12:09:42 -0700 | [diff] [blame] | 115 | return error == Error::NONE; |
| 116 | } |
| 117 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 118 | void ComposerClient::setPowerMode_2_2(Display display, IComposerClient::PowerMode mode) { |
| 119 | Error error = mClient->setPowerMode_2_2(display, mode); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 120 | ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode"; |
| 121 | } |
| 122 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 123 | void ComposerClient::setReadbackBuffer(Display display, const native_handle_t* buffer, |
| 124 | int32_t /* releaseFence */) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 125 | // Ignoring fence, HIDL doesn't care |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 126 | Error error = mClient->setReadbackBuffer(display, buffer, nullptr); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 127 | ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer"; |
| 128 | } |
| 129 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 130 | void ComposerClient::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat, |
| 131 | Dataspace* outDataspace) { |
| 132 | mClient->getReadbackBufferAttributes( |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 133 | display, |
| 134 | [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) { |
| 135 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes"; |
| 136 | *outPixelFormat = tmpOutPixelFormat; |
| 137 | *outDataspace = tmpOutDataspace; |
| 138 | }); |
| 139 | } |
| 140 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 141 | void ComposerClient::getReadbackBufferFence(Display display, int32_t* outFence) { |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 142 | mClient->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) { |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 143 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence"; |
Valerie Hau | 667f11a | 2018-08-01 12:58:44 -0700 | [diff] [blame] | 144 | const native_handle_t* nativeFenceHandle = tmpHandle.getNativeHandle(); |
| 145 | *outFence = dup(nativeFenceHandle->data[0]); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 146 | }); |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 149 | std::vector<ColorMode> ComposerClient::getColorModes(Display display) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 150 | std::vector<ColorMode> modes; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 151 | mClient->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 152 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes"; |
| 153 | modes = tmpModes; |
| 154 | }); |
| 155 | return modes; |
| 156 | } |
| 157 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 158 | std::vector<RenderIntent> ComposerClient::getRenderIntents(Display display, ColorMode mode) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 159 | std::vector<RenderIntent> intents; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 160 | mClient->getRenderIntents(display, mode, [&](const auto& tmpError, const auto& tmpIntents) { |
| 161 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents"; |
| 162 | intents = tmpIntents; |
| 163 | }); |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 164 | return intents; |
| 165 | } |
| 166 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 167 | void ComposerClient::setColorMode(Display display, ColorMode mode, RenderIntent intent) { |
| 168 | Error error = mClient->setColorMode_2_2(display, mode, intent); |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 169 | ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode"; |
| 170 | } |
| 171 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 172 | std::array<float, 16> ComposerClient::getDataspaceSaturationMatrix(Dataspace dataspace) { |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 173 | std::array<float, 16> matrix; |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 174 | mClient->getDataspaceSaturationMatrix( |
Chia-I Wu | 6c8257f | 2018-02-28 12:24:42 -0800 | [diff] [blame] | 175 | dataspace, [&](const auto& tmpError, const auto& tmpMatrix) { |
| 176 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix"; |
| 177 | std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin()); |
| 178 | }); |
| 179 | |
| 180 | return matrix; |
| 181 | } |
| 182 | |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 183 | Gralloc::Gralloc() { |
| 184 | [this] { |
| 185 | ALOGD("Attempting to initialize gralloc3"); |
| 186 | ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default", |
| 187 | /*errOnFailure=*/false)); |
| 188 | if (mGralloc3->getMapper() == nullptr || mGralloc3->getAllocator() == nullptr) { |
| 189 | mGralloc3 = nullptr; |
| 190 | ALOGD("Failed to initialize gralloc3, initializing gralloc2_1"); |
| 191 | mGralloc2_1 = std::make_shared<Gralloc2_1>(/*errOnFailure*/ false); |
| 192 | if (!mGralloc2_1->getMapper()) { |
| 193 | mGralloc2_1 = nullptr; |
| 194 | ALOGD("Failed to initialize gralloc2_1, initializing gralloc2"); |
| 195 | ASSERT_NO_FATAL_FAILURE(mGralloc2 = std::make_shared<Gralloc2>()); |
| 196 | } |
| 197 | } |
| 198 | }(); |
| 199 | } |
| 200 | |
| 201 | bool Gralloc::validateBufferSize(const native_handle_t* bufferHandle, uint32_t width, |
| 202 | uint32_t height, uint32_t layerCount, PixelFormat format, |
| 203 | uint64_t usage, uint32_t stride) { |
| 204 | if (mGralloc3) { |
| 205 | IMapper3::BufferDescriptorInfo info{}; |
| 206 | info.width = width; |
| 207 | info.height = height; |
| 208 | info.layerCount = layerCount; |
| 209 | info.format = static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format); |
| 210 | info.usage = usage; |
| 211 | return mGralloc3->validateBufferSize(bufferHandle, info, stride); |
| 212 | } else if (mGralloc2_1) { |
| 213 | IMapper2_1::BufferDescriptorInfo info{}; |
| 214 | info.width = width; |
| 215 | info.height = height; |
| 216 | info.layerCount = layerCount; |
| 217 | info.format = static_cast<android::hardware::graphics::common::V1_1::PixelFormat>(format); |
| 218 | info.usage = usage; |
| 219 | return mGralloc2_1->validateBufferSize(bufferHandle, info, stride); |
| 220 | } else { |
| 221 | return true; |
| 222 | } |
| 223 | } |
| 224 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 225 | } // namespace vts |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 226 | } // namespace V2_2 |
| 227 | } // namespace composer |
| 228 | } // namespace graphics |
| 229 | } // namespace hardware |
| 230 | } // namespace android |