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