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 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 596 | status_t HWComposer::setPowerMode(DisplayId displayId, int32_t intMode) { |
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 | auto mode = static_cast<hal::PowerMode>(intMode); |
| 606 | if (mode == hal::PowerMode::OFF) { |
| 607 | setVsyncEnabled(displayId, hal::Vsync::DISABLE); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 610 | auto& hwcDisplay = displayData.hwcDisplay; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 611 | switch (mode) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 612 | case hal::PowerMode::OFF: |
| 613 | case hal::PowerMode::ON: |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 614 | ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str()); |
| 615 | { |
| 616 | auto error = hwcDisplay->setPowerMode(mode); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 617 | if (error != hal::Error::NONE) { |
| 618 | LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error, |
| 619 | displayId); |
Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 620 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 621 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 622 | break; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 623 | case hal::PowerMode::DOZE: |
| 624 | case hal::PowerMode::DOZE_SUSPEND: |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 625 | ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str()); |
| 626 | { |
| 627 | bool supportsDoze = false; |
| 628 | auto error = hwcDisplay->supportsDoze(&supportsDoze); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 629 | if (error != hal::Error::NONE) { |
Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 630 | LOG_HWC_ERROR("supportsDoze", error, displayId); |
| 631 | } |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 632 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 633 | if (!supportsDoze) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 634 | mode = hal::PowerMode::ON; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | error = hwcDisplay->setPowerMode(mode); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 638 | if (error != hal::Error::NONE) { |
| 639 | LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error, |
| 640 | displayId); |
Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 641 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 642 | } |
| 643 | break; |
| 644 | default: |
| 645 | ALOGV("setPowerMode: Not calling HWC"); |
| 646 | break; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 647 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 648 | |
| 649 | return NO_ERROR; |
| 650 | } |
| 651 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 652 | status_t HWComposer::setActiveConfigWithConstraints( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 653 | DisplayId displayId, size_t configId, const hal::VsyncPeriodChangeConstraints& constraints, |
| 654 | hal::VsyncPeriodChangeTimeline* outTimeline) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 655 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 656 | |
| 657 | auto& displayData = mDisplayData[displayId]; |
| 658 | if (displayData.configMap.count(configId) == 0) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 659 | LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 660 | return BAD_INDEX; |
| 661 | } |
| 662 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 663 | auto error = |
| 664 | displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configMap[configId], |
| 665 | constraints, outTimeline); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 666 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 667 | return NO_ERROR; |
| 668 | } |
| 669 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 670 | status_t HWComposer::setColorTransform(DisplayId displayId, const mat4& transform) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 671 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 672 | |
| 673 | auto& displayData = mDisplayData[displayId]; |
| 674 | bool isIdentity = transform == mat4(); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 675 | auto error = displayData.hwcDisplay |
| 676 | ->setColorTransform(transform, |
| 677 | isIdentity ? hal::ColorTransform::IDENTITY |
| 678 | : hal::ColorTransform::ARBITRARY_MATRIX); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 679 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 680 | return NO_ERROR; |
| 681 | } |
| 682 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 683 | void HWComposer::disconnectDisplay(DisplayId displayId) { |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 684 | RETURN_IF_INVALID_DISPLAY(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 685 | auto& displayData = mDisplayData[displayId]; |
| 686 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 687 | // If this was a virtual display, add its slot back for reuse by future |
| 688 | // virtual displays |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 689 | if (displayData.isVirtual) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 690 | mFreeVirtualDisplayIds.insert(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 691 | ++mRemainingHwcVirtualDisplays; |
| 692 | } |
| 693 | |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 694 | const auto hwcDisplayId = displayData.hwcDisplay->getId(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 695 | |
| 696 | // TODO(b/74619554): Select internal/external display from remaining displays. |
| 697 | if (hwcDisplayId == mInternalHwcDisplayId) { |
| 698 | mInternalHwcDisplayId.reset(); |
| 699 | } else if (hwcDisplayId == mExternalHwcDisplayId) { |
| 700 | mExternalHwcDisplayId.reset(); |
| 701 | } |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 702 | mPhysicalDisplayIdMap.erase(hwcDisplayId); |
| 703 | mDisplayData.erase(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 706 | status_t HWComposer::setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, |
| 707 | const sp<GraphicBuffer>& buffer) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 708 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 709 | const auto& displayData = mDisplayData[displayId]; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 710 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 711 | if (!displayData.isVirtual) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 712 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display"); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 713 | return INVALID_OPERATION; |
| 714 | } |
| 715 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 716 | auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 717 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 718 | return NO_ERROR; |
| 719 | } |
| 720 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 721 | void HWComposer::clearReleaseFences(DisplayId displayId) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 722 | RETURN_IF_INVALID_DISPLAY(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 723 | mDisplayData[displayId].releaseFences.clear(); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 726 | status_t HWComposer::getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 727 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 728 | |
| 729 | auto& hwcDisplay = mDisplayData[displayId].hwcDisplay; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 730 | auto error = hwcDisplay->getHdrCapabilities(outCapabilities); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 731 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 732 | return NO_ERROR; |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 735 | int32_t HWComposer::getSupportedPerFrameMetadata(DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 736 | RETURN_IF_INVALID_DISPLAY(displayId, 0); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 737 | return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata(); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 740 | std::vector<ui::RenderIntent> HWComposer::getRenderIntents(DisplayId displayId, |
| 741 | ui::ColorMode colorMode) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 742 | RETURN_IF_INVALID_DISPLAY(displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 743 | |
| 744 | std::vector<ui::RenderIntent> renderIntents; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 745 | auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 746 | RETURN_IF_HWC_ERROR(error, displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 747 | return renderIntents; |
| 748 | } |
| 749 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 750 | mat4 HWComposer::getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 751 | RETURN_IF_INVALID_DISPLAY(displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 752 | |
| 753 | mat4 matrix; |
| 754 | auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace, |
| 755 | &matrix); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 756 | RETURN_IF_HWC_ERROR(error, displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 757 | return matrix; |
| 758 | } |
| 759 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 760 | status_t HWComposer::getDisplayedContentSamplingAttributes(DisplayId displayId, |
| 761 | ui::PixelFormat* outFormat, |
| 762 | ui::Dataspace* outDataspace, |
| 763 | uint8_t* outComponentMask) { |
| 764 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 765 | const auto error = |
| 766 | mDisplayData[displayId] |
| 767 | .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace, |
| 768 | outComponentMask); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 769 | 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] | 770 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 771 | return NO_ERROR; |
| 772 | } |
| 773 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 774 | status_t HWComposer::setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, |
| 775 | uint8_t componentMask, uint64_t maxFrames) { |
| 776 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 777 | const auto error = |
| 778 | mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled, |
| 779 | componentMask, |
| 780 | maxFrames); |
| 781 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 782 | if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); |
| 783 | 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] | 784 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 785 | return NO_ERROR; |
| 786 | } |
| 787 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 788 | status_t HWComposer::getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, |
| 789 | uint64_t timestamp, DisplayedFrameStats* outStats) { |
| 790 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 791 | const auto error = |
| 792 | mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp, |
| 793 | outStats); |
| 794 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 795 | return NO_ERROR; |
| 796 | } |
| 797 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 798 | status_t HWComposer::setDisplayBrightness(DisplayId displayId, float brightness) { |
| 799 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 800 | const auto error = mDisplayData[displayId].hwcDisplay->setDisplayBrightness(brightness); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 801 | if (error == hal::Error::UNSUPPORTED) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 802 | RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); |
| 803 | } |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 804 | if (error == hal::Error::BAD_PARAMETER) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 805 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); |
| 806 | } |
| 807 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 808 | return NO_ERROR; |
| 809 | } |
| 810 | |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 811 | bool HWComposer::isUsingVrComposer() const { |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 812 | return getComposer()->isUsingVrComposer(); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 815 | status_t HWComposer::setAutoLowLatencyMode(DisplayId displayId, bool on) { |
| 816 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 817 | const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 818 | if (error == hal::Error::UNSUPPORTED) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 819 | RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); |
| 820 | } |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 821 | if (error == hal::Error::BAD_PARAMETER) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 822 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); |
| 823 | } |
| 824 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 825 | return NO_ERROR; |
| 826 | } |
| 827 | |
| 828 | status_t HWComposer::getSupportedContentTypes( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 829 | DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 830 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 831 | const auto error = |
| 832 | mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes); |
| 833 | |
| 834 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 835 | |
| 836 | return NO_ERROR; |
| 837 | } |
| 838 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 839 | status_t HWComposer::setContentType(DisplayId displayId, hal::ContentType contentType) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 840 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 841 | const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 842 | if (error == hal::Error::UNSUPPORTED) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 843 | RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); |
| 844 | } |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 845 | if (error == hal::Error::BAD_PARAMETER) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 846 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); |
| 847 | } |
| 848 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
| 849 | |
| 850 | return NO_ERROR; |
| 851 | } |
| 852 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 853 | const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const { |
| 854 | return mSupportedLayerGenericMetadata; |
| 855 | } |
| 856 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 857 | void HWComposer::dump(std::string& result) const { |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 858 | result.append(mComposer->dumpDebugInfo()); |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 861 | std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 862 | if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId); |
| 863 | it != mPhysicalDisplayIdMap.end()) { |
| 864 | return it->second; |
| 865 | } |
| 866 | return {}; |
| 867 | } |
| 868 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 869 | std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 870 | if (const auto it = mDisplayData.find(displayId); |
| 871 | it != mDisplayData.end() && !it->second.isVirtual) { |
| 872 | return it->second.hwcDisplay->getId(); |
| 873 | } |
| 874 | return {}; |
| 875 | } |
| 876 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 877 | bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId, |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 878 | bool hasDisplayIdentificationData) const { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 879 | if (isUsingVrComposer() && mInternalHwcDisplayId) { |
| 880 | ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId); |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 881 | return true; |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 882 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 883 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 884 | if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 885 | ALOGE("Ignoring connection of display %" PRIu64 " without identification data", |
| 886 | hwcDisplayId); |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 887 | return true; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 890 | if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 891 | ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId); |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 892 | return true; |
| 893 | } |
| 894 | |
| 895 | return false; |
| 896 | } |
| 897 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 898 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect( |
| 899 | hal::HWDisplayId hwcDisplayId) { |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 900 | std::optional<DisplayIdentificationInfo> info; |
| 901 | if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) { |
| 902 | info = DisplayIdentificationInfo{.id = *displayId, |
| 903 | .name = std::string(), |
| 904 | .deviceProductInfo = std::nullopt}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 905 | } else { |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 906 | uint8_t port; |
| 907 | DisplayIdentificationData data; |
| 908 | const bool hasDisplayIdentificationData = |
| 909 | getDisplayIdentificationData(hwcDisplayId, &port, &data); |
| 910 | if (mPhysicalDisplayIdMap.empty()) { |
| 911 | mHasMultiDisplaySupport = hasDisplayIdentificationData; |
| 912 | ALOGI("Switching to %s multi-display mode", |
| 913 | mHasMultiDisplaySupport ? "generalized" : "legacy"); |
| 914 | } |
| 915 | |
| 916 | if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) { |
| 917 | return {}; |
| 918 | } |
| 919 | |
| 920 | info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] { |
| 921 | const bool isPrimary = !mInternalHwcDisplayId; |
| 922 | if (mHasMultiDisplaySupport) { |
| 923 | if (const auto info = parseDisplayIdentificationData(port, data)) { |
| 924 | return *info; |
| 925 | } |
| 926 | ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId); |
| 927 | } else { |
| 928 | ALOGW_IF(hasDisplayIdentificationData, |
| 929 | "Ignoring identification data for display %" PRIu64, hwcDisplayId); |
| 930 | port = isPrimary ? HWC_DISPLAY_PRIMARY : HWC_DISPLAY_EXTERNAL; |
| 931 | } |
| 932 | |
| 933 | return DisplayIdentificationInfo{.id = getFallbackDisplayId(port), |
| 934 | .name = isPrimary ? "Internal display" |
| 935 | : "External display", |
| 936 | .deviceProductInfo = std::nullopt}; |
| 937 | }(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 940 | if (!isConnected(info->id)) { |
| 941 | allocatePhysicalDisplay(hwcDisplayId, info->id); |
| 942 | } |
| 943 | return info; |
| 944 | } |
| 945 | |
| 946 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect( |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 947 | hal::HWDisplayId hwcDisplayId) { |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 948 | const auto displayId = toPhysicalDisplayId(hwcDisplayId); |
| 949 | if (!displayId) { |
| 950 | ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId); |
| 951 | return {}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Marin Shalamanov | bdd5915 | 2020-02-14 15:30:06 +0100 | [diff] [blame] | 954 | // The display will later be destroyed by a call to |
| 955 | // destroyDisplay(). For now we just mark it disconnected. |
| 956 | if (isConnected(*displayId)) { |
| 957 | mDisplayData[*displayId].hwcDisplay->setConnected(false); |
| 958 | } else { |
| 959 | ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId); |
| 960 | } |
| 961 | // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay |
| 962 | // via SurfaceFlinger's onHotplugReceived callback handling |
| 963 | return DisplayIdentificationInfo{.id = *displayId, |
| 964 | .name = std::string(), |
Marin Shalamanov | f5de90d | 2019-10-08 10:57:25 +0200 | [diff] [blame] | 965 | .deviceProductInfo = std::nullopt}; |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 968 | void HWComposer::loadCapabilities() { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 969 | static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed"); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 970 | auto capabilities = mComposer->getCapabilities(); |
| 971 | for (auto capability : capabilities) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 972 | mCapabilities.emplace(static_cast<hal::Capability>(capability)); |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 976 | void HWComposer::loadLayerMetadataSupport() { |
| 977 | mSupportedLayerGenericMetadata.clear(); |
| 978 | |
| 979 | std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo; |
| 980 | const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo); |
| 981 | if (error != hardware::graphics::composer::V2_4::Error::NONE) { |
| 982 | ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys", |
| 983 | toString(error).c_str(), static_cast<int32_t>(error)); |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | for (const auto& [name, mandatory] : supportedMetadataKeyInfo) { |
| 988 | mSupportedLayerGenericMetadata.emplace(name, mandatory); |
| 989 | } |
| 990 | } |
| 991 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 992 | uint32_t HWComposer::getMaxVirtualDisplayCount() const { |
| 993 | return mComposer->getMaxVirtualDisplayCount(); |
| 994 | } |
| 995 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 996 | } // namespace impl |
Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 997 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 998 | |
| 999 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1000 | #pragma clang diagnostic pop // ignored "-Wconversion" |