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