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