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