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