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 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 17 | #include <composer-vts/2.1/ComposerVts.h> |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 18 | |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace graphics { |
| 22 | namespace composer { |
| 23 | namespace V2_1 { |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 24 | namespace vts { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 25 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 26 | Composer::Composer(const sp<IComposer>& composer) : mComposer(composer) { |
| 27 | // ASSERT_* can only be used in functions returning void. |
| 28 | [this] { |
| 29 | ASSERT_NE(nullptr, mComposer.get()) << "failed to get composer service"; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 30 | |
Dominik Laskowski | 0c41558 | 2018-04-02 15:35:00 -0700 | [diff] [blame] | 31 | std::vector<IComposer::Capability> capabilities = getCapabilities(); |
| 32 | mCapabilities.insert(capabilities.begin(), capabilities.end()); |
| 33 | }(); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 36 | sp<IComposer> Composer::getRaw() const { |
| 37 | return mComposer; |
| 38 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 39 | |
| 40 | bool Composer::hasCapability(IComposer::Capability capability) const { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 41 | return mCapabilities.count(capability) > 0; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | std::vector<IComposer::Capability> Composer::getCapabilities() { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 45 | std::vector<IComposer::Capability> capabilities; |
| 46 | mComposer->getCapabilities( |
| 47 | [&](const auto& tmpCapabilities) { capabilities = tmpCapabilities; }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 48 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 49 | return capabilities; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | std::string Composer::dumpDebugInfo() { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 53 | std::string debugInfo; |
| 54 | mComposer->dumpDebugInfo([&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 55 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 56 | return debugInfo; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | std::unique_ptr<ComposerClient> Composer::createClient() { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 60 | std::unique_ptr<ComposerClient> client; |
| 61 | mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) { |
| 62 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; |
| 63 | client = std::make_unique<ComposerClient>(tmpClient); |
| 64 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 65 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 66 | return client; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 69 | ComposerClient::ComposerClient(const sp<IComposerClient>& client) : mClient(client) {} |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 70 | |
| 71 | ComposerClient::~ComposerClient() { |
Chih-Hung Hsieh | 65ab673 | 2018-12-12 14:13:48 -0800 | [diff] [blame] | 72 | for (const auto& it : mDisplayResources) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 73 | Display display = it.first; |
Chih-Hung Hsieh | 65ab673 | 2018-12-12 14:13:48 -0800 | [diff] [blame] | 74 | const DisplayResource& resource = it.second; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 75 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 76 | for (auto layer : resource.layers) { |
| 77 | EXPECT_EQ(Error::NONE, mClient->destroyLayer(display, layer)) |
| 78 | << "failed to destroy layer " << layer; |
| 79 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 80 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 81 | if (resource.isVirtual) { |
| 82 | EXPECT_EQ(Error::NONE, mClient->destroyVirtualDisplay(display)) |
| 83 | << "failed to destroy virtual display " << display; |
| 84 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 85 | } |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 86 | mDisplayResources.clear(); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 89 | sp<IComposerClient> ComposerClient::getRaw() const { |
| 90 | return mClient; |
| 91 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 92 | |
| 93 | void ComposerClient::registerCallback(const sp<IComposerCallback>& callback) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 94 | mClient->registerCallback(callback); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | uint32_t ComposerClient::getMaxVirtualDisplayCount() { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 98 | return mClient->getMaxVirtualDisplayCount(); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | Display ComposerClient::createVirtualDisplay(uint32_t width, uint32_t height, |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 102 | PixelFormat formatHint, uint32_t outputBufferSlotCount, |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 103 | PixelFormat* outFormat) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 104 | Display display = 0; |
| 105 | mClient->createVirtualDisplay( |
| 106 | width, height, formatHint, outputBufferSlotCount, |
| 107 | [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) { |
| 108 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display"; |
| 109 | display = tmpDisplay; |
| 110 | *outFormat = tmpFormat; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 111 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 112 | ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second) |
| 113 | << "duplicated virtual display id " << display; |
| 114 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 115 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 116 | return display; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void ComposerClient::destroyVirtualDisplay(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 120 | Error error = mClient->destroyVirtualDisplay(display); |
| 121 | ASSERT_EQ(Error::NONE, error) << "failed to destroy virtual display " << display; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 122 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 123 | mDisplayResources.erase(display); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | Layer ComposerClient::createLayer(Display display, uint32_t bufferSlotCount) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 127 | Layer layer = 0; |
| 128 | mClient->createLayer(display, bufferSlotCount, [&](const auto& tmpError, const auto& tmpLayer) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 129 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create layer"; |
| 130 | layer = tmpLayer; |
| 131 | |
| 132 | auto resourceIt = mDisplayResources.find(display); |
| 133 | if (resourceIt == mDisplayResources.end()) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 134 | resourceIt = mDisplayResources.insert({display, DisplayResource(false)}).first; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | ASSERT_TRUE(resourceIt->second.layers.insert(layer).second) |
| 138 | << "duplicated layer id " << layer; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 139 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 140 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 141 | return layer; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void ComposerClient::destroyLayer(Display display, Layer layer) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 145 | Error error = mClient->destroyLayer(display, layer); |
| 146 | ASSERT_EQ(Error::NONE, error) << "failed to destroy layer " << layer; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 147 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 148 | auto resourceIt = mDisplayResources.find(display); |
| 149 | ASSERT_NE(mDisplayResources.end(), resourceIt); |
| 150 | resourceIt->second.layers.erase(layer); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | Config ComposerClient::getActiveConfig(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 154 | Config config = 0; |
| 155 | mClient->getActiveConfig(display, [&](const auto& tmpError, const auto& tmpConfig) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 156 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get active config"; |
| 157 | config = tmpConfig; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 158 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 159 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 160 | return config; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 163 | bool ComposerClient::getClientTargetSupport(Display display, uint32_t width, uint32_t height, |
| 164 | PixelFormat format, Dataspace dataspace) { |
| 165 | Error error = mClient->getClientTargetSupport(display, width, height, format, dataspace); |
| 166 | return error == Error::NONE; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | std::vector<ColorMode> ComposerClient::getColorModes(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 170 | std::vector<ColorMode> modes; |
| 171 | mClient->getColorModes(display, [&](const auto& tmpError, const auto& tmpMode) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 172 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get color mode"; |
| 173 | modes = tmpMode; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 174 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 175 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 176 | return modes; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 179 | int32_t ComposerClient::getDisplayAttribute(Display display, Config config, |
| 180 | IComposerClient::Attribute attribute) { |
| 181 | int32_t value = 0; |
| 182 | mClient->getDisplayAttribute( |
| 183 | display, config, attribute, [&](const auto& tmpError, const auto& tmpValue) { |
| 184 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display attribute"; |
| 185 | value = tmpValue; |
| 186 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 187 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 188 | return value; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | std::vector<Config> ComposerClient::getDisplayConfigs(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 192 | std::vector<Config> configs; |
| 193 | mClient->getDisplayConfigs(display, [&](const auto& tmpError, const auto& tmpConfigs) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 194 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display configs"; |
| 195 | configs = tmpConfigs; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 196 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 197 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 198 | return configs; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | std::string ComposerClient::getDisplayName(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 202 | std::string name; |
| 203 | mClient->getDisplayName(display, [&](const auto& tmpError, const auto& tmpName) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 204 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display name"; |
| 205 | name = tmpName.c_str(); |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 206 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 207 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 208 | return name; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | IComposerClient::DisplayType ComposerClient::getDisplayType(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 212 | IComposerClient::DisplayType type = IComposerClient::DisplayType::INVALID; |
| 213 | mClient->getDisplayType(display, [&](const auto& tmpError, const auto& tmpType) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 214 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get display type"; |
| 215 | type = tmpType; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 216 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 217 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 218 | return type; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | bool ComposerClient::getDozeSupport(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 222 | bool support = false; |
| 223 | mClient->getDozeSupport(display, [&](const auto& tmpError, const auto& tmpSupport) { |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 224 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get doze support"; |
| 225 | support = tmpSupport; |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 226 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 227 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 228 | return support; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 231 | std::vector<Hdr> ComposerClient::getHdrCapabilities(Display display, float* outMaxLuminance, |
| 232 | float* outMaxAverageLuminance, |
| 233 | float* outMinLuminance) { |
| 234 | std::vector<Hdr> types; |
| 235 | mClient->getHdrCapabilities( |
| 236 | display, [&](const auto& tmpError, const auto& tmpTypes, const auto& tmpMaxLuminance, |
| 237 | const auto& tmpMaxAverageLuminance, const auto& tmpMinLuminance) { |
| 238 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR capabilities"; |
| 239 | types = tmpTypes; |
| 240 | *outMaxLuminance = tmpMaxLuminance; |
| 241 | *outMaxAverageLuminance = tmpMaxAverageLuminance; |
| 242 | *outMinLuminance = tmpMinLuminance; |
| 243 | }); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 244 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 245 | return types; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 248 | void ComposerClient::setClientTargetSlotCount(Display display, uint32_t clientTargetSlotCount) { |
| 249 | Error error = mClient->setClientTargetSlotCount(display, clientTargetSlotCount); |
| 250 | ASSERT_EQ(Error::NONE, error) << "failed to set client target slot count"; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void ComposerClient::setActiveConfig(Display display, Config config) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 254 | Error error = mClient->setActiveConfig(display, config); |
| 255 | ASSERT_EQ(Error::NONE, error) << "failed to set active config"; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void ComposerClient::setColorMode(Display display, ColorMode mode) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 259 | Error error = mClient->setColorMode(display, mode); |
| 260 | ASSERT_EQ(Error::NONE, error) << "failed to set color mode"; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 263 | void ComposerClient::setPowerMode(Display display, IComposerClient::PowerMode mode) { |
| 264 | Error error = mClient->setPowerMode(display, mode); |
| 265 | ASSERT_EQ(Error::NONE, error) << "failed to set power mode"; |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void ComposerClient::setVsyncEnabled(Display display, bool enabled) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 269 | IComposerClient::Vsync vsync = |
| 270 | (enabled) ? IComposerClient::Vsync::ENABLE : IComposerClient::Vsync::DISABLE; |
| 271 | Error error = mClient->setVsyncEnabled(display, vsync); |
| 272 | ASSERT_EQ(Error::NONE, error) << "failed to set vsync mode"; |
Chia-I Wu | 4f49038 | 2017-07-24 11:11:01 -0700 | [diff] [blame] | 273 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 274 | // give the hwbinder thread some time to handle any pending vsync callback |
| 275 | if (!enabled) { |
| 276 | usleep(5 * 1000); |
| 277 | } |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 280 | void ComposerClient::execute(TestCommandReader* reader, CommandWriterBase* writer) { |
| 281 | bool queueChanged = false; |
| 282 | uint32_t commandLength = 0; |
| 283 | hidl_vec<hidl_handle> commandHandles; |
| 284 | ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles)); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 285 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 286 | if (queueChanged) { |
| 287 | auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor()); |
| 288 | ASSERT_EQ(Error::NONE, static_cast<Error>(ret)); |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 289 | } |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 290 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 291 | mClient->executeCommands(commandLength, commandHandles, |
| 292 | [&](const auto& tmpError, const auto& tmpOutQueueChanged, |
| 293 | const auto& tmpOutLength, const auto& tmpOutHandles) { |
| 294 | ASSERT_EQ(Error::NONE, tmpError); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 295 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 296 | if (tmpOutQueueChanged) { |
| 297 | mClient->getOutputCommandQueue( |
| 298 | [&](const auto& tmpError, const auto& tmpDescriptor) { |
| 299 | ASSERT_EQ(Error::NONE, tmpError); |
| 300 | reader->setMQDescriptor(tmpDescriptor); |
| 301 | }); |
| 302 | } |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 303 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame] | 304 | ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles)); |
| 305 | reader->parse(); |
| 306 | }); |
Valerie Hau | cbe8e9a | 2018-09-17 10:58:03 -0700 | [diff] [blame] | 307 | reader->reset(); |
| 308 | writer->reset(); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Marin Shalamanov | 513ae73 | 2021-06-14 11:07:30 +0200 | [diff] [blame] | 311 | NativeHandleWrapper::~NativeHandleWrapper() { |
| 312 | if (mHandle) { |
| 313 | mGralloc.freeBuffer(mHandle); |
| 314 | } |
| 315 | } |
| 316 | |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 317 | Gralloc::Gralloc() { |
| 318 | [this] { |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 319 | ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>( |
| 320 | /*aidlAllocatorServiceName*/ IAllocator::descriptor + |
| 321 | std::string("/default"), |
| 322 | /*hidlAllocatorServiceName*/ "default", |
| 323 | /*mapperServiceName*/ "default", |
| 324 | /*errOnFailure=*/false)); |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 325 | if (!mGralloc4->hasAllocator() || mGralloc4->getMapper() == nullptr) { |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 326 | mGralloc4 = nullptr; |
| 327 | ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default", |
| 328 | /*errOnFailure=*/false)); |
| 329 | if (mGralloc3->getAllocator() == nullptr || mGralloc3->getMapper() == nullptr) { |
| 330 | mGralloc3 = nullptr; |
| 331 | ASSERT_NO_FATAL_FAILURE(mGralloc2 = std::make_shared<Gralloc2>()); |
| 332 | } |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 333 | } |
| 334 | }(); |
| 335 | } |
| 336 | |
Marin Shalamanov | 513ae73 | 2021-06-14 11:07:30 +0200 | [diff] [blame] | 337 | const NativeHandleWrapper Gralloc::allocate(uint32_t width, uint32_t height, uint32_t layerCount, |
| 338 | PixelFormat format, uint64_t usage, bool import, |
| 339 | uint32_t* outStride) { |
| 340 | const native_handle_t* handle; |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 341 | if (mGralloc4) { |
| 342 | IMapper4::BufferDescriptorInfo info{}; |
| 343 | info.width = width; |
| 344 | info.height = height; |
| 345 | info.layerCount = layerCount; |
| 346 | info.format = static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format); |
| 347 | info.usage = usage; |
Marin Shalamanov | 513ae73 | 2021-06-14 11:07:30 +0200 | [diff] [blame] | 348 | handle = mGralloc4->allocate(info, import, outStride); |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 349 | } else if (mGralloc3) { |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 350 | IMapper3::BufferDescriptorInfo info{}; |
| 351 | info.width = width; |
| 352 | info.height = height; |
| 353 | info.layerCount = layerCount; |
| 354 | info.format = static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format); |
| 355 | info.usage = usage; |
Marin Shalamanov | 513ae73 | 2021-06-14 11:07:30 +0200 | [diff] [blame] | 356 | handle = mGralloc3->allocate(info, import, outStride); |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 357 | } else { |
| 358 | IMapper2::BufferDescriptorInfo info{}; |
| 359 | info.width = width; |
| 360 | info.height = height; |
| 361 | info.layerCount = layerCount; |
| 362 | info.format = format; |
| 363 | info.usage = usage; |
Marin Shalamanov | 513ae73 | 2021-06-14 11:07:30 +0200 | [diff] [blame] | 364 | handle = mGralloc2->allocate(info, import, outStride); |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 365 | } |
Marin Shalamanov | 513ae73 | 2021-06-14 11:07:30 +0200 | [diff] [blame] | 366 | return NativeHandleWrapper(*this, handle); |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage, |
| 370 | const AccessRegion& accessRegionRect, int acquireFence) { |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 371 | if (mGralloc4) { |
| 372 | IMapper4::Rect accessRegion; |
| 373 | accessRegion.left = accessRegionRect.left; |
| 374 | accessRegion.top = accessRegionRect.top; |
| 375 | accessRegion.width = accessRegionRect.width; |
| 376 | accessRegion.height = accessRegionRect.height; |
Marissa Wall | 9c5ebfc | 2019-11-05 14:59:27 -0800 | [diff] [blame] | 377 | return mGralloc4->lock(bufferHandle, cpuUsage, accessRegion, acquireFence); |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 378 | } else if (mGralloc3) { |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 379 | IMapper3::Rect accessRegion; |
| 380 | accessRegion.left = accessRegionRect.left; |
| 381 | accessRegion.top = accessRegionRect.top; |
| 382 | accessRegion.width = accessRegionRect.width; |
| 383 | accessRegion.height = accessRegionRect.height; |
| 384 | int32_t bytesPerPixel; |
| 385 | int32_t bytesPerStride; |
| 386 | return mGralloc3->lock(bufferHandle, cpuUsage, accessRegion, acquireFence, &bytesPerPixel, |
| 387 | &bytesPerStride); |
| 388 | } else { |
| 389 | IMapper2::Rect accessRegion; |
| 390 | accessRegion.left = accessRegionRect.left; |
| 391 | accessRegion.top = accessRegionRect.top; |
| 392 | accessRegion.width = accessRegionRect.width; |
| 393 | accessRegion.height = accessRegionRect.height; |
| 394 | return mGralloc2->lock(bufferHandle, cpuUsage, accessRegion, acquireFence); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | int Gralloc::unlock(const native_handle_t* bufferHandle) { |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 399 | if (mGralloc4) { |
| 400 | return mGralloc4->unlock(bufferHandle); |
| 401 | } else if (mGralloc3) { |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 402 | return mGralloc3->unlock(bufferHandle); |
| 403 | } else { |
| 404 | return mGralloc2->unlock(bufferHandle); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | void Gralloc::freeBuffer(const native_handle_t* bufferHandle) { |
Marissa Wall | 53aff11 | 2019-06-20 13:49:21 -0700 | [diff] [blame] | 409 | if (mGralloc4) { |
| 410 | mGralloc4->freeBuffer(bufferHandle); |
| 411 | } else if (mGralloc3) { |
Valerie Hau | c1dc313 | 2019-06-13 09:49:44 -0700 | [diff] [blame] | 412 | mGralloc3->freeBuffer(bufferHandle); |
| 413 | } else { |
| 414 | mGralloc2->freeBuffer(bufferHandle); |
| 415 | } |
| 416 | } |
| 417 | |
Chia-I Wu | 96a098a | 2018-01-25 10:38:06 -0800 | [diff] [blame] | 418 | } // namespace vts |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 419 | } // namespace V2_1 |
| 420 | } // namespace composer |
| 421 | } // namespace graphics |
| 422 | } // namespace hardware |
| 423 | } // namespace android |