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