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