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