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 | |
| 17 | #include <VtsHalHidlTargetBaseTest.h> |
| 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 | |
| 28 | Composer::Composer() { init(); } |
| 29 | |
| 30 | void Composer::init() { |
| 31 | mComposer = ::testing::VtsHalHidlTargetBaseTest::getService<IComposer>(); |
| 32 | ASSERT_NE(nullptr, mComposer.get()) << "failed to get composer service"; |
| 33 | |
| 34 | std::vector<IComposer::Capability> capabilities = getCapabilities(); |
| 35 | mCapabilities.insert(capabilities.begin(), capabilities.end()); |
| 36 | } |
| 37 | |
| 38 | sp<IComposer> Composer::getRaw() const { return mComposer; } |
| 39 | |
| 40 | bool Composer::hasCapability(IComposer::Capability capability) const { |
| 41 | return mCapabilities.count(capability) > 0; |
| 42 | } |
| 43 | |
| 44 | std::vector<IComposer::Capability> Composer::getCapabilities() { |
| 45 | std::vector<IComposer::Capability> capabilities; |
| 46 | mComposer->getCapabilities( |
| 47 | [&](const auto& tmpCapabilities) { capabilities = tmpCapabilities; }); |
| 48 | |
| 49 | return capabilities; |
| 50 | } |
| 51 | |
| 52 | std::string Composer::dumpDebugInfo() { |
| 53 | std::string debugInfo; |
| 54 | mComposer->dumpDebugInfo( |
| 55 | [&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); }); |
| 56 | |
| 57 | return debugInfo; |
| 58 | } |
| 59 | |
| 60 | std::unique_ptr<ComposerClient> Composer::createClient() { |
| 61 | std::unique_ptr<ComposerClient> client; |
| 62 | mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) { |
| 63 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; |
| 64 | client = std::make_unique<ComposerClient>(tmpClient); |
| 65 | }); |
| 66 | |
| 67 | return client; |
| 68 | } |
| 69 | |
| 70 | ComposerClient::ComposerClient(const sp<IComposerClient>& client) |
| 71 | : mClient(client) {} |
| 72 | |
| 73 | ComposerClient::~ComposerClient() { |
| 74 | for (auto it : mDisplayResources) { |
| 75 | Display display = it.first; |
| 76 | DisplayResource& resource = it.second; |
| 77 | |
| 78 | for (auto layer : resource.layers) { |
| 79 | EXPECT_EQ(Error::NONE, mClient->destroyLayer(display, layer)) |
| 80 | << "failed to destroy layer " << layer; |
| 81 | } |
| 82 | |
| 83 | if (resource.isVirtual) { |
| 84 | EXPECT_EQ(Error::NONE, mClient->destroyVirtualDisplay(display)) |
| 85 | << "failed to destroy virtual display " << display; |
| 86 | } |
| 87 | } |
| 88 | mDisplayResources.clear(); |
| 89 | } |
| 90 | |
| 91 | sp<IComposerClient> ComposerClient::getRaw() const { return mClient; } |
| 92 | |
| 93 | void ComposerClient::registerCallback(const sp<IComposerCallback>& callback) { |
| 94 | mClient->registerCallback(callback); |
| 95 | } |
| 96 | |
| 97 | uint32_t ComposerClient::getMaxVirtualDisplayCount() { |
| 98 | return mClient->getMaxVirtualDisplayCount(); |
| 99 | } |
| 100 | |
| 101 | Display ComposerClient::createVirtualDisplay(uint32_t width, uint32_t height, |
| 102 | PixelFormat formatHint, |
| 103 | uint32_t outputBufferSlotCount, |
| 104 | PixelFormat* outFormat) { |
| 105 | Display display = 0; |
| 106 | mClient->createVirtualDisplay( |
| 107 | width, height, formatHint, outputBufferSlotCount, |
| 108 | [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) { |
| 109 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display"; |
| 110 | display = tmpDisplay; |
| 111 | *outFormat = tmpFormat; |
| 112 | |
| 113 | ASSERT_TRUE( |
| 114 | mDisplayResources.insert({display, DisplayResource(true)}).second) |
| 115 | << "duplicated virtual display id " << display; |
| 116 | }); |
| 117 | |
| 118 | return display; |
| 119 | } |
| 120 | |
| 121 | void ComposerClient::destroyVirtualDisplay(Display display) { |
| 122 | Error error = mClient->destroyVirtualDisplay(display); |
| 123 | ASSERT_EQ(Error::NONE, error) |
| 124 | << "failed to destroy virtual display " << display; |
| 125 | |
| 126 | mDisplayResources.erase(display); |
| 127 | } |
| 128 | |
| 129 | Layer ComposerClient::createLayer(Display display, uint32_t bufferSlotCount) { |
| 130 | Layer layer = 0; |
| 131 | mClient->createLayer( |
| 132 | display, bufferSlotCount, |
| 133 | [&](const auto& tmpError, const auto& tmpLayer) { |
| 134 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create layer"; |
| 135 | layer = tmpLayer; |
| 136 | |
| 137 | auto resourceIt = mDisplayResources.find(display); |
| 138 | if (resourceIt == mDisplayResources.end()) { |
| 139 | resourceIt = |
| 140 | mDisplayResources.insert({display, DisplayResource(false)}).first; |
| 141 | } |
| 142 | |
| 143 | ASSERT_TRUE(resourceIt->second.layers.insert(layer).second) |
| 144 | << "duplicated layer id " << layer; |
| 145 | }); |
| 146 | |
| 147 | return layer; |
| 148 | } |
| 149 | |
| 150 | void ComposerClient::destroyLayer(Display display, Layer layer) { |
| 151 | Error error = mClient->destroyLayer(display, layer); |
| 152 | ASSERT_EQ(Error::NONE, error) << "failed to destroy layer " << layer; |
| 153 | |
| 154 | auto resourceIt = mDisplayResources.find(display); |
| 155 | ASSERT_NE(mDisplayResources.end(), resourceIt); |
| 156 | resourceIt->second.layers.erase(layer); |
| 157 | } |
| 158 | |
| 159 | Config ComposerClient::getActiveConfig(Display display) { |
| 160 | Config config = 0; |
| 161 | mClient->getActiveConfig( |
| 162 | display, [&](const auto& tmpError, const auto& tmpConfig) { |
| 163 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get active config"; |
| 164 | config = tmpConfig; |
| 165 | }); |
| 166 | |
| 167 | return config; |
| 168 | } |
| 169 | |
| 170 | bool ComposerClient::getClientTargetSupport(Display display, uint32_t width, |
| 171 | uint32_t height, PixelFormat format, |
| 172 | Dataspace dataspace) { |
| 173 | Error error = mClient->getClientTargetSupport(display, width, height, format, |
| 174 | dataspace); |
| 175 | return error == Error::NONE; |
| 176 | } |
| 177 | |
| 178 | std::vector<ColorMode> ComposerClient::getColorModes(Display display) { |
| 179 | std::vector<ColorMode> modes; |
| 180 | mClient->getColorModes( |
| 181 | display, [&](const auto& tmpError, const auto& tmpMode) { |
| 182 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get color mode"; |
| 183 | modes = tmpMode; |
| 184 | }); |
| 185 | |
| 186 | return modes; |
| 187 | } |
| 188 | |
| 189 | int32_t ComposerClient::getDisplayAttribute( |
| 190 | Display display, Config config, IComposerClient::Attribute attribute) { |
| 191 | int32_t value = 0; |
| 192 | mClient->getDisplayAttribute(display, config, attribute, |
| 193 | [&](const auto& tmpError, const auto& tmpValue) { |
| 194 | ASSERT_EQ(Error::NONE, tmpError) |
| 195 | << "failed to get display attribute"; |
| 196 | value = tmpValue; |
| 197 | }); |
| 198 | |
| 199 | return value; |
| 200 | } |
| 201 | |
| 202 | std::vector<Config> ComposerClient::getDisplayConfigs(Display display) { |
| 203 | std::vector<Config> configs; |
| 204 | mClient->getDisplayConfigs( |
| 205 | display, [&](const auto& tmpError, const auto& tmpConfigs) { |
| 206 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display configs"; |
| 207 | configs = tmpConfigs; |
| 208 | }); |
| 209 | |
| 210 | return configs; |
| 211 | } |
| 212 | |
| 213 | std::string ComposerClient::getDisplayName(Display display) { |
| 214 | std::string name; |
| 215 | mClient->getDisplayName( |
| 216 | display, [&](const auto& tmpError, const auto& tmpName) { |
| 217 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display name"; |
| 218 | name = tmpName.c_str(); |
| 219 | }); |
| 220 | |
| 221 | return name; |
| 222 | } |
| 223 | |
| 224 | IComposerClient::DisplayType ComposerClient::getDisplayType(Display display) { |
| 225 | IComposerClient::DisplayType type = IComposerClient::DisplayType::INVALID; |
| 226 | mClient->getDisplayType( |
| 227 | display, [&](const auto& tmpError, const auto& tmpType) { |
| 228 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display type"; |
| 229 | type = tmpType; |
| 230 | }); |
| 231 | |
| 232 | return type; |
| 233 | } |
| 234 | |
| 235 | bool ComposerClient::getDozeSupport(Display display) { |
| 236 | bool support = false; |
| 237 | mClient->getDozeSupport( |
| 238 | display, [&](const auto& tmpError, const auto& tmpSupport) { |
| 239 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get doze support"; |
| 240 | support = tmpSupport; |
| 241 | }); |
| 242 | |
| 243 | return support; |
| 244 | } |
| 245 | |
| 246 | std::vector<Hdr> ComposerClient::getHdrCapabilities( |
| 247 | Display display, float* outMaxLuminance, float* outMaxAverageLuminance, |
| 248 | float* outMinLuminance) { |
| 249 | std::vector<Hdr> types; |
| 250 | mClient->getHdrCapabilities( |
| 251 | display, |
| 252 | [&](const auto& tmpError, const auto& tmpTypes, |
| 253 | const auto& tmpMaxLuminance, const auto& tmpMaxAverageLuminance, |
| 254 | const auto& tmpMinLuminance) { |
| 255 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR capabilities"; |
| 256 | types = tmpTypes; |
| 257 | *outMaxLuminance = tmpMaxLuminance; |
| 258 | *outMaxAverageLuminance = tmpMaxAverageLuminance; |
| 259 | *outMinLuminance = tmpMinLuminance; |
| 260 | }); |
| 261 | |
| 262 | return types; |
| 263 | } |
| 264 | |
| 265 | void ComposerClient::setClientTargetSlotCount(Display display, |
| 266 | uint32_t clientTargetSlotCount) { |
| 267 | Error error = |
| 268 | mClient->setClientTargetSlotCount(display, clientTargetSlotCount); |
| 269 | ASSERT_EQ(Error::NONE, error) << "failed to set client target slot count"; |
| 270 | } |
| 271 | |
| 272 | void ComposerClient::setActiveConfig(Display display, Config config) { |
| 273 | Error error = mClient->setActiveConfig(display, config); |
| 274 | ASSERT_EQ(Error::NONE, error) << "failed to set active config"; |
| 275 | } |
| 276 | |
| 277 | void ComposerClient::setColorMode(Display display, ColorMode mode) { |
| 278 | Error error = mClient->setColorMode(display, mode); |
| 279 | ASSERT_EQ(Error::NONE, error) << "failed to set color mode"; |
| 280 | } |
| 281 | |
| 282 | void ComposerClient::setPowerMode(Display display, |
| 283 | IComposerClient::PowerMode mode) { |
| 284 | Error error = mClient->setPowerMode(display, mode); |
| 285 | ASSERT_EQ(Error::NONE, error) << "failed to set power mode"; |
| 286 | } |
| 287 | |
| 288 | void ComposerClient::setVsyncEnabled(Display display, bool enabled) { |
| 289 | IComposerClient::Vsync vsync = (enabled) ? IComposerClient::Vsync::ENABLE |
| 290 | : IComposerClient::Vsync::DISABLE; |
| 291 | Error error = mClient->setVsyncEnabled(display, vsync); |
| 292 | ASSERT_EQ(Error::NONE, error) << "failed to set vsync mode"; |
| 293 | } |
| 294 | |
| 295 | } // namespace tests |
| 296 | } // namespace V2_1 |
| 297 | } // namespace composer |
| 298 | } // namespace graphics |
| 299 | } // namespace hardware |
| 300 | } // namespace android |