Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 17 | #include <VtsHalHidlTargetTestBase.h> |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 18 | |
| 19 | #include "VtsHalGraphicsComposerTestUtils.h" |
| 20 | |
| 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace graphics { |
| 24 | namespace composer { |
| 25 | namespace V2_1 { |
| 26 | namespace tests { |
| 27 | |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 28 | Composer::Composer() { |
| 29 | mComposer = ::testing::VtsHalHidlTargetTestBase::getService<IComposer>(); |
| 30 | init(); |
| 31 | } |
| 32 | |
| 33 | Composer::Composer(const std::string& name) { |
| 34 | mComposer = ::testing::VtsHalHidlTargetTestBase::getService<IComposer>(name); |
| 35 | init(); |
| 36 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 37 | |
| 38 | void Composer::init() { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 39 | ASSERT_NE(nullptr, mComposer.get()) << "failed to get composer service"; |
| 40 | |
| 41 | std::vector<IComposer::Capability> capabilities = getCapabilities(); |
| 42 | mCapabilities.insert(capabilities.begin(), capabilities.end()); |
| 43 | } |
| 44 | |
| 45 | sp<IComposer> Composer::getRaw() const { return mComposer; } |
| 46 | |
| 47 | bool Composer::hasCapability(IComposer::Capability capability) const { |
| 48 | return mCapabilities.count(capability) > 0; |
| 49 | } |
| 50 | |
| 51 | std::vector<IComposer::Capability> Composer::getCapabilities() { |
| 52 | std::vector<IComposer::Capability> capabilities; |
| 53 | mComposer->getCapabilities( |
| 54 | [&](const auto& tmpCapabilities) { capabilities = tmpCapabilities; }); |
| 55 | |
| 56 | return capabilities; |
| 57 | } |
| 58 | |
| 59 | std::string Composer::dumpDebugInfo() { |
| 60 | std::string debugInfo; |
| 61 | mComposer->dumpDebugInfo( |
| 62 | [&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); }); |
| 63 | |
| 64 | return debugInfo; |
| 65 | } |
| 66 | |
| 67 | std::unique_ptr<ComposerClient> Composer::createClient() { |
| 68 | std::unique_ptr<ComposerClient> client; |
| 69 | mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) { |
| 70 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; |
| 71 | client = std::make_unique<ComposerClient>(tmpClient); |
| 72 | }); |
| 73 | |
| 74 | return client; |
| 75 | } |
| 76 | |
| 77 | ComposerClient::ComposerClient(const sp<IComposerClient>& client) |
| 78 | : mClient(client) {} |
| 79 | |
| 80 | ComposerClient::~ComposerClient() { |
| 81 | for (auto it : mDisplayResources) { |
| 82 | Display display = it.first; |
| 83 | DisplayResource& resource = it.second; |
| 84 | |
| 85 | for (auto layer : resource.layers) { |
| 86 | EXPECT_EQ(Error::NONE, mClient->destroyLayer(display, layer)) |
| 87 | << "failed to destroy layer " << layer; |
| 88 | } |
| 89 | |
| 90 | if (resource.isVirtual) { |
| 91 | EXPECT_EQ(Error::NONE, mClient->destroyVirtualDisplay(display)) |
| 92 | << "failed to destroy virtual display " << display; |
| 93 | } |
| 94 | } |
| 95 | mDisplayResources.clear(); |
| 96 | } |
| 97 | |
| 98 | sp<IComposerClient> ComposerClient::getRaw() const { return mClient; } |
| 99 | |
| 100 | void ComposerClient::registerCallback(const sp<IComposerCallback>& callback) { |
| 101 | mClient->registerCallback(callback); |
| 102 | } |
| 103 | |
| 104 | uint32_t ComposerClient::getMaxVirtualDisplayCount() { |
| 105 | return mClient->getMaxVirtualDisplayCount(); |
| 106 | } |
| 107 | |
| 108 | Display ComposerClient::createVirtualDisplay(uint32_t width, uint32_t height, |
| 109 | PixelFormat formatHint, |
| 110 | uint32_t outputBufferSlotCount, |
| 111 | PixelFormat* outFormat) { |
| 112 | Display display = 0; |
| 113 | mClient->createVirtualDisplay( |
| 114 | width, height, formatHint, outputBufferSlotCount, |
| 115 | [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) { |
| 116 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display"; |
| 117 | display = tmpDisplay; |
| 118 | *outFormat = tmpFormat; |
| 119 | |
| 120 | ASSERT_TRUE( |
| 121 | mDisplayResources.insert({display, DisplayResource(true)}).second) |
| 122 | << "duplicated virtual display id " << display; |
| 123 | }); |
| 124 | |
| 125 | return display; |
| 126 | } |
| 127 | |
| 128 | void ComposerClient::destroyVirtualDisplay(Display display) { |
| 129 | Error error = mClient->destroyVirtualDisplay(display); |
| 130 | ASSERT_EQ(Error::NONE, error) |
| 131 | << "failed to destroy virtual display " << display; |
| 132 | |
| 133 | mDisplayResources.erase(display); |
| 134 | } |
| 135 | |
| 136 | Layer ComposerClient::createLayer(Display display, uint32_t bufferSlotCount) { |
| 137 | Layer layer = 0; |
| 138 | mClient->createLayer( |
| 139 | display, bufferSlotCount, |
| 140 | [&](const auto& tmpError, const auto& tmpLayer) { |
| 141 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create layer"; |
| 142 | layer = tmpLayer; |
| 143 | |
| 144 | auto resourceIt = mDisplayResources.find(display); |
| 145 | if (resourceIt == mDisplayResources.end()) { |
| 146 | resourceIt = |
| 147 | mDisplayResources.insert({display, DisplayResource(false)}).first; |
| 148 | } |
| 149 | |
| 150 | ASSERT_TRUE(resourceIt->second.layers.insert(layer).second) |
| 151 | << "duplicated layer id " << layer; |
| 152 | }); |
| 153 | |
| 154 | return layer; |
| 155 | } |
| 156 | |
| 157 | void ComposerClient::destroyLayer(Display display, Layer layer) { |
| 158 | Error error = mClient->destroyLayer(display, layer); |
| 159 | ASSERT_EQ(Error::NONE, error) << "failed to destroy layer " << layer; |
| 160 | |
| 161 | auto resourceIt = mDisplayResources.find(display); |
| 162 | ASSERT_NE(mDisplayResources.end(), resourceIt); |
| 163 | resourceIt->second.layers.erase(layer); |
| 164 | } |
| 165 | |
| 166 | Config ComposerClient::getActiveConfig(Display display) { |
| 167 | Config config = 0; |
| 168 | mClient->getActiveConfig( |
| 169 | display, [&](const auto& tmpError, const auto& tmpConfig) { |
| 170 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get active config"; |
| 171 | config = tmpConfig; |
| 172 | }); |
| 173 | |
| 174 | return config; |
| 175 | } |
| 176 | |
| 177 | bool ComposerClient::getClientTargetSupport(Display display, uint32_t width, |
| 178 | uint32_t height, PixelFormat format, |
| 179 | Dataspace dataspace) { |
| 180 | Error error = mClient->getClientTargetSupport(display, width, height, format, |
| 181 | dataspace); |
| 182 | return error == Error::NONE; |
| 183 | } |
| 184 | |
| 185 | std::vector<ColorMode> ComposerClient::getColorModes(Display display) { |
| 186 | std::vector<ColorMode> modes; |
| 187 | mClient->getColorModes( |
| 188 | display, [&](const auto& tmpError, const auto& tmpMode) { |
| 189 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get color mode"; |
| 190 | modes = tmpMode; |
| 191 | }); |
| 192 | |
| 193 | return modes; |
| 194 | } |
| 195 | |
| 196 | int32_t ComposerClient::getDisplayAttribute( |
| 197 | Display display, Config config, IComposerClient::Attribute attribute) { |
| 198 | int32_t value = 0; |
| 199 | mClient->getDisplayAttribute(display, config, attribute, |
| 200 | [&](const auto& tmpError, const auto& tmpValue) { |
| 201 | ASSERT_EQ(Error::NONE, tmpError) |
| 202 | << "failed to get display attribute"; |
| 203 | value = tmpValue; |
| 204 | }); |
| 205 | |
| 206 | return value; |
| 207 | } |
| 208 | |
| 209 | std::vector<Config> ComposerClient::getDisplayConfigs(Display display) { |
| 210 | std::vector<Config> configs; |
| 211 | mClient->getDisplayConfigs( |
| 212 | display, [&](const auto& tmpError, const auto& tmpConfigs) { |
| 213 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display configs"; |
| 214 | configs = tmpConfigs; |
| 215 | }); |
| 216 | |
| 217 | return configs; |
| 218 | } |
| 219 | |
| 220 | std::string ComposerClient::getDisplayName(Display display) { |
| 221 | std::string name; |
| 222 | mClient->getDisplayName( |
| 223 | display, [&](const auto& tmpError, const auto& tmpName) { |
| 224 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display name"; |
| 225 | name = tmpName.c_str(); |
| 226 | }); |
| 227 | |
| 228 | return name; |
| 229 | } |
| 230 | |
| 231 | IComposerClient::DisplayType ComposerClient::getDisplayType(Display display) { |
| 232 | IComposerClient::DisplayType type = IComposerClient::DisplayType::INVALID; |
| 233 | mClient->getDisplayType( |
| 234 | display, [&](const auto& tmpError, const auto& tmpType) { |
| 235 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display type"; |
| 236 | type = tmpType; |
| 237 | }); |
| 238 | |
| 239 | return type; |
| 240 | } |
| 241 | |
| 242 | bool ComposerClient::getDozeSupport(Display display) { |
| 243 | bool support = false; |
| 244 | mClient->getDozeSupport( |
| 245 | display, [&](const auto& tmpError, const auto& tmpSupport) { |
| 246 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get doze support"; |
| 247 | support = tmpSupport; |
| 248 | }); |
| 249 | |
| 250 | return support; |
| 251 | } |
| 252 | |
| 253 | std::vector<Hdr> ComposerClient::getHdrCapabilities( |
| 254 | Display display, float* outMaxLuminance, float* outMaxAverageLuminance, |
| 255 | float* outMinLuminance) { |
| 256 | std::vector<Hdr> types; |
| 257 | mClient->getHdrCapabilities( |
| 258 | display, |
| 259 | [&](const auto& tmpError, const auto& tmpTypes, |
| 260 | const auto& tmpMaxLuminance, const auto& tmpMaxAverageLuminance, |
| 261 | const auto& tmpMinLuminance) { |
| 262 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR capabilities"; |
| 263 | types = tmpTypes; |
| 264 | *outMaxLuminance = tmpMaxLuminance; |
| 265 | *outMaxAverageLuminance = tmpMaxAverageLuminance; |
| 266 | *outMinLuminance = tmpMinLuminance; |
| 267 | }); |
| 268 | |
| 269 | return types; |
| 270 | } |
| 271 | |
| 272 | void ComposerClient::setClientTargetSlotCount(Display display, |
| 273 | uint32_t clientTargetSlotCount) { |
| 274 | Error error = |
| 275 | mClient->setClientTargetSlotCount(display, clientTargetSlotCount); |
| 276 | ASSERT_EQ(Error::NONE, error) << "failed to set client target slot count"; |
| 277 | } |
| 278 | |
| 279 | void ComposerClient::setActiveConfig(Display display, Config config) { |
| 280 | Error error = mClient->setActiveConfig(display, config); |
| 281 | ASSERT_EQ(Error::NONE, error) << "failed to set active config"; |
| 282 | } |
| 283 | |
| 284 | void ComposerClient::setColorMode(Display display, ColorMode mode) { |
| 285 | Error error = mClient->setColorMode(display, mode); |
| 286 | ASSERT_EQ(Error::NONE, error) << "failed to set color mode"; |
| 287 | } |
| 288 | |
| 289 | void ComposerClient::setPowerMode(Display display, |
| 290 | IComposerClient::PowerMode mode) { |
| 291 | Error error = mClient->setPowerMode(display, mode); |
| 292 | ASSERT_EQ(Error::NONE, error) << "failed to set power mode"; |
| 293 | } |
| 294 | |
| 295 | void ComposerClient::setVsyncEnabled(Display display, bool enabled) { |
| 296 | IComposerClient::Vsync vsync = (enabled) ? IComposerClient::Vsync::ENABLE |
| 297 | : IComposerClient::Vsync::DISABLE; |
| 298 | Error error = mClient->setVsyncEnabled(display, vsync); |
| 299 | ASSERT_EQ(Error::NONE, error) << "failed to set vsync mode"; |
Chia-I Wu | 4f49038 | 2017-07-24 11:11:01 -0700 | [diff] [blame^] | 300 | |
| 301 | // give the hwbinder thread some time to handle any pending vsync callback |
| 302 | if (!enabled) { |
| 303 | usleep(5 * 1000); |
| 304 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 307 | void ComposerClient::execute(TestCommandReader* reader, |
| 308 | CommandWriterBase* writer) { |
| 309 | bool queueChanged = false; |
| 310 | uint32_t commandLength = 0; |
| 311 | hidl_vec<hidl_handle> commandHandles; |
| 312 | ASSERT_TRUE( |
| 313 | writer->writeQueue(&queueChanged, &commandLength, &commandHandles)); |
| 314 | |
| 315 | if (queueChanged) { |
| 316 | auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor()); |
| 317 | ASSERT_EQ(Error::NONE, static_cast<Error>(ret)); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | mClient->executeCommands( |
| 322 | commandLength, commandHandles, |
| 323 | [&](const auto& tmpError, const auto& tmpOutQueueChanged, |
| 324 | const auto& tmpOutLength, const auto& tmpOutHandles) { |
| 325 | ASSERT_EQ(Error::NONE, tmpError); |
| 326 | |
| 327 | if (tmpOutQueueChanged) { |
| 328 | mClient->getOutputCommandQueue( |
| 329 | [&](const auto& tmpError, const auto& tmpDescriptor) { |
| 330 | ASSERT_EQ(Error::NONE, tmpError); |
| 331 | reader->setMQDescriptor(tmpDescriptor); |
| 332 | }); |
| 333 | } |
| 334 | |
| 335 | ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles)); |
| 336 | reader->parse(); |
| 337 | }); |
| 338 | } |
| 339 | |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 340 | } // namespace tests |
| 341 | } // namespace V2_1 |
| 342 | } // namespace composer |
| 343 | } // namespace graphics |
| 344 | } // namespace hardware |
| 345 | } // namespace android |