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