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