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