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