| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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 |  | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 18 | #pragma clang diagnostic push | 
|  | 19 | #pragma clang diagnostic ignored "-Wconversion" | 
|  | 20 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 21 | // #define LOG_NDEBUG 0 | 
|  | 22 |  | 
|  | 23 | #undef LOG_TAG | 
|  | 24 | #define LOG_TAG "HWComposer" | 
| Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 25 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 26 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 27 | #include "HWComposer.h" | 
|  | 28 |  | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 29 | #include <compositionengine/Output.h> | 
|  | 30 | #include <compositionengine/OutputLayer.h> | 
|  | 31 | #include <compositionengine/impl/OutputLayerCompositionState.h> | 
|  | 32 | #include <log/log.h> | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 33 | #include <ui/DebugUtils.h> | 
| Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 34 | #include <ui/GraphicBuffer.h> | 
| Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 35 | #include <utils/Errors.h> | 
|  | 36 | #include <utils/Trace.h> | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 37 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 38 | #include "../Layer.h" // needed only for debugging | 
| Mathias Agopian | 33ceeb3 | 2013-04-01 16:54:58 -0700 | [diff] [blame] | 39 | #include "../SurfaceFlinger.h" | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 40 | #include "ComposerHal.h" | 
|  | 41 | #include "HWC2.h" | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 42 |  | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 43 | #define LOG_HWC_DISPLAY_ERROR(hwcDisplayId, msg) \ | 
|  | 44 | ALOGE("%s failed for HWC display %" PRIu64 ": %s", __FUNCTION__, hwcDisplayId, msg) | 
|  | 45 |  | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 46 | #define LOG_DISPLAY_ERROR(displayId, msg) \ | 
| Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 47 | ALOGE("%s failed for display %s: %s", __FUNCTION__, to_string(displayId).c_str(), msg) | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 48 |  | 
| Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 49 | #define LOG_HWC_ERROR(what, error, displayId)                          \ | 
|  | 50 | ALOGE("%s: %s failed for display %s: %s (%d)", __FUNCTION__, what, \ | 
|  | 51 | to_string(displayId).c_str(), to_string(error).c_str(), static_cast<int32_t>(error)) | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 52 |  | 
|  | 53 | #define RETURN_IF_INVALID_DISPLAY(displayId, ...)            \ | 
|  | 54 | do {                                                     \ | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 55 | if (mDisplayData.count(displayId) == 0) {            \ | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 56 | LOG_DISPLAY_ERROR(displayId, "Invalid display"); \ | 
|  | 57 | return __VA_ARGS__;                              \ | 
|  | 58 | }                                                    \ | 
|  | 59 | } while (false) | 
|  | 60 |  | 
|  | 61 | #define RETURN_IF_HWC_ERROR_FOR(what, error, displayId, ...) \ | 
|  | 62 | do {                                                     \ | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 63 | if (error != hal::Error::NONE) {                     \ | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 64 | LOG_HWC_ERROR(what, error, displayId);           \ | 
|  | 65 | return __VA_ARGS__;                              \ | 
|  | 66 | }                                                    \ | 
|  | 67 | } while (false) | 
|  | 68 |  | 
|  | 69 | #define RETURN_IF_HWC_ERROR(error, displayId, ...) \ | 
|  | 70 | RETURN_IF_HWC_ERROR_FOR(__FUNCTION__, error, displayId, __VA_ARGS__) | 
|  | 71 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 72 | namespace hal = android::hardware::graphics::composer::hal; | 
|  | 73 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 74 | namespace { | 
|  | 75 |  | 
|  | 76 | using android::hardware::Return; | 
|  | 77 | using android::hardware::Void; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 78 | using android::HWC2::ComposerCallback; | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 79 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 80 | class ComposerCallbackBridge : public hal::IComposerCallback { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 81 | public: | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 82 | ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId, | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 83 | bool vsyncSwitchingSupported) | 
|  | 84 | : mCallback(callback), | 
|  | 85 | mSequenceId(sequenceId), | 
|  | 86 | mVsyncSwitchingSupported(vsyncSwitchingSupported) {} | 
|  | 87 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 88 | android::hardware::Return<void> onHotplug(hal::HWDisplayId display, | 
|  | 89 | hal::Connection conn) override { | 
|  | 90 | mCallback->onHotplugReceived(mSequenceId, display, conn); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 91 | return android::hardware::Void(); | 
|  | 92 | } | 
|  | 93 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 94 | android::hardware::Return<void> onRefresh(hal::HWDisplayId display) override { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 95 | mCallback->onRefreshReceived(mSequenceId, display); | 
|  | 96 | return android::hardware::Void(); | 
|  | 97 | } | 
|  | 98 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 99 | android::hardware::Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 100 | if (!mVsyncSwitchingSupported) { | 
|  | 101 | mCallback->onVsyncReceived(mSequenceId, display, timestamp, std::nullopt); | 
|  | 102 | } else { | 
|  | 103 | ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring."); | 
|  | 104 | } | 
|  | 105 | return android::hardware::Void(); | 
|  | 106 | } | 
|  | 107 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 108 | android::hardware::Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp, | 
|  | 109 | hal::VsyncPeriodNanos vsyncPeriodNanos) override { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 110 | if (mVsyncSwitchingSupported) { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 111 | mCallback->onVsyncReceived(mSequenceId, display, timestamp, | 
|  | 112 | std::make_optional(vsyncPeriodNanos)); | 
|  | 113 | } else { | 
|  | 114 | ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring."); | 
|  | 115 | } | 
|  | 116 | return android::hardware::Void(); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | android::hardware::Return<void> onVsyncPeriodTimingChanged( | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 120 | hal::HWDisplayId display, | 
|  | 121 | const hal::VsyncPeriodChangeTimeline& updatedTimeline) override { | 
|  | 122 | mCallback->onVsyncPeriodTimingChangedReceived(mSequenceId, display, updatedTimeline); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 123 | return android::hardware::Void(); | 
|  | 124 | } | 
|  | 125 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 126 | android::hardware::Return<void> onSeamlessPossible(hal::HWDisplayId display) override { | 
| Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 127 | mCallback->onSeamlessPossible(mSequenceId, display); | 
|  | 128 | return android::hardware::Void(); | 
|  | 129 | } | 
|  | 130 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 131 | private: | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 132 | ComposerCallback* mCallback; | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 133 | const int32_t mSequenceId; | 
|  | 134 | const bool mVsyncSwitchingSupported; | 
|  | 135 | }; | 
|  | 136 |  | 
|  | 137 | } // namespace | 
|  | 138 |  | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 139 | namespace android { | 
| Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 140 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 141 | HWComposer::~HWComposer() = default; | 
|  | 142 |  | 
|  | 143 | namespace impl { | 
|  | 144 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 145 | HWComposer::HWComposer(std::unique_ptr<Hwc2::Composer> composer) : mComposer(std::move(composer)) { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 146 | } | 
|  | 147 |  | 
|  | 148 | HWComposer::HWComposer(const std::string& composerServiceName) | 
|  | 149 | : mComposer(std::make_unique<Hwc2::impl::Composer>(composerServiceName)) { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 150 | } | 
| Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 151 |  | 
| Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 152 | HWComposer::~HWComposer() { | 
|  | 153 | mDisplayData.clear(); | 
|  | 154 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 155 |  | 
| Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 156 | void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) { | 
|  | 157 | loadCapabilities(); | 
|  | 158 | loadLayerMetadataSupport(); | 
|  | 159 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 160 | if (mRegisteredCallback) { | 
|  | 161 | ALOGW("Callback already registered. Ignored extra registration attempt."); | 
|  | 162 | return; | 
|  | 163 | } | 
|  | 164 | mRegisteredCallback = true; | 
|  | 165 | sp<ComposerCallbackBridge> callbackBridge( | 
|  | 166 | new ComposerCallbackBridge(callback, sequenceId, | 
|  | 167 | mComposer->isVsyncPeriodSwitchSupported())); | 
|  | 168 | mComposer->registerCallback(callbackBridge); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 169 | } | 
|  | 170 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 171 | bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort, | 
| Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 172 | DisplayIdentificationData* outData) const { | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 173 | const auto error = static_cast<hal::Error>( | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 174 | mComposer->getDisplayIdentificationData(hwcDisplayId, outPort, outData)); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 175 | if (error != hal::Error::NONE) { | 
|  | 176 | if (error != hal::Error::UNSUPPORTED) { | 
| Chia-I Wu | d0aff9d | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 177 | LOG_HWC_DISPLAY_ERROR(hwcDisplayId, to_string(error).c_str()); | 
|  | 178 | } | 
| Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 179 | return false; | 
|  | 180 | } | 
|  | 181 | return true; | 
|  | 182 | } | 
|  | 183 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 184 | bool HWComposer::hasCapability(hal::Capability capability) const { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 185 | return mCapabilities.count(capability) > 0; | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 186 | } | 
|  | 187 |  | 
| Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame] | 188 | bool HWComposer::hasDisplayCapability(DisplayId displayId, | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 189 | hal::DisplayCapability capability) const { | 
| Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame] | 190 | RETURN_IF_INVALID_DISPLAY(displayId, false); | 
|  | 191 | return mDisplayData.at(displayId).hwcDisplay->getCapabilities().count(capability) > 0; | 
| Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 192 | } | 
|  | 193 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 194 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplug(hal::HWDisplayId hwcDisplayId, | 
|  | 195 | hal::Connection connection) { | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 196 | switch (connection) { | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 197 | case hal::Connection::CONNECTED: | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 198 | return onHotplugConnect(hwcDisplayId); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 199 | case hal::Connection::DISCONNECTED: | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 200 | return onHotplugDisconnect(hwcDisplayId); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 201 | case hal::Connection::INVALID: | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 202 | return {}; | 
| Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 203 | } | 
| Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 204 | } | 
|  | 205 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 206 | bool HWComposer::onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 207 | const auto displayId = toPhysicalDisplayId(hwcDisplayId); | 
|  | 208 | if (!displayId) { | 
|  | 209 | LOG_HWC_DISPLAY_ERROR(hwcDisplayId, "Invalid HWC display"); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 210 | return false; | 
| Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 211 | } | 
| Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 212 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 213 | RETURN_IF_INVALID_DISPLAY(*displayId, false); | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 214 |  | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 215 | auto& displayData = mDisplayData[*displayId]; | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 216 | if (displayData.isVirtual) { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 217 | LOG_DISPLAY_ERROR(*displayId, "Invalid operation on virtual display"); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 218 | return false; | 
| Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 219 | } | 
|  | 220 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 221 | { | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 222 | std::lock_guard lock(displayData.lastHwVsyncLock); | 
| Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 223 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 224 | // There have been reports of HWCs that signal several vsync events | 
|  | 225 | // with the same timestamp when turning the display off and on. This | 
|  | 226 | // is a bug in the HWC implementation, but filter the extra events | 
|  | 227 | // out here so they don't cause havoc downstream. | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 228 | if (timestamp == displayData.lastHwVsync) { | 
| Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 229 | ALOGW("Ignoring duplicate VSYNC event from HWC for display %s (t=%" PRId64 ")", | 
|  | 230 | to_string(*displayId).c_str(), timestamp); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 231 | return false; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 232 | } | 
|  | 233 |  | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 234 | displayData.lastHwVsync = timestamp; | 
| Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 235 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 236 |  | 
| Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 237 | const auto tag = "HW_VSYNC_" + to_string(*displayId); | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 238 | ATRACE_INT(tag.c_str(), displayData.vsyncTraceToggle); | 
|  | 239 | displayData.vsyncTraceToggle = !displayData.vsyncTraceToggle; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 240 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 241 | return true; | 
| Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 244 | std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height, | 
|  | 245 | ui::PixelFormat* format) { | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 246 | if (mRemainingHwcVirtualDisplays == 0) { | 
| Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 247 | ALOGE("%s: No remaining virtual displays", __FUNCTION__); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 248 | return {}; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 249 | } | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 250 |  | 
| Fabien Sanglard | c8e387e | 2017-03-10 10:30:28 -0800 | [diff] [blame] | 251 | if (SurfaceFlinger::maxVirtualDisplaySize != 0 && | 
|  | 252 | (width > SurfaceFlinger::maxVirtualDisplaySize || | 
|  | 253 | height > SurfaceFlinger::maxVirtualDisplaySize)) { | 
| Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 254 | ALOGE("%s: Display size %ux%u exceeds maximum dimension of %" PRIu64, __FUNCTION__, width, | 
|  | 255 | height, SurfaceFlinger::maxVirtualDisplaySize); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 256 | return {}; | 
| Fabien Sanglard | e29055f | 2017-03-08 11:36:46 -0800 | [diff] [blame] | 257 | } | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 258 | hal::HWDisplayId hwcDisplayId = 0; | 
|  | 259 | const auto error = static_cast<hal::Error>( | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 260 | mComposer->createVirtualDisplay(width, height, format, &hwcDisplayId)); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 261 | if (error != hal::Error::NONE) { | 
| Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 262 | ALOGE("%s: Failed to create HWC virtual display", __FUNCTION__); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 263 | return {}; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 264 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 265 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 266 | auto display = std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities, | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 267 | hwcDisplayId, hal::DisplayType::VIRTUAL); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 268 | display->setConnected(true); | 
|  | 269 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 270 | DisplayId displayId; | 
|  | 271 | if (mFreeVirtualDisplayIds.empty()) { | 
|  | 272 | displayId = getVirtualDisplayId(mNextVirtualDisplayId++); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 273 | } else { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 274 | displayId = *mFreeVirtualDisplayIds.begin(); | 
|  | 275 | mFreeVirtualDisplayIds.erase(displayId); | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 276 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 277 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 278 | auto& displayData = mDisplayData[displayId]; | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 279 | displayData.hwcDisplay = std::move(display); | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 280 | displayData.isVirtual = true; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 281 |  | 
|  | 282 | --mRemainingHwcVirtualDisplays; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 283 | return displayId; | 
| Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 284 | } | 
|  | 285 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 286 | void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) { | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 287 | if (!mInternalHwcDisplayId) { | 
|  | 288 | mInternalHwcDisplayId = hwcDisplayId; | 
|  | 289 | } else if (mInternalHwcDisplayId != hwcDisplayId && !mExternalHwcDisplayId) { | 
|  | 290 | mExternalHwcDisplayId = hwcDisplayId; | 
|  | 291 | } | 
|  | 292 |  | 
|  | 293 | auto& displayData = mDisplayData[displayId]; | 
|  | 294 | auto newDisplay = | 
|  | 295 | std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities, hwcDisplayId, | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 296 | hal::DisplayType::PHYSICAL); | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 297 | newDisplay->setConnected(true); | 
|  | 298 | displayData.hwcDisplay = std::move(newDisplay); | 
|  | 299 | mPhysicalDisplayIdMap[hwcDisplayId] = displayId; | 
|  | 300 | } | 
|  | 301 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 302 | HWC2::Layer* HWComposer::createLayer(DisplayId displayId) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 303 | RETURN_IF_INVALID_DISPLAY(displayId, nullptr); | 
|  | 304 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 305 | HWC2::Layer* layer; | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 306 | auto error = mDisplayData[displayId].hwcDisplay->createLayer(&layer); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 307 | RETURN_IF_HWC_ERROR(error, displayId, nullptr); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 308 | return layer; | 
|  | 309 | } | 
|  | 310 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 311 | void HWComposer::destroyLayer(DisplayId displayId, HWC2::Layer* layer) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 312 | RETURN_IF_INVALID_DISPLAY(displayId); | 
|  | 313 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 314 | auto error = mDisplayData[displayId].hwcDisplay->destroyLayer(layer); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 315 | RETURN_IF_HWC_ERROR(error, displayId); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 316 | } | 
|  | 317 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 318 | nsecs_t HWComposer::getRefreshTimestamp(DisplayId displayId) const { | 
|  | 319 | RETURN_IF_INVALID_DISPLAY(displayId, 0); | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 320 | const auto& displayData = mDisplayData.at(displayId); | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 321 | // this returns the last refresh timestamp. | 
|  | 322 | // if the last one is not available, we estimate it based on | 
|  | 323 | // the refresh period and whatever closest timestamp we have. | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 324 | std::lock_guard lock(displayData.lastHwVsyncLock); | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 325 | nsecs_t now = systemTime(CLOCK_MONOTONIC); | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 326 | auto vsyncPeriodNanos = getDisplayVsyncPeriod(displayId); | 
|  | 327 | return now - ((now - displayData.lastHwVsync) % vsyncPeriodNanos); | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 328 | } | 
|  | 329 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 330 | bool HWComposer::isConnected(DisplayId displayId) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 331 | RETURN_IF_INVALID_DISPLAY(displayId, false); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 332 | return mDisplayData.at(displayId).hwcDisplay->isConnected(); | 
| Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 333 | } | 
|  | 334 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 335 | std::vector<std::shared_ptr<const HWC2::Display::Config>> HWComposer::getConfigs( | 
|  | 336 | DisplayId displayId) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 337 | RETURN_IF_INVALID_DISPLAY(displayId, {}); | 
|  | 338 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 339 | const auto& displayData = mDisplayData.at(displayId); | 
|  | 340 | auto configs = displayData.hwcDisplay->getConfigs(); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 341 | if (displayData.configMap.empty()) { | 
|  | 342 | for (size_t i = 0; i < configs.size(); ++i) { | 
|  | 343 | displayData.configMap[i] = configs[i]; | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 344 | } | 
|  | 345 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 346 | return configs; | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 347 | } | 
|  | 348 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 349 | std::shared_ptr<const HWC2::Display::Config> HWComposer::getActiveConfig( | 
|  | 350 | DisplayId displayId) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 351 | RETURN_IF_INVALID_DISPLAY(displayId, nullptr); | 
|  | 352 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 353 | std::shared_ptr<const HWC2::Display::Config> config; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 354 | auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfig(&config); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 355 | if (error == hal::Error::BAD_CONFIG) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 356 | LOG_DISPLAY_ERROR(displayId, "No active config"); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 357 | return nullptr; | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 358 | } | 
|  | 359 |  | 
|  | 360 | RETURN_IF_HWC_ERROR(error, displayId, nullptr); | 
|  | 361 |  | 
|  | 362 | if (!config) { | 
|  | 363 | LOG_DISPLAY_ERROR(displayId, "Unknown config"); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 364 | return nullptr; | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | return config; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 368 | } | 
|  | 369 |  | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 370 | // Composer 2.4 | 
|  | 371 |  | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 372 | DisplayConnectionType HWComposer::getDisplayConnectionType(DisplayId displayId) const { | 
|  | 373 | RETURN_IF_INVALID_DISPLAY(displayId, DisplayConnectionType::Internal); | 
|  | 374 | const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay; | 
|  | 375 |  | 
|  | 376 | DisplayConnectionType type; | 
|  | 377 | const auto error = hwcDisplay->getConnectionType(&type); | 
|  | 378 |  | 
|  | 379 | const auto FALLBACK_TYPE = hwcDisplay->getId() == mInternalHwcDisplayId | 
|  | 380 | ? DisplayConnectionType::Internal | 
|  | 381 | : DisplayConnectionType::External; | 
|  | 382 |  | 
|  | 383 | RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE); | 
|  | 384 | return type; | 
|  | 385 | } | 
|  | 386 |  | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 387 | bool HWComposer::isVsyncPeriodSwitchSupported(DisplayId displayId) const { | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 388 | RETURN_IF_INVALID_DISPLAY(displayId, false); | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 389 | return mDisplayData.at(displayId).hwcDisplay->isVsyncPeriodSwitchSupported(); | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | nsecs_t HWComposer::getDisplayVsyncPeriod(DisplayId displayId) const { | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 393 | RETURN_IF_INVALID_DISPLAY(displayId, 0); | 
|  | 394 |  | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 395 | nsecs_t vsyncPeriodNanos; | 
|  | 396 | auto error = mDisplayData.at(displayId).hwcDisplay->getDisplayVsyncPeriod(&vsyncPeriodNanos); | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 397 | RETURN_IF_HWC_ERROR(error, displayId, 0); | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 398 | return vsyncPeriodNanos; | 
|  | 399 | } | 
|  | 400 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 401 | int HWComposer::getActiveConfigIndex(DisplayId displayId) const { | 
| Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 402 | RETURN_IF_INVALID_DISPLAY(displayId, -1); | 
|  | 403 |  | 
| Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 404 | int index; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 405 | auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfigIndex(&index); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 406 | if (error == hal::Error::BAD_CONFIG) { | 
| Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 407 | LOG_DISPLAY_ERROR(displayId, "No active config"); | 
| Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 408 | return -1; | 
| Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 409 | } | 
|  | 410 |  | 
|  | 411 | RETURN_IF_HWC_ERROR(error, displayId, -1); | 
|  | 412 |  | 
|  | 413 | if (index < 0) { | 
|  | 414 | LOG_DISPLAY_ERROR(displayId, "Unknown config"); | 
| Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 415 | return -1; | 
|  | 416 | } | 
|  | 417 |  | 
|  | 418 | return index; | 
|  | 419 | } | 
|  | 420 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 421 | std::vector<ui::ColorMode> HWComposer::getColorModes(DisplayId displayId) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 422 | RETURN_IF_INVALID_DISPLAY(displayId, {}); | 
|  | 423 |  | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 424 | std::vector<ui::ColorMode> modes; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 425 | auto error = mDisplayData.at(displayId).hwcDisplay->getColorModes(&modes); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 426 | RETURN_IF_HWC_ERROR(error, displayId, {}); | 
| Courtney Goeltzenleuchter | fad9d8c | 2016-06-23 11:49:50 -0600 | [diff] [blame] | 427 | return modes; | 
|  | 428 | } | 
|  | 429 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 430 | status_t HWComposer::setActiveColorMode(DisplayId displayId, ui::ColorMode mode, | 
|  | 431 | ui::RenderIntent renderIntent) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 432 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 433 |  | 
|  | 434 | auto& displayData = mDisplayData[displayId]; | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 435 | auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 436 | RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " + | 
|  | 437 | decodeRenderIntent(renderIntent) + ")") | 
|  | 438 | .c_str(), | 
|  | 439 | error, displayId, UNKNOWN_ERROR); | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 440 |  | 
|  | 441 | return NO_ERROR; | 
|  | 442 | } | 
|  | 443 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 444 | void HWComposer::setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) { | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 445 | RETURN_IF_INVALID_DISPLAY(displayId); | 
|  | 446 | auto& displayData = mDisplayData[displayId]; | 
|  | 447 |  | 
|  | 448 | if (displayData.isVirtual) { | 
|  | 449 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display"); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 450 | return; | 
|  | 451 | } | 
|  | 452 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 453 | // NOTE: we use our own internal lock here because we have to call | 
|  | 454 | // into the HWC with the lock held, and we want to make sure | 
|  | 455 | // that even if HWC blocks (which it shouldn't), it won't | 
|  | 456 | // affect other threads. | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 457 | std::lock_guard lock(displayData.vsyncEnabledLock); | 
|  | 458 | if (enabled == displayData.vsyncEnabled) { | 
|  | 459 | return; | 
| Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 460 | } | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 461 |  | 
|  | 462 | ATRACE_CALL(); | 
|  | 463 | auto error = displayData.hwcDisplay->setVsyncEnabled(enabled); | 
|  | 464 | RETURN_IF_HWC_ERROR(error, displayId); | 
|  | 465 |  | 
|  | 466 | displayData.vsyncEnabled = enabled; | 
|  | 467 |  | 
|  | 468 | const auto tag = "HW_VSYNC_ON_" + to_string(displayId); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 469 | ATRACE_INT(tag.c_str(), enabled == hal::Vsync::ENABLE ? 1 : 0); | 
| Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 470 | } | 
|  | 471 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 472 | status_t HWComposer::setClientTarget(DisplayId displayId, uint32_t slot, | 
|  | 473 | const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target, | 
|  | 474 | ui::Dataspace dataspace) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 475 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 476 |  | 
| Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 477 | ALOGV("%s for display %s", __FUNCTION__, to_string(displayId).c_str()); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 478 | auto& hwcDisplay = mDisplayData[displayId].hwcDisplay; | 
| Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 479 | auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 480 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); | 
| Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 481 | return NO_ERROR; | 
|  | 482 | } | 
|  | 483 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 484 | status_t HWComposer::getDeviceCompositionChanges( | 
|  | 485 | DisplayId displayId, bool frameUsesClientComposition, | 
|  | 486 | std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) { | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 487 | ATRACE_CALL(); | 
|  | 488 |  | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 489 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 490 |  | 
|  | 491 | auto& displayData = mDisplayData[displayId]; | 
|  | 492 | auto& hwcDisplay = displayData.hwcDisplay; | 
|  | 493 | if (!hwcDisplay->isConnected()) { | 
|  | 494 | return NO_ERROR; | 
|  | 495 | } | 
|  | 496 |  | 
|  | 497 | uint32_t numTypes = 0; | 
|  | 498 | uint32_t numRequests = 0; | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 499 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 500 | hal::Error error = hal::Error::NONE; | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 501 |  | 
| Chia-I Wu | 41b98d4 | 2017-12-11 11:04:36 -0800 | [diff] [blame] | 502 | // First try to skip validate altogether when there is no client | 
|  | 503 | // composition.  When there is client composition, since we haven't | 
|  | 504 | // rendered to the client target yet, we should not attempt to skip | 
|  | 505 | // validate. | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 506 | displayData.validateWasSkipped = false; | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 507 | if (!frameUsesClientComposition) { | 
| Dominik Laskowski | 1af4793 | 2018-11-12 10:20:46 -0800 | [diff] [blame] | 508 | sp<Fence> outPresentFence; | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 509 | uint32_t state = UINT32_MAX; | 
|  | 510 | error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 511 | if (!hasChangesError(error)) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 512 | RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR); | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 513 | } | 
|  | 514 | if (state == 1) { //Present Succeeded. | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 515 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 516 | error = hwcDisplay->getReleaseFences(&releaseFences); | 
|  | 517 | displayData.releaseFences = std::move(releaseFences); | 
|  | 518 | displayData.lastPresentFence = outPresentFence; | 
|  | 519 | displayData.validateWasSkipped = true; | 
|  | 520 | displayData.presentError = error; | 
|  | 521 | return NO_ERROR; | 
|  | 522 | } | 
|  | 523 | // Present failed but Validate ran. | 
|  | 524 | } else { | 
|  | 525 | error = hwcDisplay->validate(&numTypes, &numRequests); | 
|  | 526 | } | 
|  | 527 | ALOGV("SkipValidate failed, Falling back to SLOW validate/present"); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 528 | if (!hasChangesError(error)) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 529 | RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 530 | } | 
|  | 531 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 532 | android::HWComposer::DeviceRequestedChanges::ChangedTypes changedTypes; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 533 | changedTypes.reserve(numTypes); | 
|  | 534 | error = hwcDisplay->getChangedCompositionTypes(&changedTypes); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 535 | RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 536 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 537 | auto displayRequests = static_cast<hal::DisplayRequest>(0); | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 538 | android::HWComposer::DeviceRequestedChanges::LayerRequests layerRequests; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 539 | layerRequests.reserve(numRequests); | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 540 | error = hwcDisplay->getRequests(&displayRequests, &layerRequests); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 541 | RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 542 |  | 
| Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 543 | outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests), | 
|  | 544 | std::move(layerRequests)}); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 545 |  | 
|  | 546 | error = hwcDisplay->acceptChanges(); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 547 | RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 548 |  | 
|  | 549 | return NO_ERROR; | 
|  | 550 | } | 
|  | 551 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 552 | sp<Fence> HWComposer::getPresentFence(DisplayId displayId) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 553 | RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 554 | return mDisplayData.at(displayId).lastPresentFence; | 
| Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 555 | } | 
|  | 556 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 557 | sp<Fence> HWComposer::getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 558 | RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE); | 
| Tim Murray | 2d3f8b8 | 2019-12-04 16:24:17 -0800 | [diff] [blame] | 559 | const auto& displayFences = mDisplayData.at(displayId).releaseFences; | 
|  | 560 | auto fence = displayFences.find(layer); | 
|  | 561 | if (fence == displayFences.end()) { | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 562 | ALOGV("getLayerReleaseFence: Release fence not found"); | 
|  | 563 | return Fence::NO_FENCE; | 
| Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 564 | } | 
| Tim Murray | 2d3f8b8 | 2019-12-04 16:24:17 -0800 | [diff] [blame] | 565 | return fence->second; | 
| Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 566 | } | 
|  | 567 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 568 | status_t HWComposer::presentAndGetReleaseFences(DisplayId displayId) { | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 569 | ATRACE_CALL(); | 
| Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 570 |  | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 571 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Pablo Ceballos | d814cf2 | 2015-09-11 14:37:39 -0700 | [diff] [blame] | 572 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 573 | auto& displayData = mDisplayData[displayId]; | 
|  | 574 | auto& hwcDisplay = displayData.hwcDisplay; | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 575 |  | 
|  | 576 | if (displayData.validateWasSkipped) { | 
| Chia-I Wu | ae5a6b8 | 2017-10-10 09:09:22 -0700 | [diff] [blame] | 577 | // explicitly flush all pending commands | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 578 | auto error = static_cast<hal::Error>(mComposer->executeCommands()); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 579 | RETURN_IF_HWC_ERROR_FOR("executeCommands", error, displayId, UNKNOWN_ERROR); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 580 | RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR); | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 581 | return NO_ERROR; | 
|  | 582 | } | 
|  | 583 |  | 
| Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 584 | auto error = hwcDisplay->present(&displayData.lastPresentFence); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 585 | RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR); | 
| Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 586 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 587 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 588 | error = hwcDisplay->getReleaseFences(&releaseFences); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 589 | RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 590 |  | 
|  | 591 | displayData.releaseFences = std::move(releaseFences); | 
|  | 592 |  | 
|  | 593 | return NO_ERROR; | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 596 | status_t HWComposer::setPowerMode(DisplayId displayId, hal::PowerMode mode) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 597 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 598 |  | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 599 | const auto& displayData = mDisplayData[displayId]; | 
|  | 600 | if (displayData.isVirtual) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 601 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display"); | 
|  | 602 | return INVALID_OPERATION; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 603 | } | 
| Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 604 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 605 | if (mode == hal::PowerMode::OFF) { | 
|  | 606 | setVsyncEnabled(displayId, hal::Vsync::DISABLE); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 607 | } | 
|  | 608 |  | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 609 | auto& hwcDisplay = displayData.hwcDisplay; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 610 | switch (mode) { | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 611 | case hal::PowerMode::OFF: | 
|  | 612 | case hal::PowerMode::ON: | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 613 | ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str()); | 
|  | 614 | { | 
|  | 615 | auto error = hwcDisplay->setPowerMode(mode); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 616 | if (error != hal::Error::NONE) { | 
|  | 617 | LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error, | 
|  | 618 | displayId); | 
| Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 619 | } | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 620 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 621 | break; | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 622 | case hal::PowerMode::DOZE: | 
|  | 623 | case hal::PowerMode::DOZE_SUSPEND: | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 624 | ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str()); | 
|  | 625 | { | 
|  | 626 | bool supportsDoze = false; | 
|  | 627 | auto error = hwcDisplay->supportsDoze(&supportsDoze); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 628 | if (error != hal::Error::NONE) { | 
| Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 629 | LOG_HWC_ERROR("supportsDoze", error, displayId); | 
|  | 630 | } | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 631 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 632 | if (!supportsDoze) { | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 633 | mode = hal::PowerMode::ON; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 634 | } | 
|  | 635 |  | 
|  | 636 | error = hwcDisplay->setPowerMode(mode); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 637 | if (error != hal::Error::NONE) { | 
|  | 638 | LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error, | 
|  | 639 | displayId); | 
| Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 640 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 641 | } | 
|  | 642 | break; | 
|  | 643 | default: | 
|  | 644 | ALOGV("setPowerMode: Not calling HWC"); | 
|  | 645 | break; | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 646 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 647 |  | 
|  | 648 | return NO_ERROR; | 
|  | 649 | } | 
|  | 650 |  | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 651 | status_t HWComposer::setActiveConfigWithConstraints( | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 652 | DisplayId displayId, size_t configId, const hal::VsyncPeriodChangeConstraints& constraints, | 
|  | 653 | hal::VsyncPeriodChangeTimeline* outTimeline) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 654 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 655 |  | 
|  | 656 | auto& displayData = mDisplayData[displayId]; | 
|  | 657 | if (displayData.configMap.count(configId) == 0) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 658 | LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str()); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 659 | return BAD_INDEX; | 
|  | 660 | } | 
|  | 661 |  | 
| Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 662 | auto error = | 
|  | 663 | displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configMap[configId], | 
|  | 664 | constraints, outTimeline); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 665 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 666 | return NO_ERROR; | 
|  | 667 | } | 
|  | 668 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 669 | status_t HWComposer::setColorTransform(DisplayId displayId, const mat4& transform) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 670 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 671 |  | 
|  | 672 | auto& displayData = mDisplayData[displayId]; | 
|  | 673 | bool isIdentity = transform == mat4(); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 674 | auto error = displayData.hwcDisplay | 
|  | 675 | ->setColorTransform(transform, | 
|  | 676 | isIdentity ? hal::ColorTransform::IDENTITY | 
|  | 677 | : hal::ColorTransform::ARBITRARY_MATRIX); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 678 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
| Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 679 | return NO_ERROR; | 
|  | 680 | } | 
|  | 681 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 682 | void HWComposer::disconnectDisplay(DisplayId displayId) { | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 683 | RETURN_IF_INVALID_DISPLAY(displayId); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 684 | auto& displayData = mDisplayData[displayId]; | 
|  | 685 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 686 | // If this was a virtual display, add its slot back for reuse by future | 
|  | 687 | // virtual displays | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 688 | if (displayData.isVirtual) { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 689 | mFreeVirtualDisplayIds.insert(displayId); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 690 | ++mRemainingHwcVirtualDisplays; | 
|  | 691 | } | 
|  | 692 |  | 
| Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 693 | const auto hwcDisplayId = displayData.hwcDisplay->getId(); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 694 |  | 
|  | 695 | // TODO(b/74619554): Select internal/external display from remaining displays. | 
|  | 696 | if (hwcDisplayId == mInternalHwcDisplayId) { | 
|  | 697 | mInternalHwcDisplayId.reset(); | 
|  | 698 | } else if (hwcDisplayId == mExternalHwcDisplayId) { | 
|  | 699 | mExternalHwcDisplayId.reset(); | 
|  | 700 | } | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 701 | mPhysicalDisplayIdMap.erase(hwcDisplayId); | 
|  | 702 | mDisplayData.erase(displayId); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 703 | } | 
|  | 704 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 705 | status_t HWComposer::setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, | 
|  | 706 | const sp<GraphicBuffer>& buffer) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 707 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 708 | const auto& displayData = mDisplayData[displayId]; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 709 |  | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 710 | if (!displayData.isVirtual) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 711 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display"); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 712 | return INVALID_OPERATION; | 
|  | 713 | } | 
|  | 714 |  | 
| Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 715 | auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 716 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 717 | return NO_ERROR; | 
|  | 718 | } | 
|  | 719 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 720 | void HWComposer::clearReleaseFences(DisplayId displayId) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 721 | RETURN_IF_INVALID_DISPLAY(displayId); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 722 | mDisplayData[displayId].releaseFences.clear(); | 
| Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 723 | } | 
|  | 724 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 725 | status_t HWComposer::getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 726 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 727 |  | 
|  | 728 | auto& hwcDisplay = mDisplayData[displayId].hwcDisplay; | 
| Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 729 | auto error = hwcDisplay->getHdrCapabilities(outCapabilities); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 730 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
| Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 731 | return NO_ERROR; | 
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 732 | } | 
|  | 733 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 734 | int32_t HWComposer::getSupportedPerFrameMetadata(DisplayId displayId) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 735 | RETURN_IF_INVALID_DISPLAY(displayId, 0); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 736 | return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata(); | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 737 | } | 
|  | 738 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 739 | std::vector<ui::RenderIntent> HWComposer::getRenderIntents(DisplayId displayId, | 
|  | 740 | ui::ColorMode colorMode) const { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 741 | RETURN_IF_INVALID_DISPLAY(displayId, {}); | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 742 |  | 
|  | 743 | std::vector<ui::RenderIntent> renderIntents; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 744 | auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 745 | RETURN_IF_HWC_ERROR(error, displayId, {}); | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 746 | return renderIntents; | 
|  | 747 | } | 
|  | 748 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 749 | mat4 HWComposer::getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) { | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 750 | RETURN_IF_INVALID_DISPLAY(displayId, {}); | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 751 |  | 
|  | 752 | mat4 matrix; | 
|  | 753 | auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace, | 
|  | 754 | &matrix); | 
| Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 755 | RETURN_IF_HWC_ERROR(error, displayId, {}); | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 756 | return matrix; | 
|  | 757 | } | 
|  | 758 |  | 
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 759 | status_t HWComposer::getDisplayedContentSamplingAttributes(DisplayId displayId, | 
|  | 760 | ui::PixelFormat* outFormat, | 
|  | 761 | ui::Dataspace* outDataspace, | 
|  | 762 | uint8_t* outComponentMask) { | 
|  | 763 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 764 | const auto error = | 
|  | 765 | mDisplayData[displayId] | 
|  | 766 | .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace, | 
|  | 767 | outComponentMask); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 768 | if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); | 
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 769 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 770 | return NO_ERROR; | 
|  | 771 | } | 
|  | 772 |  | 
| Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 773 | status_t HWComposer::setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, | 
|  | 774 | uint8_t componentMask, uint64_t maxFrames) { | 
|  | 775 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 776 | const auto error = | 
|  | 777 | mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled, | 
|  | 778 | componentMask, | 
|  | 779 | maxFrames); | 
|  | 780 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 781 | if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); | 
|  | 782 | if (error == hal::Error::BAD_PARAMETER) RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); | 
| Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 783 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 784 | return NO_ERROR; | 
|  | 785 | } | 
|  | 786 |  | 
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 787 | status_t HWComposer::getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, | 
|  | 788 | uint64_t timestamp, DisplayedFrameStats* outStats) { | 
|  | 789 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 790 | const auto error = | 
|  | 791 | mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp, | 
|  | 792 | outStats); | 
|  | 793 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 794 | return NO_ERROR; | 
|  | 795 | } | 
|  | 796 |  | 
| Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 797 | status_t HWComposer::setDisplayBrightness(DisplayId displayId, float brightness) { | 
|  | 798 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 799 | const auto error = mDisplayData[displayId].hwcDisplay->setDisplayBrightness(brightness); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 800 | if (error == hal::Error::UNSUPPORTED) { | 
| Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 801 | RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); | 
|  | 802 | } | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 803 | if (error == hal::Error::BAD_PARAMETER) { | 
| Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 804 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); | 
|  | 805 | } | 
|  | 806 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 807 | return NO_ERROR; | 
|  | 808 | } | 
|  | 809 |  | 
| Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 810 | bool HWComposer::isUsingVrComposer() const { | 
| Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 811 | return getComposer()->isUsingVrComposer(); | 
| Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 812 | } | 
|  | 813 |  | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 814 | status_t HWComposer::setAutoLowLatencyMode(DisplayId displayId, bool on) { | 
|  | 815 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 816 | const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 817 | if (error == hal::Error::UNSUPPORTED) { | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 818 | RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); | 
|  | 819 | } | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 820 | if (error == hal::Error::BAD_PARAMETER) { | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 821 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); | 
|  | 822 | } | 
|  | 823 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 824 | return NO_ERROR; | 
|  | 825 | } | 
|  | 826 |  | 
|  | 827 | status_t HWComposer::getSupportedContentTypes( | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 828 | DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) { | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 829 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 830 | const auto error = | 
|  | 831 | mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes); | 
|  | 832 |  | 
|  | 833 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 834 |  | 
|  | 835 | return NO_ERROR; | 
|  | 836 | } | 
|  | 837 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 838 | status_t HWComposer::setContentType(DisplayId displayId, hal::ContentType contentType) { | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 839 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); | 
|  | 840 | const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType); | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 841 | if (error == hal::Error::UNSUPPORTED) { | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 842 | RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); | 
|  | 843 | } | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 844 | if (error == hal::Error::BAD_PARAMETER) { | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 845 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); | 
|  | 846 | } | 
|  | 847 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); | 
|  | 848 |  | 
|  | 849 | return NO_ERROR; | 
|  | 850 | } | 
|  | 851 |  | 
| Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 852 | const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const { | 
|  | 853 | return mSupportedLayerGenericMetadata; | 
|  | 854 | } | 
|  | 855 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 856 | void HWComposer::dump(std::string& result) const { | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 857 | result.append(mComposer->dumpDebugInfo()); | 
| Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 858 | } | 
|  | 859 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 860 | std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 861 | if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId); | 
|  | 862 | it != mPhysicalDisplayIdMap.end()) { | 
|  | 863 | return it->second; | 
|  | 864 | } | 
|  | 865 | return {}; | 
|  | 866 | } | 
|  | 867 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 868 | std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 869 | if (const auto it = mDisplayData.find(displayId); | 
|  | 870 | it != mDisplayData.end() && !it->second.isVirtual) { | 
|  | 871 | return it->second.hwcDisplay->getId(); | 
|  | 872 | } | 
|  | 873 | return {}; | 
|  | 874 | } | 
|  | 875 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 876 | bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId, | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 877 | bool hasDisplayIdentificationData) const { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 878 | if (isUsingVrComposer() && mInternalHwcDisplayId) { | 
|  | 879 | ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId); | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 880 | return true; | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 881 | } | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 882 |  | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 883 | if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 884 | ALOGE("Ignoring connection of display %" PRIu64 " without identification data", | 
|  | 885 | hwcDisplayId); | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 886 | return true; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 887 | } | 
|  | 888 |  | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 889 | if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) { | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 890 | ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId); | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 891 | return true; | 
|  | 892 | } | 
|  | 893 |  | 
|  | 894 | return false; | 
|  | 895 | } | 
|  | 896 |  | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 897 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect( | 
|  | 898 | hal::HWDisplayId hwcDisplayId) { | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 899 | std::optional<DisplayIdentificationInfo> info; | 
|  | 900 | if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) { | 
|  | 901 | info = DisplayIdentificationInfo{.id = *displayId, | 
|  | 902 | .name = std::string(), | 
|  | 903 | .deviceProductInfo = std::nullopt}; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 904 | } else { | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 905 | uint8_t port; | 
|  | 906 | DisplayIdentificationData data; | 
|  | 907 | const bool hasDisplayIdentificationData = | 
|  | 908 | getDisplayIdentificationData(hwcDisplayId, &port, &data); | 
|  | 909 | if (mPhysicalDisplayIdMap.empty()) { | 
|  | 910 | mHasMultiDisplaySupport = hasDisplayIdentificationData; | 
|  | 911 | ALOGI("Switching to %s multi-display mode", | 
|  | 912 | mHasMultiDisplaySupport ? "generalized" : "legacy"); | 
|  | 913 | } | 
|  | 914 |  | 
|  | 915 | if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) { | 
|  | 916 | return {}; | 
|  | 917 | } | 
|  | 918 |  | 
|  | 919 | info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] { | 
|  | 920 | const bool isPrimary = !mInternalHwcDisplayId; | 
|  | 921 | if (mHasMultiDisplaySupport) { | 
|  | 922 | if (const auto info = parseDisplayIdentificationData(port, data)) { | 
|  | 923 | return *info; | 
|  | 924 | } | 
|  | 925 | ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId); | 
|  | 926 | } else { | 
|  | 927 | ALOGW_IF(hasDisplayIdentificationData, | 
|  | 928 | "Ignoring identification data for display %" PRIu64, hwcDisplayId); | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 929 | port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL; | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 930 | } | 
|  | 931 |  | 
|  | 932 | return DisplayIdentificationInfo{.id = getFallbackDisplayId(port), | 
|  | 933 | .name = isPrimary ? "Internal display" | 
|  | 934 | : "External display", | 
|  | 935 | .deviceProductInfo = std::nullopt}; | 
|  | 936 | }(); | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 937 | } | 
|  | 938 |  | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 939 | if (!isConnected(info->id)) { | 
|  | 940 | allocatePhysicalDisplay(hwcDisplayId, info->id); | 
|  | 941 | } | 
|  | 942 | return info; | 
|  | 943 | } | 
|  | 944 |  | 
|  | 945 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect( | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 946 | hal::HWDisplayId hwcDisplayId) { | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 947 | const auto displayId = toPhysicalDisplayId(hwcDisplayId); | 
|  | 948 | if (!displayId) { | 
|  | 949 | ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId); | 
|  | 950 | return {}; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 951 | } | 
|  | 952 |  | 
| Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 953 | // The display will later be destroyed by a call to | 
|  | 954 | // destroyDisplay(). For now we just mark it disconnected. | 
|  | 955 | if (isConnected(*displayId)) { | 
|  | 956 | mDisplayData[*displayId].hwcDisplay->setConnected(false); | 
|  | 957 | } else { | 
|  | 958 | ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId); | 
|  | 959 | } | 
|  | 960 | // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay | 
|  | 961 | // via SurfaceFlinger's onHotplugReceived callback handling | 
|  | 962 | return DisplayIdentificationInfo{.id = *displayId, | 
|  | 963 | .name = std::string(), | 
| Marin Shalamanov | f5de90d | 2019-10-08 10:57:25 +0200 | [diff] [blame] | 964 | .deviceProductInfo = std::nullopt}; | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 965 | } | 
|  | 966 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 967 | void HWComposer::loadCapabilities() { | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 968 | static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed"); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 969 | auto capabilities = mComposer->getCapabilities(); | 
|  | 970 | for (auto capability : capabilities) { | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 971 | mCapabilities.emplace(static_cast<hal::Capability>(capability)); | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 972 | } | 
|  | 973 | } | 
|  | 974 |  | 
| Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 975 | void HWComposer::loadLayerMetadataSupport() { | 
|  | 976 | mSupportedLayerGenericMetadata.clear(); | 
|  | 977 |  | 
|  | 978 | std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo; | 
|  | 979 | const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo); | 
|  | 980 | if (error != hardware::graphics::composer::V2_4::Error::NONE) { | 
|  | 981 | ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys", | 
|  | 982 | toString(error).c_str(), static_cast<int32_t>(error)); | 
|  | 983 | return; | 
|  | 984 | } | 
|  | 985 |  | 
|  | 986 | for (const auto& [name, mandatory] : supportedMetadataKeyInfo) { | 
|  | 987 | mSupportedLayerGenericMetadata.emplace(name, mandatory); | 
|  | 988 | } | 
|  | 989 | } | 
|  | 990 |  | 
| Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 991 | uint32_t HWComposer::getMaxVirtualDisplayCount() const { | 
|  | 992 | return mComposer->getMaxVirtualDisplayCount(); | 
|  | 993 | } | 
|  | 994 |  | 
| Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 995 | } // namespace impl | 
| Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 996 | } // namespace android | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 997 |  | 
|  | 998 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 999 | #pragma clang diagnostic pop // ignored "-Wconversion" |