Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | // #define LOG_NDEBUG 0 |
| 18 | |
| 19 | #undef LOG_TAG |
| 20 | #define LOG_TAG "HWC2" |
| 21 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 22 | |
| 23 | #include "HWC2.h" |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 24 | #include "ComposerHal.h" |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 25 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 26 | #include <ui/Fence.h> |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 27 | #include <ui/FloatRect.h> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 28 | #include <ui/GraphicBuffer.h> |
| 29 | #include <ui/Region.h> |
| 30 | |
| 31 | #include <android/configuration.h> |
| 32 | |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 33 | #include <algorithm> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 34 | #include <inttypes.h> |
| 35 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 36 | using android::Fence; |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 37 | using android::FloatRect; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 38 | using android::GraphicBuffer; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 39 | using android::HdrCapabilities; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 40 | using android::Rect; |
| 41 | using android::Region; |
| 42 | using android::sp; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 43 | using android::hardware::Return; |
| 44 | using android::hardware::Void; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 45 | |
| 46 | namespace HWC2 { |
| 47 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 48 | namespace Hwc2 = android::Hwc2; |
| 49 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 50 | namespace { |
| 51 | |
| 52 | class ComposerCallbackBridge : public Hwc2::IComposerCallback { |
| 53 | public: |
| 54 | ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId) |
Lloyd Pique | 715a2c1 | 2017-12-14 17:18:08 -0800 | [diff] [blame] | 55 | : mCallback(callback), mSequenceId(sequenceId) {} |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 56 | |
| 57 | Return<void> onHotplug(Hwc2::Display display, |
| 58 | IComposerCallback::Connection conn) override |
| 59 | { |
| 60 | HWC2::Connection connection = static_cast<HWC2::Connection>(conn); |
Lloyd Pique | 715a2c1 | 2017-12-14 17:18:08 -0800 | [diff] [blame] | 61 | mCallback->onHotplugReceived(mSequenceId, display, connection); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 62 | return Void(); |
| 63 | } |
| 64 | |
| 65 | Return<void> onRefresh(Hwc2::Display display) override |
| 66 | { |
| 67 | mCallback->onRefreshReceived(mSequenceId, display); |
| 68 | return Void(); |
| 69 | } |
| 70 | |
| 71 | Return<void> onVsync(Hwc2::Display display, int64_t timestamp) override |
| 72 | { |
| 73 | mCallback->onVsyncReceived(mSequenceId, display, timestamp); |
| 74 | return Void(); |
| 75 | } |
| 76 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 77 | private: |
| 78 | ComposerCallback* mCallback; |
| 79 | int32_t mSequenceId; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace anonymous |
| 83 | |
| 84 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 85 | // Device methods |
| 86 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 87 | Device::Device(std::unique_ptr<android::Hwc2::Composer> composer) : mComposer(std::move(composer)) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 88 | loadCapabilities(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 91 | void Device::registerCallback(ComposerCallback* callback, int32_t sequenceId) { |
| 92 | if (mRegisteredCallback) { |
| 93 | ALOGW("Callback already registered. Ignored extra registration " |
| 94 | "attempt."); |
| 95 | return; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 96 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 97 | mRegisteredCallback = true; |
| 98 | sp<ComposerCallbackBridge> callbackBridge( |
| 99 | new ComposerCallbackBridge(callback, sequenceId)); |
| 100 | mComposer->registerCallback(callbackBridge); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Required by HWC2 device |
| 104 | |
| 105 | std::string Device::dump() const |
| 106 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 107 | return mComposer->dumpDebugInfo(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | uint32_t Device::getMaxVirtualDisplayCount() const |
| 111 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 112 | return mComposer->getMaxVirtualDisplayCount(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | Error Device::createVirtualDisplay(uint32_t width, uint32_t height, |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 116 | android_pixel_format_t* format, Display** outDisplay) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 117 | { |
| 118 | ALOGI("Creating virtual display"); |
| 119 | |
| 120 | hwc2_display_t displayId = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 121 | auto intFormat = static_cast<Hwc2::PixelFormat>(*format); |
| 122 | auto intError = mComposer->createVirtualDisplay(width, height, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 123 | &intFormat, &displayId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 124 | auto error = static_cast<Error>(intError); |
| 125 | if (error != Error::None) { |
| 126 | return error; |
| 127 | } |
| 128 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 129 | auto display = std::make_unique<Display>( |
| 130 | *mComposer.get(), mCapabilities, displayId, DisplayType::Virtual); |
| 131 | *outDisplay = display.get(); |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 132 | *format = static_cast<android_pixel_format_t>(intFormat); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 133 | mDisplays.emplace(displayId, std::move(display)); |
| 134 | ALOGI("Created virtual display"); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 135 | return Error::None; |
| 136 | } |
| 137 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 138 | void Device::destroyDisplay(hwc2_display_t displayId) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 139 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 140 | ALOGI("Destroying display %" PRIu64, displayId); |
| 141 | mDisplays.erase(displayId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 144 | void Device::onHotplug(hwc2_display_t displayId, Connection connection) { |
| 145 | if (connection == Connection::Connected) { |
| 146 | auto display = getDisplayById(displayId); |
| 147 | if (display) { |
| 148 | if (display->isConnected()) { |
| 149 | ALOGW("Attempt to hotplug connect display %" PRIu64 |
| 150 | " , which is already connected.", displayId); |
| 151 | } else { |
| 152 | display->setConnected(true); |
| 153 | } |
| 154 | } else { |
| 155 | DisplayType displayType; |
| 156 | auto intError = mComposer->getDisplayType(displayId, |
| 157 | reinterpret_cast<Hwc2::IComposerClient::DisplayType *>( |
| 158 | &displayType)); |
| 159 | auto error = static_cast<Error>(intError); |
| 160 | if (error != Error::None) { |
| 161 | ALOGE("getDisplayType(%" PRIu64 ") failed: %s (%d). " |
| 162 | "Aborting hotplug attempt.", |
| 163 | displayId, to_string(error).c_str(), intError); |
| 164 | return; |
| 165 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 166 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 167 | auto newDisplay = std::make_unique<Display>( |
| 168 | *mComposer.get(), mCapabilities, displayId, displayType); |
| 169 | mDisplays.emplace(displayId, std::move(newDisplay)); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 170 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 171 | } else if (connection == Connection::Disconnected) { |
| 172 | // The display will later be destroyed by a call to |
| 173 | // destroyDisplay(). For now we just mark it disconnected. |
| 174 | auto display = getDisplayById(displayId); |
| 175 | if (display) { |
| 176 | display->setConnected(false); |
| 177 | } else { |
| 178 | ALOGW("Attempted to disconnect unknown display %" PRIu64, |
| 179 | displayId); |
| 180 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
| 184 | // Other Device methods |
| 185 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 186 | Display* Device::getDisplayById(hwc2_display_t id) { |
| 187 | auto iter = mDisplays.find(id); |
| 188 | return iter == mDisplays.end() ? nullptr : iter->second.get(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Device initialization methods |
| 192 | |
| 193 | void Device::loadCapabilities() |
| 194 | { |
| 195 | static_assert(sizeof(Capability) == sizeof(int32_t), |
| 196 | "Capability size has changed"); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 197 | auto capabilities = mComposer->getCapabilities(); |
| 198 | for (auto capability : capabilities) { |
| 199 | mCapabilities.emplace(static_cast<Capability>(capability)); |
| 200 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Chia-I Wu | ae5a6b8 | 2017-10-10 09:09:22 -0700 | [diff] [blame] | 203 | Error Device::flushCommands() |
| 204 | { |
| 205 | return static_cast<Error>(mComposer->executeCommands()); |
| 206 | } |
| 207 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 208 | // Display methods |
| 209 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 210 | Display::Display(android::Hwc2::Composer& composer, |
| 211 | const std::unordered_set<Capability>& capabilities, |
| 212 | hwc2_display_t id, DisplayType type) |
| 213 | : mComposer(composer), |
| 214 | mCapabilities(capabilities), |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 215 | mId(id), |
| 216 | mIsConnected(false), |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 217 | mType(type) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 218 | { |
| 219 | ALOGV("Created display %" PRIu64, id); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 220 | setConnected(true); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 223 | Display::~Display() { |
| 224 | mLayers.clear(); |
| 225 | |
Chris Forbes | ceb67d1 | 2017-04-11 12:20:00 -0700 | [diff] [blame] | 226 | if (mType == DisplayType::Virtual) { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 227 | ALOGV("Destroying virtual display"); |
| 228 | auto intError = mComposer.destroyVirtualDisplay(mId); |
| 229 | auto error = static_cast<Error>(intError); |
| 230 | ALOGE_IF(error != Error::None, "destroyVirtualDisplay(%" PRIu64 |
| 231 | ") failed: %s (%d)", mId, to_string(error).c_str(), intError); |
| 232 | } else if (mType == DisplayType::Physical) { |
| 233 | auto error = setVsyncEnabled(HWC2::Vsync::Disable); |
| 234 | if (error != Error::None) { |
| 235 | ALOGE("~Display: Failed to disable vsync for display %" PRIu64 |
| 236 | ": %s (%d)", mId, to_string(error).c_str(), |
| 237 | static_cast<int32_t>(error)); |
| 238 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | Display::Config::Config(Display& display, hwc2_config_t id) |
| 243 | : mDisplay(display), |
| 244 | mId(id), |
| 245 | mWidth(-1), |
| 246 | mHeight(-1), |
| 247 | mVsyncPeriod(-1), |
| 248 | mDpiX(-1), |
| 249 | mDpiY(-1) {} |
| 250 | |
| 251 | Display::Config::Builder::Builder(Display& display, hwc2_config_t id) |
| 252 | : mConfig(new Config(display, id)) {} |
| 253 | |
| 254 | float Display::Config::Builder::getDefaultDensity() { |
| 255 | // Default density is based on TVs: 1080p displays get XHIGH density, lower- |
| 256 | // resolution displays get TV density. Maybe eventually we'll need to update |
| 257 | // it for 4k displays, though hopefully those will just report accurate DPI |
| 258 | // information to begin with. This is also used for virtual displays and |
| 259 | // older HWC implementations, so be careful about orientation. |
| 260 | |
| 261 | auto longDimension = std::max(mConfig->mWidth, mConfig->mHeight); |
| 262 | if (longDimension >= 1080) { |
| 263 | return ACONFIGURATION_DENSITY_XHIGH; |
| 264 | } else { |
| 265 | return ACONFIGURATION_DENSITY_TV; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // Required by HWC2 display |
| 270 | |
| 271 | Error Display::acceptChanges() |
| 272 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 273 | auto intError = mComposer.acceptDisplayChanges(mId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 274 | return static_cast<Error>(intError); |
| 275 | } |
| 276 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 277 | Error Display::createLayer(Layer** outLayer) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 278 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 279 | if (!outLayer) { |
| 280 | return Error::BadParameter; |
| 281 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 282 | hwc2_layer_t layerId = 0; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 283 | auto intError = mComposer.createLayer(mId, &layerId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 284 | auto error = static_cast<Error>(intError); |
| 285 | if (error != Error::None) { |
| 286 | return error; |
| 287 | } |
| 288 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 289 | auto layer = std::make_unique<Layer>( |
| 290 | mComposer, mCapabilities, mId, layerId); |
| 291 | *outLayer = layer.get(); |
| 292 | mLayers.emplace(layerId, std::move(layer)); |
| 293 | return Error::None; |
| 294 | } |
| 295 | |
| 296 | Error Display::destroyLayer(Layer* layer) |
| 297 | { |
| 298 | if (!layer) { |
| 299 | return Error::BadParameter; |
| 300 | } |
| 301 | mLayers.erase(layer->getId()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 302 | return Error::None; |
| 303 | } |
| 304 | |
| 305 | Error Display::getActiveConfig( |
| 306 | std::shared_ptr<const Display::Config>* outConfig) const |
| 307 | { |
| 308 | ALOGV("[%" PRIu64 "] getActiveConfig", mId); |
| 309 | hwc2_config_t configId = 0; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 310 | auto intError = mComposer.getActiveConfig(mId, &configId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 311 | auto error = static_cast<Error>(intError); |
| 312 | |
| 313 | if (error != Error::None) { |
Fabien Sanglard | b7432cc | 2016-11-11 09:40:27 -0800 | [diff] [blame] | 314 | ALOGE("Unable to get active config for mId:[%" PRIu64 "]", mId); |
| 315 | *outConfig = nullptr; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 316 | return error; |
| 317 | } |
| 318 | |
| 319 | if (mConfigs.count(configId) != 0) { |
| 320 | *outConfig = mConfigs.at(configId); |
| 321 | } else { |
| 322 | ALOGE("[%" PRIu64 "] getActiveConfig returned unknown config %u", mId, |
| 323 | configId); |
| 324 | // Return no error, but the caller needs to check for a null pointer to |
| 325 | // detect this case |
| 326 | *outConfig = nullptr; |
| 327 | } |
| 328 | |
| 329 | return Error::None; |
| 330 | } |
| 331 | |
| 332 | Error Display::getChangedCompositionTypes( |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 333 | std::unordered_map<Layer*, Composition>* outTypes) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 334 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 335 | std::vector<Hwc2::Layer> layerIds; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 336 | std::vector<Hwc2::IComposerClient::Composition> types; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 337 | auto intError = mComposer.getChangedCompositionTypes( |
| 338 | mId, &layerIds, &types); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 339 | uint32_t numElements = layerIds.size(); |
| 340 | auto error = static_cast<Error>(intError); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 341 | error = static_cast<Error>(intError); |
| 342 | if (error != Error::None) { |
| 343 | return error; |
| 344 | } |
| 345 | |
| 346 | outTypes->clear(); |
| 347 | outTypes->reserve(numElements); |
| 348 | for (uint32_t element = 0; element < numElements; ++element) { |
| 349 | auto layer = getLayerById(layerIds[element]); |
| 350 | if (layer) { |
| 351 | auto type = static_cast<Composition>(types[element]); |
| 352 | ALOGV("getChangedCompositionTypes: adding %" PRIu64 " %s", |
| 353 | layer->getId(), to_string(type).c_str()); |
| 354 | outTypes->emplace(layer, type); |
| 355 | } else { |
| 356 | ALOGE("getChangedCompositionTypes: invalid layer %" PRIu64 " found" |
| 357 | " on display %" PRIu64, layerIds[element], mId); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return Error::None; |
| 362 | } |
| 363 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 364 | Error Display::getColorModes(std::vector<android_color_mode_t>* outModes) const |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 365 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 366 | std::vector<Hwc2::ColorMode> modes; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 367 | auto intError = mComposer.getColorModes(mId, &modes); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 368 | uint32_t numModes = modes.size(); |
| 369 | auto error = static_cast<Error>(intError); |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 370 | if (error != Error::None) { |
| 371 | return error; |
| 372 | } |
| 373 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 374 | outModes->resize(numModes); |
| 375 | for (size_t i = 0; i < numModes; i++) { |
| 376 | (*outModes)[i] = static_cast<android_color_mode_t>(modes[i]); |
| 377 | } |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 378 | return Error::None; |
| 379 | } |
| 380 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 381 | std::vector<std::shared_ptr<const Display::Config>> Display::getConfigs() const |
| 382 | { |
| 383 | std::vector<std::shared_ptr<const Config>> configs; |
| 384 | for (const auto& element : mConfigs) { |
| 385 | configs.emplace_back(element.second); |
| 386 | } |
| 387 | return configs; |
| 388 | } |
| 389 | |
| 390 | Error Display::getName(std::string* outName) const |
| 391 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 392 | auto intError = mComposer.getDisplayName(mId, outName); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 393 | return static_cast<Error>(intError); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | Error Display::getRequests(HWC2::DisplayRequest* outDisplayRequests, |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 397 | std::unordered_map<Layer*, LayerRequest>* outLayerRequests) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 398 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 399 | uint32_t intDisplayRequests; |
| 400 | std::vector<Hwc2::Layer> layerIds; |
| 401 | std::vector<uint32_t> layerRequests; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 402 | auto intError = mComposer.getDisplayRequests( |
| 403 | mId, &intDisplayRequests, &layerIds, &layerRequests); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 404 | uint32_t numElements = layerIds.size(); |
| 405 | auto error = static_cast<Error>(intError); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 406 | if (error != Error::None) { |
| 407 | return error; |
| 408 | } |
| 409 | |
| 410 | *outDisplayRequests = static_cast<DisplayRequest>(intDisplayRequests); |
| 411 | outLayerRequests->clear(); |
| 412 | outLayerRequests->reserve(numElements); |
| 413 | for (uint32_t element = 0; element < numElements; ++element) { |
| 414 | auto layer = getLayerById(layerIds[element]); |
| 415 | if (layer) { |
| 416 | auto layerRequest = |
| 417 | static_cast<LayerRequest>(layerRequests[element]); |
| 418 | outLayerRequests->emplace(layer, layerRequest); |
| 419 | } else { |
| 420 | ALOGE("getRequests: invalid layer %" PRIu64 " found on display %" |
| 421 | PRIu64, layerIds[element], mId); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | return Error::None; |
| 426 | } |
| 427 | |
| 428 | Error Display::getType(DisplayType* outType) const |
| 429 | { |
Chris Forbes | 016d73c | 2017-04-11 10:04:31 -0700 | [diff] [blame] | 430 | *outType = mType; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 431 | return Error::None; |
| 432 | } |
| 433 | |
| 434 | Error Display::supportsDoze(bool* outSupport) const |
| 435 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 436 | bool intSupport = false; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 437 | auto intError = mComposer.getDozeSupport(mId, &intSupport); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 438 | auto error = static_cast<Error>(intError); |
| 439 | if (error != Error::None) { |
| 440 | return error; |
| 441 | } |
| 442 | *outSupport = static_cast<bool>(intSupport); |
| 443 | return Error::None; |
| 444 | } |
| 445 | |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 446 | Error Display::getHdrCapabilities( |
| 447 | std::unique_ptr<HdrCapabilities>* outCapabilities) const |
| 448 | { |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 449 | float maxLuminance = -1.0f; |
| 450 | float maxAverageLuminance = -1.0f; |
| 451 | float minLuminance = -1.0f; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 452 | std::vector<Hwc2::Hdr> intTypes; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 453 | auto intError = mComposer.getHdrCapabilities(mId, &intTypes, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 454 | &maxLuminance, &maxAverageLuminance, &minLuminance); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 455 | auto error = static_cast<HWC2::Error>(intError); |
| 456 | |
| 457 | std::vector<int32_t> types; |
| 458 | for (auto type : intTypes) { |
| 459 | types.push_back(static_cast<int32_t>(type)); |
| 460 | } |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 461 | if (error != Error::None) { |
| 462 | return error; |
| 463 | } |
| 464 | |
| 465 | *outCapabilities = std::make_unique<HdrCapabilities>(std::move(types), |
| 466 | maxLuminance, maxAverageLuminance, minLuminance); |
| 467 | return Error::None; |
| 468 | } |
| 469 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 470 | Error Display::getReleaseFences( |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 471 | std::unordered_map<Layer*, sp<Fence>>* outFences) const |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 472 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 473 | std::vector<Hwc2::Layer> layerIds; |
| 474 | std::vector<int> fenceFds; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 475 | auto intError = mComposer.getReleaseFences(mId, &layerIds, &fenceFds); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 476 | auto error = static_cast<Error>(intError); |
| 477 | uint32_t numElements = layerIds.size(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 478 | if (error != Error::None) { |
| 479 | return error; |
| 480 | } |
| 481 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 482 | std::unordered_map<Layer*, sp<Fence>> releaseFences; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 483 | releaseFences.reserve(numElements); |
| 484 | for (uint32_t element = 0; element < numElements; ++element) { |
| 485 | auto layer = getLayerById(layerIds[element]); |
| 486 | if (layer) { |
| 487 | sp<Fence> fence(new Fence(fenceFds[element])); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 488 | releaseFences.emplace(layer, fence); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 489 | } else { |
| 490 | ALOGE("getReleaseFences: invalid layer %" PRIu64 |
| 491 | " found on display %" PRIu64, layerIds[element], mId); |
Chia-I Wu | 5e74c65 | 2017-05-17 13:43:16 -0700 | [diff] [blame] | 492 | for (; element < numElements; ++element) { |
| 493 | close(fenceFds[element]); |
| 494 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 495 | return Error::BadLayer; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | *outFences = std::move(releaseFences); |
| 500 | return Error::None; |
| 501 | } |
| 502 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 503 | Error Display::present(sp<Fence>* outPresentFence) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 504 | { |
Naseer Ahmed | 847650b | 2016-06-17 11:14:25 -0400 | [diff] [blame] | 505 | int32_t presentFenceFd = -1; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 506 | auto intError = mComposer.presentDisplay(mId, &presentFenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 507 | auto error = static_cast<Error>(intError); |
| 508 | if (error != Error::None) { |
| 509 | return error; |
| 510 | } |
| 511 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 512 | *outPresentFence = new Fence(presentFenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 513 | return Error::None; |
| 514 | } |
| 515 | |
| 516 | Error Display::setActiveConfig(const std::shared_ptr<const Config>& config) |
| 517 | { |
| 518 | if (config->getDisplayId() != mId) { |
| 519 | ALOGE("setActiveConfig received config %u for the wrong display %" |
| 520 | PRIu64 " (expected %" PRIu64 ")", config->getId(), |
| 521 | config->getDisplayId(), mId); |
| 522 | return Error::BadConfig; |
| 523 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 524 | auto intError = mComposer.setActiveConfig(mId, config->getId()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 525 | return static_cast<Error>(intError); |
| 526 | } |
| 527 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 528 | Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 529 | const sp<Fence>& acquireFence, android_dataspace_t dataspace) |
| 530 | { |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 531 | // TODO: Properly encode client target surface damage |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 532 | int32_t fenceFd = acquireFence->dup(); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 533 | auto intError = mComposer.setClientTarget(mId, slot, target, |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 534 | fenceFd, static_cast<Hwc2::Dataspace>(dataspace), |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 535 | std::vector<Hwc2::IComposerClient::Rect>()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 536 | return static_cast<Error>(intError); |
| 537 | } |
| 538 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 539 | Error Display::setColorMode(android_color_mode_t mode) |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 540 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 541 | auto intError = mComposer.setColorMode( |
| 542 | mId, static_cast<Hwc2::ColorMode>(mode)); |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 543 | return static_cast<Error>(intError); |
| 544 | } |
| 545 | |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 546 | Error Display::setColorTransform(const android::mat4& matrix, |
| 547 | android_color_transform_t hint) |
| 548 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 549 | auto intError = mComposer.setColorTransform(mId, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 550 | matrix.asArray(), static_cast<Hwc2::ColorTransform>(hint)); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 551 | return static_cast<Error>(intError); |
| 552 | } |
| 553 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 554 | Error Display::setOutputBuffer(const sp<GraphicBuffer>& buffer, |
| 555 | const sp<Fence>& releaseFence) |
| 556 | { |
| 557 | int32_t fenceFd = releaseFence->dup(); |
| 558 | auto handle = buffer->getNativeBuffer()->handle; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 559 | auto intError = mComposer.setOutputBuffer(mId, handle, fenceFd); |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 560 | close(fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 561 | return static_cast<Error>(intError); |
| 562 | } |
| 563 | |
| 564 | Error Display::setPowerMode(PowerMode mode) |
| 565 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 566 | auto intMode = static_cast<Hwc2::IComposerClient::PowerMode>(mode); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 567 | auto intError = mComposer.setPowerMode(mId, intMode); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 568 | return static_cast<Error>(intError); |
| 569 | } |
| 570 | |
| 571 | Error Display::setVsyncEnabled(Vsync enabled) |
| 572 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 573 | auto intEnabled = static_cast<Hwc2::IComposerClient::Vsync>(enabled); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 574 | auto intError = mComposer.setVsyncEnabled(mId, intEnabled); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 575 | return static_cast<Error>(intError); |
| 576 | } |
| 577 | |
| 578 | Error Display::validate(uint32_t* outNumTypes, uint32_t* outNumRequests) |
| 579 | { |
| 580 | uint32_t numTypes = 0; |
| 581 | uint32_t numRequests = 0; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 582 | auto intError = mComposer.validateDisplay(mId, &numTypes, &numRequests); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 583 | auto error = static_cast<Error>(intError); |
| 584 | if (error != Error::None && error != Error::HasChanges) { |
| 585 | return error; |
| 586 | } |
| 587 | |
| 588 | *outNumTypes = numTypes; |
| 589 | *outNumRequests = numRequests; |
| 590 | return error; |
| 591 | } |
| 592 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 593 | Error Display::presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 594 | sp<android::Fence>* outPresentFence, uint32_t* state) { |
| 595 | |
| 596 | uint32_t numTypes = 0; |
| 597 | uint32_t numRequests = 0; |
| 598 | int32_t presentFenceFd = -1; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 599 | auto intError = mComposer.presentOrValidateDisplay( |
| 600 | mId, &numTypes, &numRequests, &presentFenceFd, state); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 601 | auto error = static_cast<Error>(intError); |
| 602 | if (error != Error::None && error != Error::HasChanges) { |
| 603 | return error; |
| 604 | } |
| 605 | |
| 606 | if (*state == 1) { |
| 607 | *outPresentFence = new Fence(presentFenceFd); |
| 608 | } |
| 609 | |
| 610 | if (*state == 0) { |
| 611 | *outNumTypes = numTypes; |
| 612 | *outNumRequests = numRequests; |
| 613 | } |
| 614 | return error; |
| 615 | } |
Chia-I Wu | 0c6ce46 | 2017-06-22 10:48:28 -0700 | [diff] [blame] | 616 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 617 | // For use by Device |
| 618 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 619 | void Display::setConnected(bool connected) { |
Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 620 | if (!mIsConnected && connected) { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 621 | mComposer.setClientTargetSlotCount(mId); |
Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 622 | if (mType == DisplayType::Physical) { |
| 623 | loadConfigs(); |
| 624 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 625 | } |
| 626 | mIsConnected = connected; |
| 627 | } |
| 628 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 629 | int32_t Display::getAttribute(hwc2_config_t configId, Attribute attribute) |
| 630 | { |
| 631 | int32_t value = 0; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 632 | auto intError = mComposer.getDisplayAttribute(mId, configId, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 633 | static_cast<Hwc2::IComposerClient::Attribute>(attribute), |
| 634 | &value); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 635 | auto error = static_cast<Error>(intError); |
| 636 | if (error != Error::None) { |
| 637 | ALOGE("getDisplayAttribute(%" PRIu64 ", %u, %s) failed: %s (%d)", mId, |
| 638 | configId, to_string(attribute).c_str(), |
| 639 | to_string(error).c_str(), intError); |
| 640 | return -1; |
| 641 | } |
| 642 | return value; |
| 643 | } |
| 644 | |
| 645 | void Display::loadConfig(hwc2_config_t configId) |
| 646 | { |
| 647 | ALOGV("[%" PRIu64 "] loadConfig(%u)", mId, configId); |
| 648 | |
| 649 | auto config = Config::Builder(*this, configId) |
| 650 | .setWidth(getAttribute(configId, Attribute::Width)) |
| 651 | .setHeight(getAttribute(configId, Attribute::Height)) |
| 652 | .setVsyncPeriod(getAttribute(configId, Attribute::VsyncPeriod)) |
| 653 | .setDpiX(getAttribute(configId, Attribute::DpiX)) |
| 654 | .setDpiY(getAttribute(configId, Attribute::DpiY)) |
| 655 | .build(); |
| 656 | mConfigs.emplace(configId, std::move(config)); |
| 657 | } |
| 658 | |
| 659 | void Display::loadConfigs() |
| 660 | { |
| 661 | ALOGV("[%" PRIu64 "] loadConfigs", mId); |
| 662 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 663 | std::vector<Hwc2::Config> configIds; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 664 | auto intError = mComposer.getDisplayConfigs(mId, &configIds); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 665 | auto error = static_cast<Error>(intError); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 666 | if (error != Error::None) { |
| 667 | ALOGE("[%" PRIu64 "] getDisplayConfigs [2] failed: %s (%d)", mId, |
| 668 | to_string(error).c_str(), intError); |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | for (auto configId : configIds) { |
| 673 | loadConfig(configId); |
| 674 | } |
| 675 | } |
| 676 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 677 | // Other Display methods |
| 678 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 679 | Layer* Display::getLayerById(hwc2_layer_t id) const |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 680 | { |
| 681 | if (mLayers.count(id) == 0) { |
| 682 | return nullptr; |
| 683 | } |
| 684 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 685 | return mLayers.at(id).get(); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | // Layer methods |
| 689 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 690 | Layer::Layer(android::Hwc2::Composer& composer, |
| 691 | const std::unordered_set<Capability>& capabilities, |
| 692 | hwc2_display_t displayId, hwc2_layer_t layerId) |
| 693 | : mComposer(composer), |
| 694 | mCapabilities(capabilities), |
| 695 | mDisplayId(displayId), |
| 696 | mId(layerId) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 697 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 698 | ALOGV("Created layer %" PRIu64 " on display %" PRIu64, layerId, displayId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | Layer::~Layer() |
| 702 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 703 | auto intError = mComposer.destroyLayer(mDisplayId, mId); |
| 704 | auto error = static_cast<Error>(intError); |
| 705 | ALOGE_IF(error != Error::None, "destroyLayer(%" PRIu64 ", %" PRIu64 ")" |
| 706 | " failed: %s (%d)", mDisplayId, mId, to_string(error).c_str(), |
| 707 | intError); |
| 708 | if (mLayerDestroyedListener) { |
| 709 | mLayerDestroyedListener(this); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 713 | void Layer::setLayerDestroyedListener(std::function<void(Layer*)> listener) { |
| 714 | LOG_ALWAYS_FATAL_IF(mLayerDestroyedListener && listener, |
| 715 | "Attempt to set layer destroyed listener multiple times"); |
| 716 | mLayerDestroyedListener = listener; |
| 717 | } |
| 718 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 719 | Error Layer::setCursorPosition(int32_t x, int32_t y) |
| 720 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 721 | auto intError = mComposer.setCursorPosition(mDisplayId, mId, x, y); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 722 | return static_cast<Error>(intError); |
| 723 | } |
| 724 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 725 | Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 726 | const sp<Fence>& acquireFence) |
| 727 | { |
| 728 | int32_t fenceFd = acquireFence->dup(); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 729 | auto intError = mComposer.setLayerBuffer(mDisplayId, mId, slot, buffer, |
| 730 | fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 731 | return static_cast<Error>(intError); |
| 732 | } |
| 733 | |
| 734 | Error Layer::setSurfaceDamage(const Region& damage) |
| 735 | { |
| 736 | // We encode default full-screen damage as INVALID_RECT upstream, but as 0 |
| 737 | // rects for HWC |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 738 | Hwc2::Error intError = Hwc2::Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 739 | if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 740 | intError = mComposer.setLayerSurfaceDamage(mDisplayId, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 741 | mId, std::vector<Hwc2::IComposerClient::Rect>()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 742 | } else { |
| 743 | size_t rectCount = 0; |
| 744 | auto rectArray = damage.getArray(&rectCount); |
| 745 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 746 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 747 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 748 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, |
| 749 | rectArray[rect].right, rectArray[rect].bottom}); |
| 750 | } |
| 751 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 752 | intError = mComposer.setLayerSurfaceDamage(mDisplayId, mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | return static_cast<Error>(intError); |
| 756 | } |
| 757 | |
| 758 | Error Layer::setBlendMode(BlendMode mode) |
| 759 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 760 | auto intMode = static_cast<Hwc2::IComposerClient::BlendMode>(mode); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 761 | auto intError = mComposer.setLayerBlendMode(mDisplayId, mId, intMode); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 762 | return static_cast<Error>(intError); |
| 763 | } |
| 764 | |
| 765 | Error Layer::setColor(hwc_color_t color) |
| 766 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 767 | Hwc2::IComposerClient::Color hwcColor{color.r, color.g, color.b, color.a}; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 768 | auto intError = mComposer.setLayerColor(mDisplayId, mId, hwcColor); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 769 | return static_cast<Error>(intError); |
| 770 | } |
| 771 | |
| 772 | Error Layer::setCompositionType(Composition type) |
| 773 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 774 | auto intType = static_cast<Hwc2::IComposerClient::Composition>(type); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 775 | auto intError = mComposer.setLayerCompositionType( |
| 776 | mDisplayId, mId, intType); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 777 | return static_cast<Error>(intError); |
| 778 | } |
| 779 | |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 780 | Error Layer::setDataspace(android_dataspace_t dataspace) |
| 781 | { |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 782 | if (dataspace == mDataSpace) { |
| 783 | return Error::None; |
| 784 | } |
| 785 | mDataSpace = dataspace; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 786 | auto intDataspace = static_cast<Hwc2::Dataspace>(dataspace); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 787 | auto intError = mComposer.setLayerDataspace(mDisplayId, mId, intDataspace); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 788 | return static_cast<Error>(intError); |
| 789 | } |
| 790 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 791 | Error Layer::setDisplayFrame(const Rect& frame) |
| 792 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 793 | Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 794 | frame.right, frame.bottom}; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 795 | auto intError = mComposer.setLayerDisplayFrame(mDisplayId, mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 796 | return static_cast<Error>(intError); |
| 797 | } |
| 798 | |
| 799 | Error Layer::setPlaneAlpha(float alpha) |
| 800 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 801 | auto intError = mComposer.setLayerPlaneAlpha(mDisplayId, mId, alpha); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 802 | return static_cast<Error>(intError); |
| 803 | } |
| 804 | |
| 805 | Error Layer::setSidebandStream(const native_handle_t* stream) |
| 806 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 807 | if (mCapabilities.count(Capability::SidebandStream) == 0) { |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 808 | ALOGE("Attempted to call setSidebandStream without checking that the " |
| 809 | "device supports sideband streams"); |
| 810 | return Error::Unsupported; |
| 811 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 812 | auto intError = mComposer.setLayerSidebandStream(mDisplayId, mId, stream); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 813 | return static_cast<Error>(intError); |
| 814 | } |
| 815 | |
| 816 | Error Layer::setSourceCrop(const FloatRect& crop) |
| 817 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 818 | Hwc2::IComposerClient::FRect hwcRect{ |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 819 | crop.left, crop.top, crop.right, crop.bottom}; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 820 | auto intError = mComposer.setLayerSourceCrop(mDisplayId, mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 821 | return static_cast<Error>(intError); |
| 822 | } |
| 823 | |
| 824 | Error Layer::setTransform(Transform transform) |
| 825 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 826 | auto intTransform = static_cast<Hwc2::Transform>(transform); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 827 | auto intError = mComposer.setLayerTransform(mDisplayId, mId, intTransform); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 828 | return static_cast<Error>(intError); |
| 829 | } |
| 830 | |
| 831 | Error Layer::setVisibleRegion(const Region& region) |
| 832 | { |
| 833 | size_t rectCount = 0; |
| 834 | auto rectArray = region.getArray(&rectCount); |
| 835 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 836 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 837 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 838 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, |
| 839 | rectArray[rect].right, rectArray[rect].bottom}); |
| 840 | } |
| 841 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 842 | auto intError = mComposer.setLayerVisibleRegion(mDisplayId, mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 843 | return static_cast<Error>(intError); |
| 844 | } |
| 845 | |
| 846 | Error Layer::setZOrder(uint32_t z) |
| 847 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 848 | auto intError = mComposer.setLayerZOrder(mDisplayId, mId, z); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 849 | return static_cast<Error>(intError); |
| 850 | } |
| 851 | |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 852 | Error Layer::setInfo(uint32_t type, uint32_t appId) |
| 853 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 854 | auto intError = mComposer.setLayerInfo(mDisplayId, mId, type, appId); |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 855 | return static_cast<Error>(intError); |
| 856 | } |
| 857 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 858 | } // namespace HWC2 |