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